throws AccessControlException {
return login(userId, TEST_PUB_ID);
}
protected Session login(String userId, String pubId) throws AccessControlException {
Session session = new SessionImpl(null, true, getManager(), getLogger());
getRequest().setAttribute(Session.class.getName(), session);
DefaultAccessController ac = getAccessController(session, pubId);
AccreditableManager acMgr = ac.getAccreditableManager();
User user = acMgr.getUserManager().getUser(userId);
if (user == null) {
throw new AccessControlException("The user [" + userId + "] does not exist!");
}
ac.setupIdentity(getRequest());
org.apache.cocoon.environment.Session cocoonSession = getRequest().getSession();
Identity identity = (Identity) cocoonSession.getAttribute(Identity.class.getName());
if (!identity.contains(user)) {
User oldUser = identity.getUser();
if (oldUser != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Removing user [" + oldUser + "] from identity.");
}
identity.removeIdentifiable(oldUser);
}
identity.addIdentifiable(user);
}
ac.authorize(getRequest());
Accreditable[] accrs = identity.getAccreditables();
for (int i = 0; i < accrs.length; i++) {
getLogger().info("Accreditable: " + accrs[i]);
}
session.setIdentity(identity);
return session;
}