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

Shane Bryzak Shane_Bryzak at symantec.com
Wed Jul 26 02:04:35 EDT 2006


  User: sbryzak2
  Date: 06/07/26 02:04:35

  Modified:    src/main/org/jboss/seam/security/realm    
                        CatalinaRealm.java JaasRealm.java
  Added:       src/main/org/jboss/seam/security/realm    
                        RolePrincipal.java UserPrincipal.java
  Log:
  ongoing security framework stuff
  
  Revision  Changes    Path
  1.2       +6 -0      jboss-seam/src/main/org/jboss/seam/security/realm/CatalinaRealm.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CatalinaRealm.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/realm/CatalinaRealm.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- CatalinaRealm.java	24 Jul 2006 07:13:39 -0000	1.1
  +++ CatalinaRealm.java	26 Jul 2006 06:04:35 -0000	1.2
  @@ -3,11 +3,17 @@
   import java.lang.reflect.Method;
   import java.security.Principal;
   
  +import static org.jboss.seam.ScopeType.APPLICATION;
  +import org.jboss.seam.annotations.Name;
  +import org.jboss.seam.annotations.Scope;
  +
   /**
    * Wrapper for Tomcat realm authentication
    *
    * @author Shane Bryzak
    */
  + at Name("org.jboss.seam.security.realm.Realm")
  + at Scope(APPLICATION)
   public class CatalinaRealm implements Realm
   {
     private Object realm;
  
  
  
  1.3       +35 -5     jboss-seam/src/main/org/jboss/seam/security/realm/JaasRealm.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JaasRealm.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/realm/JaasRealm.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JaasRealm.java	25 Jul 2006 06:50:19 -0000	1.2
  +++ JaasRealm.java	26 Jul 2006 06:04:35 -0000	1.3
  @@ -7,20 +7,44 @@
   import javax.security.auth.login.LoginContext;
   import javax.security.auth.login.LoginException;
   
  +import static org.jboss.seam.ScopeType.APPLICATION;
  +import org.jboss.seam.annotations.Name;
  +import org.jboss.seam.annotations.Scope;
  +import javax.security.auth.login.Configuration;
  +import javax.security.auth.login.AppConfigurationEntry;
  +import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
  +import java.util.Map;
  +import java.util.HashMap;
  +
   /**
    * JAAS realm implementation
    *
    * @author Shane Bryzak
    */
  + at Name("org.jboss.seam.security.realm.Realm")
  + at Scope(APPLICATION)
   public class JaasRealm implements Realm
   {
     public Principal authenticate(String username, String credentials)
     {
       try
       {
  +      /** @todo This is a hack just to get things working.  This stuff should be
  +       * loaded from the config file */
  +      Map<String,?> options = new HashMap<String,Object>();
  +      final AppConfigurationEntry entry = new AppConfigurationEntry("org.jboss.seam.security.loginmodule.SeamLoginModule",
  +          LoginModuleControlFlag.REQUIRED, options);
  +      Configuration config = new Configuration() {
  +        public AppConfigurationEntry[] getAppConfigurationEntry(String name)
  +        {
  +          return new AppConfigurationEntry[] {entry};
  +        }
  +        public void refresh() {}
  +      };
  +
         /** @todo get the JAAS configuration name from the config file? */
  -      LoginContext loginContext = new LoginContext("securityexample",
  -          new JaasCallbackHandler(username, credentials));
  +      LoginContext loginContext = new LoginContext("seam", new Subject(),
  +          new JaasCallbackHandler(username, credentials), config);
   
         loginContext.login();
   
  @@ -28,7 +52,7 @@
       }
       catch (LoginException ex)
       {
  -      return null;
  +      throw new SecurityException("Authentication failed", ex);
       }
     }
   
  @@ -44,8 +68,14 @@
   
       for (Principal principal : subject.getPrincipals())
       {
  -      /** @todo since JAAS doesn't tell us which principals are the user and
  -       * which are roles, we need to work it out ourselves */
  +      if (principal instanceof UserPrincipal && userPrincipal == null)
  +      {
  +        userPrincipal = principal;
  +      }
  +      else if (principal instanceof RolePrincipal)
  +      {
  +        roles.add(principal.getName());
  +      }
       }
   
       // Return the resulting Principal for our authenticated user
  
  
  
  1.1      date: 2006/07/26 06:04:35;  author: sbryzak2;  state: Exp;jboss-seam/src/main/org/jboss/seam/security/realm/RolePrincipal.java
  
  Index: RolePrincipal.java
  ===================================================================
  package org.jboss.seam.security.realm;
  
  import java.security.Principal;
  
  /**
   * A role principal
   *
   * @author Shane Bryzak
   */
  public class RolePrincipal implements Principal
  {
    private String name;
  
    public RolePrincipal(String name)
    {
      this.name = name;
    }
  
    public String getName()
    {
      return name;
    }
  }
  
  
  
  1.1      date: 2006/07/26 06:04:35;  author: sbryzak2;  state: Exp;jboss-seam/src/main/org/jboss/seam/security/realm/UserPrincipal.java
  
  Index: UserPrincipal.java
  ===================================================================
  package org.jboss.seam.security.realm;
  
  import java.security.Principal;
  
  /**
   * A user principal.
   *
   * @author Shane Bryzak
   */
  public class UserPrincipal implements Principal
  {
    private String name;
  
    public UserPrincipal(String name)
    {
      this.name = name;
    }
  
    public String getName()
    {
      return name;
    }
  }
  
  
  



More information about the jboss-cvs-commits mailing list