You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/07/01 21:26:40 UTC

cvs commit: cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components DefaultAuthenticationManager.java Authenticator.java

cziegeler    2003/07/01 12:26:40

  Modified:    src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user
                        UserHandler.java
               src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context
                        AuthenticationContext.java
               src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components
                        DefaultAuthenticationManager.java
                        Authenticator.java
  Log:
  Removing last fixme - finally finished redesign of auth framework
  
  Revision  Changes    Path
  1.9       +4 -3      cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java
  
  Index: UserHandler.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/user/UserHandler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- UserHandler.java	27 May 2003 12:19:30 -0000	1.8
  +++ UserHandler.java	1 Jul 2003 19:26:40 -0000	1.9
  @@ -88,9 +88,10 @@
       /**
        * Create a new handler object.
        */
  -    public UserHandler(HandlerConfiguration handler) {
  +    public UserHandler(HandlerConfiguration handler, AuthenticationContext context) {
  +        this.context = context;
           this.handler = handler;
  -        this.context = new AuthenticationContext(this);
  +        this.context.init(this);
       }
   
       /**
  
  
  
  1.9       +21 -12    cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java
  
  Index: AuthenticationContext.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/context/AuthenticationContext.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AuthenticationContext.java	23 May 2003 12:35:32 -0000	1.8
  +++ AuthenticationContext.java	1 Jul 2003 19:26:40 -0000	1.9
  @@ -56,10 +56,12 @@
   
   import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
  +import org.apache.cocoon.webapps.authentication.components.DefaultAuthenticationManager;
   import org.apache.cocoon.webapps.authentication.configuration.ApplicationConfiguration;
   import org.apache.cocoon.webapps.authentication.user.RequestState;
   import org.apache.cocoon.webapps.authentication.user.UserHandler;
  @@ -83,19 +85,26 @@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
   */
  -public final class AuthenticationContext
  +public class AuthenticationContext
   implements SessionContext {
   
  -    private String          name;
  -    private UserHandler     handler;
  -    private SessionContext  authContext;
  -    private String          handlerName;
  -    private boolean        initialized;
  +    protected String          name;
  +    protected UserHandler     handler;
  +    protected SessionContext  authContext;
  +    protected String          handlerName;
  +    protected boolean        initialized;
  +    protected Context         context;
       
  -    // FIXME
  -    public static ThreadLocal     state = new InheritableThreadLocal();
  +    /** Constructor */
  +    public AuthenticationContext(Context context) {
  +        this.context = context;
  +    }
       
  -    public AuthenticationContext(UserHandler handler) {
  +    /**
  +     * Initialize the context. This method has to be called right after
  +     * the constructor.
  +     */
  +    public void init(UserHandler handler) {
           this.name = AuthenticationConstants.SESSION_CONTEXT_NAME;
   
           this.handler = handler;
  @@ -107,8 +116,8 @@
           }
       }
       
  -    private RequestState getState() {
  -        return (RequestState)state.get();
  +    protected RequestState getState() {
  +        return DefaultAuthenticationManager.getRequestState( this.context );
       }
       
       public void init(Document doc) 
  
  
  
  1.14      +17 -12    cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java
  
  Index: DefaultAuthenticationManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/DefaultAuthenticationManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultAuthenticationManager.java	16 Jun 2003 16:04:06 -0000	1.13
  +++ DefaultAuthenticationManager.java	1 Jul 2003 19:26:40 -0000	1.14
  @@ -58,6 +58,7 @@
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
  @@ -76,7 +77,6 @@
   import org.apache.cocoon.webapps.authentication.AuthenticationConstants;
   import org.apache.cocoon.webapps.authentication.AuthenticationManager;
   import org.apache.cocoon.webapps.authentication.configuration.HandlerConfiguration;
  -import org.apache.cocoon.webapps.authentication.context.AuthenticationContext;
   import org.apache.cocoon.webapps.authentication.user.RequestState;
   import org.apache.cocoon.webapps.authentication.user.UserHandler;
   import org.apache.cocoon.webapps.authentication.user.UserState;
  @@ -368,13 +368,15 @@
       throws ServiceException {
           this.manager = manager;
           this.authenticator = new Authenticator();
  -        this.authenticator.enableLogging( this.getLogger() );
  -        this.authenticator.service( this.manager );
  +        try {
  +            ContainerUtil.enableLogging( this.authenticator, this.getLogger() );
  +            ContainerUtil.contextualize( this.authenticator, this.context);
  +            ContainerUtil.service( this.authenticator, this.manager );
  +            ContainerUtil.initialize( this.authenticator );
  +        } catch (Exception e ) {
  +            throw new ServiceException("Unable to initialize authenticator.", e);
  +        }
           this.resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
  -        
  -        ContextManager contextManager;
  -        
  -        contextManager = (ContextManager) this.manager.lookup(ContextManager.ROLE);
   	}
   
   	/* (non-Javadoc)
  @@ -382,7 +384,7 @@
   	 */
   	public void dispose() {
   		if ( this.authenticator != null ) {
  -            this.authenticator.dispose();
  +            ContainerUtil.dispose( this.authenticator );
               this.authenticator = null;
   		}
           if ( this.manager != null) {
  @@ -396,10 +398,14 @@
        * Get the current state of authentication
        */
       public RequestState getState() {
  -        final Request req = ContextHelper.getRequest(this.context);
  -        return (RequestState)req.getAttribute( REQUEST_STATE_KEY);
  +        return getRequestState(this.context);
       }
   
  +    public static RequestState getRequestState(Context context) {
  +        final Request req = ContextHelper.getRequest(context);
  +        return (RequestState)req.getAttribute( REQUEST_STATE_KEY);
  +    }
  +    
       /* (non-Javadoc)
        * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
        */
  @@ -409,7 +415,6 @@
       }
   
       protected void setState(RequestState status) {
  -        AuthenticationContext.state.set(status);
           final Request req = ContextHelper.getRequest(this.context);
           if ( status != null ) {
               req.setAttribute(  REQUEST_STATE_KEY, status);
  
  
  
  1.7       +22 -10    cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java
  
  Index: Authenticator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/authentication-fw/java/org/apache/cocoon/webapps/authentication/components/Authenticator.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Authenticator.java	4 May 2003 20:30:56 -0000	1.6
  +++ Authenticator.java	1 Jul 2003 19:26:40 -0000	1.7
  @@ -55,6 +55,9 @@
   
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
  @@ -90,15 +93,18 @@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
   */
  -public final class Authenticator 
  +public class Authenticator 
       extends AbstractLogEnabled
  -    implements Serviceable, ThreadSafe, Disposable {
  +    implements Serviceable, ThreadSafe, Disposable, Contextualizable {
  +    
  +    /** The context */
  +    protected Context context;
           
       /** The service manager */
  -    private ServiceManager manager;
  +    protected ServiceManager manager;
       
       /** The source resolver */
  -    private SourceResolver resolver;
  +    protected SourceResolver resolver;
       
       /**
        * Check the fragment if it is valid
  @@ -216,9 +222,8 @@
                       this.getLogger().info("Authenticator: User authenticated using handler '" + configuration.getName()+"'");
                   }
                   
  -                handler = new UserHandler(configuration);
  -                
  -                AuthenticationContext context = handler.getContext();
  +                AuthenticationContext authContext = new AuthenticationContext(this.context);
  +                handler = new UserHandler(configuration, authContext);
   
                   MediaManager mediaManager = null;
                   String mediaType;
  @@ -230,7 +235,7 @@
                   } finally {
                       this.manager.release( mediaManager );
                   }
  -                synchronized(context) {
  +                synchronized(authContext) {
                       // add special nodes to the authentication block:
                       // useragent, type and media
                       Element specialElement;
  @@ -250,7 +255,7 @@
                       authNode.appendChild(specialElement);
   
                       // store the authentication data in the context
  -                    context.init(doc);
  +                    authContext.init(doc);
   
                       // And now load applications
                       boolean loaded = true;
  @@ -343,5 +348,12 @@
               this.resolver = null;
   		}
   	}
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
  +     */
  +    public void contextualize(Context context) throws ContextException {
  +        this.context = context;
  +    }
   
   }