1 15 16 package org.apache.lenya.ac.impl; 17 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 import org.apache.cocoon.environment.Request; 20 import org.apache.lenya.ac.AccessControlException; 21 import org.apache.lenya.ac.AccreditableManager; 22 import org.apache.lenya.ac.Authenticator; 23 import org.apache.lenya.ac.Identity; 24 import org.apache.lenya.ac.User; 25 26 27 33 public class AnonymousAuthenticator extends AbstractLogEnabled implements Authenticator { 34 35 36 40 public boolean authenticate(AccreditableManager accreditableManager, Request request) 41 throws AccessControlException { 42 43 String username = "anonymous"; 44 45 if (getLogger().isDebugEnabled()) { 46 getLogger().debug( 47 "Authenticating username [" + username + "]"); 48 } 49 50 Identity identity = (Identity) request.getSession(false).getAttribute(Identity.class.getName()); 51 52 User user = accreditableManager.getUserManager().getUser(username); 53 54 boolean authenticated = false; 55 if (user != null) { 56 if (getLogger().isDebugEnabled()) { 57 getLogger().debug("User [" + user + "] authenticated."); 58 } 59 60 if (!identity.contains(user)) { 61 User oldUser = identity.getUser(); 62 if (oldUser != null) { 63 if (getLogger().isDebugEnabled()) { 64 getLogger().debug("Removing user [" + oldUser + "] from identity."); 65 } 66 identity.removeIdentifiable(oldUser); 67 } 68 identity.addIdentifiable(user); 69 } 70 authenticated = true; 71 } else { 72 if (getLogger().isDebugEnabled()) { 73 if (user == null) { 74 getLogger().debug("No such user: [" + username + "]"); 75 } 76 getLogger().debug("User [" + username + "] not authenticated."); 77 } 78 } 79 return authenticated; 80 } 81 } | Popular Tags |