[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security/authenticator ...

Shane Bryzak Shane_Bryzak at symantec.com
Fri Aug 4 21:57:54 EDT 2006


  User: sbryzak2
  Date: 06/08/04 21:57:54

  Modified:    src/main/org/jboss/seam/security/authenticator  
                        Authenticator.java ProviderAuthenticator.java
  Log:
  Security stuff
  
  Revision  Changes    Path
  1.9       +86 -3     jboss-seam/src/main/org/jboss/seam/security/authenticator/Authenticator.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Authenticator.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/authenticator/Authenticator.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- Authenticator.java	2 Aug 2006 04:05:54 -0000	1.8
  +++ Authenticator.java	5 Aug 2006 01:57:54 -0000	1.9
  @@ -1,15 +1,98 @@
   package org.jboss.seam.security.authenticator;
   
  -import org.jboss.seam.security.AuthenticationException;
  +import java.util.ArrayList;
  +import java.util.List;
  +
  +import org.jboss.seam.Component;
  +import org.jboss.seam.ScopeType;
  +import org.jboss.seam.annotations.Name;
  +import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.security.Authentication;
  +import org.jboss.seam.security.AuthenticationException;
  +import org.jboss.seam.security.UsernamePasswordToken;
  +import org.jboss.seam.security.adapter.AuthenticationAdapter;
  +import org.jboss.seam.Seam;
   
   /**
    *
    *
    * @author Shane Bryzak
    */
  -public interface Authenticator
  + at Name("org.jboss.seam.security.authenticator")
  +public abstract class Authenticator
   {
  -  Authentication authenticate(Authentication authentication)
  +  private List<AuthenticationAdapter> adapters = new ArrayList<AuthenticationAdapter>();
  +
  +  public static Authenticator instance()
  +  {
  +    if (!Contexts.isApplicationContextActive())
  +       throw new IllegalStateException("No active application context");
  +
  +    Authenticator instance = (Authenticator) Component.getInstance(
  +        Authenticator.class, ScopeType.APPLICATION, true);
  +
  +    if (instance==null)
  +    {
  +      throw new IllegalStateException(
  +          "No Authenticator could be created, make sure the Component exists in application scope");
  +    }
  +
  +    return instance;
  +  }
  +
  +  public Authentication authenticate(String username, String password)
  +      throws AuthenticationException
  +  {
  +    return authenticate(new UsernamePasswordToken(username, password));
  +  }
  +
  +  public final Authentication authenticate(Authentication authentication)
  +      throws AuthenticationException
  +  {
  +    Authentication auth = doAuthentication(authentication);
  +    Contexts.getSessionContext().set(Seam.getComponentName(Authentication.class), auth);
  +    return auth;
  +  }
  +
  +  public abstract Authentication doAuthentication(Authentication authentication)
         throws AuthenticationException;
  +
  +  public void unauthenticateSession()
  +  {
  +    Authentication.instance().invalidate();
  +  }
  +
  +  public void setAdapters(List<String> adapterNames)
  +  {
  +    for (String name : adapterNames)
  +    {
  +      try
  +      {
  +        adapters.add((AuthenticationAdapter) Class.forName(name).newInstance());
  +      }
  +      catch (Exception ex)
  +      {
  +      }
  +    }
  +    this.adapters = adapters;
  +  }
  +
  +  public void beginRequest()
  +  {
  +    for (AuthenticationAdapter adapter : adapters)
  +    {
  +      adapter.beginRequest();
  +    }
  +  }
  +
  +  public void endRequest()
  +  {
  +    for (AuthenticationAdapter adapter : adapters)
  +    {
  +      adapter.endRequest();
  +    }
  +
  +    if (!Authentication.instance().isValid())
  +      Contexts.getSessionContext().remove(Seam.getComponentName(Authentication.class));
  +  }
   }
  
  
  
  1.5       +23 -38    jboss-seam/src/main/org/jboss/seam/security/authenticator/ProviderAuthenticator.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ProviderAuthenticator.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/authenticator/ProviderAuthenticator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- ProviderAuthenticator.java	1 Aug 2006 05:03:34 -0000	1.4
  +++ ProviderAuthenticator.java	5 Aug 2006 01:57:54 -0000	1.5
  @@ -7,24 +7,23 @@
   import org.jboss.seam.Component;
   import org.jboss.seam.annotations.Name;
   import org.jboss.seam.annotations.Scope;
  -import org.jboss.seam.annotations.Startup;
   import org.jboss.seam.security.Authentication;
   import org.jboss.seam.security.AuthenticationException;
   import org.jboss.seam.security.provider.AuthenticationProvider;
   
   /**
  + * Performs authentication services against one or more providers.
    *
    * @author Shane Bryzak
    */
  - at Name("org.jboss.seam.security.Authenticator")
  + at Name("org.jboss.seam.security.authenticator")
   @Scope(APPLICATION)
  - at Startup
  -public class ProviderAuthenticator implements Authenticator
  +public class ProviderAuthenticator extends Authenticator
   {
     /**
      *
      */
  -  private List<Object> providers = new ArrayList<Object>();
  +  private List<Object> providers = new ArrayList<Object> ();
   
     /**
      *
  @@ -32,7 +31,7 @@
      * @return Authentication
      * @throws AuthenticationException
      */
  -  public Authentication authenticate(Authentication authentication)
  +  public Authentication doAuthentication(Authentication authentication)
         throws AuthenticationException
     {
       for (Object p : providers)
  @@ -42,7 +41,7 @@
         if (p instanceof AuthenticationProvider)
           provider = (AuthenticationProvider) p;
         else if (p instanceof Component)
  -        provider = (AuthenticationProvider) ((Component) p).newInstance();
  +        provider = (AuthenticationProvider) ( (Component) p).newInstance();
   
         Authentication result = provider.authenticate(authentication);
         if (result != null)
  @@ -54,47 +53,33 @@
   
     /**
      *
  -   * @param authentication Authentication
  +   * @param providerNames List
      */
  -  public void unauthenticate(Authentication authentication)
  +  public void setProviders(Object values)
     {
  -    for (Object p : providers)
  +    if (values instanceof AuthenticationProvider)
       {
  -      AuthenticationProvider provider = null;
  -
  -      if (p instanceof AuthenticationProvider)
  -        provider = (AuthenticationProvider) p;
  -      else if (p instanceof Component)
  -        provider = (AuthenticationProvider) ((Component) p).newInstance();
  -
  -      provider.unauthenticate(authentication);
  +      providers.add(values);
       }
  -  }
  -
  -  /**
  -   *
  -   * @param providerNames List
  -   */
  -  public void setProviders(List<String> providerNames)
  -  {
  -    for (String providerName : providerNames)
  +    else
       {
  -      Object provider = null;
  -      try
  +      for (Object provider : (List) values)
         {
  -        Component comp = Component.forName(providerName);
  -        if (comp != null)
  -          providers.add(comp);
  +        if (provider instanceof Component)
  +          providers.add(provider);
           else
           {
  -          provider = Class.forName(providerName).newInstance();
  +          try
  +          {
  +            provider = Class.forName(provider.toString()).newInstance();
             providers.add( (AuthenticationProvider) provider);
           }
  -      }
         catch (Exception ex)
         {
   //        log.error("Error creating provider", ex);
         }
       }
     }
  +    }
  +  }
   }
  
  
  



More information about the jboss-cvs-commits mailing list