1 16 package org.apache.cocoon.webapps.authentication.context; 17 18 import org.apache.avalon.framework.component.Component; 19 import org.apache.avalon.framework.logger.AbstractLogEnabled; 20 import org.apache.avalon.framework.service.ServiceException; 21 import org.apache.avalon.framework.service.ServiceManager; 22 import org.apache.avalon.framework.service.Serviceable; 23 import org.apache.avalon.framework.thread.ThreadSafe; 24 import org.apache.cocoon.ProcessingException; 25 import org.apache.cocoon.webapps.authentication.AuthenticationConstants; 26 import org.apache.cocoon.webapps.authentication.AuthenticationManager; 27 import org.apache.cocoon.webapps.authentication.user.RequestState; 28 import org.apache.cocoon.webapps.authentication.user.UserHandler; 29 import org.apache.cocoon.webapps.session.context.SessionContext; 30 import org.apache.cocoon.webapps.session.context.SessionContextProvider; 31 32 33 39 public final class AuthenticationContextProvider 40 extends AbstractLogEnabled 41 implements SessionContextProvider, ThreadSafe, Component, Serviceable { 42 43 protected ServiceManager manager; 44 45 51 public SessionContext getSessionContext(String name) 52 throws ProcessingException { 53 AuthenticationContext context = null; 54 if (name.equals(AuthenticationConstants.SESSION_CONTEXT_NAME) ) { 55 56 AuthenticationManager authManager = null; 57 RequestState state = null; 58 try { 59 authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE); 60 state = authManager.getState(); 61 } catch (ServiceException ignore) { 62 } finally { 63 this.manager.release( authManager ); 64 } 65 66 if ( null != state ) { 67 UserHandler handler = state.getHandler(); 68 if ( handler != null ) { 69 context = handler.getContext(); 70 } 71 } 72 } 73 return context; 74 } 75 76 79 public boolean existsSessionContext(String name) 80 throws ProcessingException { 81 return (this.getSessionContext( name ) != null); 82 } 83 84 87 public void service(ServiceManager manager) throws ServiceException { 88 this.manager = manager; 89 } 90 91 } 92 | Popular Tags |