private DefaultAccessController accessController;
protected org.apache.lenya.cms.repository.Session login(String userId)
throws AccessControlException {
Session session = new SessionImpl(null, true, getManager(), getLogger());
DefaultAccessController ac = getAccessController(session, TEST_PUB_ID);
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;
}