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

Shane Bryzak Shane_Bryzak at symantec.com
Sun Dec 3 23:23:51 EST 2006


  User: sbryzak2
  Date: 06/12/03 23:23:51

  Modified:    src/main/org/jboss/seam/security     Identity.java
                        SeamSecurityManager.java UsernamePasswordToken.java
  Added:       src/main/org/jboss/seam/security     Role.java
  Log:
  added a proper Role class
  
  Revision  Changes    Path
  1.2       +3 -3      jboss-seam/src/main/org/jboss/seam/security/Identity.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Identity.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/Identity.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Identity.java	4 Dec 2006 01:06:50 -0000	1.1
  +++ Identity.java	4 Dec 2006 04:23:51 -0000	1.2
  @@ -35,7 +35,7 @@
       return instance;
     }
   
  -  public abstract String[] getRoles();
  +  public abstract Role[] getRoles();
     public abstract Object getCredentials();
     public abstract Object getPrincipal();
   
  @@ -63,9 +63,9 @@
      */
     public boolean isUserInRole(String role)
     {
  -    for (String r : getRoles())
  +    for (Role r : getRoles())
       {
  -      if (r.equals(role))
  +      if (r.getName().equals(role))
           return true;
       }
       return false;
  
  
  
  1.21      +8 -1      jboss-seam/src/main/org/jboss/seam/security/SeamSecurityManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamSecurityManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/SeamSecurityManager.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -b -r1.20 -r1.21
  --- SeamSecurityManager.java	4 Dec 2006 01:21:52 -0000	1.20
  +++ SeamSecurityManager.java	4 Dec 2006 04:23:51 -0000	1.21
  @@ -20,6 +20,7 @@
   import org.jboss.seam.security.acl.AclProvider;
   import org.jboss.seam.security.acl.IdentityGenerator;
   import org.jboss.seam.security.acl.JPAIdentityGenerator;
  +import org.jboss.seam.annotations.Create;
   
   /**
    * Holds configuration settings and provides functionality for the security API
  @@ -54,6 +55,12 @@
      */
     private Map<Class,PermissionHandler> permissionHandlers = new HashMap<Class,PermissionHandler>();
   
  +  @Create
  +  public void initSecurityManager()
  +  {
  +
  +  }
  +
     public static SeamSecurityManager instance()
     {
       if (!Contexts.isApplicationContextActive())
  @@ -124,7 +131,7 @@
     private void checkRolePermissions(String permissionName, String action)
     {
       Permission required = new SeamPermission(permissionName, action);
  -    for (String role : Identity.instance().getRoles())
  +    for (Role role : Identity.instance().getRoles())
       {
         Set<Permission> permissions = rolePermissions.get(role);
         if (permissions != null && permissions.contains(required))
  
  
  
  1.8       +3 -3      jboss-seam/src/main/org/jboss/seam/security/UsernamePasswordToken.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UsernamePasswordToken.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/UsernamePasswordToken.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- UsernamePasswordToken.java	4 Dec 2006 01:21:52 -0000	1.7
  +++ UsernamePasswordToken.java	4 Dec 2006 04:23:51 -0000	1.8
  @@ -5,7 +5,7 @@
    */
   public class UsernamePasswordToken extends Identity
   {
  -  private String[] roles;
  +  private Role[] roles;
     private Object credentials;
     private Object principal;
   
  @@ -16,7 +16,7 @@
       this.authenticated = false;
     }
   
  -  public UsernamePasswordToken(Object principal, Object credentials, String[] roles)
  +  public UsernamePasswordToken(Object principal, Object credentials, Role[] roles)
     {
       this(principal, credentials);
       this.roles = roles;
  @@ -30,7 +30,7 @@
     }
   
     @Override
  -  public String[] getRoles()
  +  public Role[] getRoles()
     {
       return roles;
     }
  
  
  
  1.1      date: 2006/12/04 04:23:51;  author: sbryzak2;  state: Exp;jboss-seam/src/main/org/jboss/seam/security/Role.java
  
  Index: Role.java
  ===================================================================
  package org.jboss.seam.security;
  
  import java.io.Serializable;
  import java.security.Principal;
  import java.security.acl.Group;
  import java.security.acl.Permission;
  import java.util.Collections;
  import java.util.Enumeration;
  import java.util.HashSet;
  import java.util.Set;
  
  /**
   * A Role implementation.  Roles can contain other roles.
   *
   * @author Shane Bryzak
   */
  public class Role implements Group, Serializable
  {
    /**
     * The name of the role
     */
    private String name;
  
    /**
     * The members of this role.  This role has the authority to perform any action
     * that any of its members (or member's members, ad infinitum) can perform.
     */
    private Set<Principal> members = new HashSet<Principal>();
  
    /**
     * A set of permissions explicitly assigned to this role.
     */
    private Set<Permission> permissions = new HashSet<Permission>();
  
    public Role(String name)
    {
      this.name = name;
    }
  
    public boolean addPermission(Permission permission)
    {
      return permissions.add(permission);
    }
  
    public boolean hasPermission(Permission permission)
    {
      return permissions.contains(permission);
    }
  
    public boolean removePermission(Permission permission)
    {
      return permissions.remove(permission);
    }
  
    public boolean addMember(Principal user)
    {
      return members.add(user);
    }
  
    public boolean isMember(Principal member)
    {
      if (members.contains(member))
        return true;
      else
      {
        for (Principal m : members)
        {
          if (m instanceof Group && ((Group) m).isMember(member))
            return true;
        }
      }
      return false;
    }
  
    public Enumeration<? extends Principal> members()
    {
      return Collections.enumeration(members);
    }
  
    public boolean removeMember(Principal user)
    {
      return members.remove(user);
    }
  
    public String getName()
    {
      return name;
    }
  
    public boolean equals(Object obj)
    {
      if (!(obj instanceof Role))
        return false;
  
      Role other = (Role) obj;
  
      return other.name.equals(name);
    }
  
    public int hashCode()
    {
      return name.hashCode();
    }
  }
  
  
  



More information about the jboss-cvs-commits mailing list