You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/04/08 15:15:32 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util/security GroupSet.java PermissionSet.java RoleSet.java SecuritySet.java TurbineAccessControlList.java

henning     2003/04/08 06:15:32

  Modified:    src/java/org/apache/turbine/om/security SecurityEntity.java
                        SecurityObject.java TurbineUser.java
               src/java/org/apache/turbine/util/security GroupSet.java
                        PermissionSet.java RoleSet.java SecuritySet.java
                        TurbineAccessControlList.java
  Log:
  Add the ability to the Security Service to retrieve Objects not only
  by name but also by id. This id must be supplied by the underlying
  security service and currently works only for the
  TorqueSecurityService. For passive, ldap and DB SecurityService, dummy
  code is added.
  
  Revision  Changes    Path
  1.5       +23 -1     jakarta-turbine-2/src/java/org/apache/turbine/om/security/SecurityEntity.java
  
  Index: SecurityEntity.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/om/security/SecurityEntity.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SecurityEntity.java	9 Mar 2003 02:45:15 -0000	1.4
  +++ SecurityEntity.java	8 Apr 2003 13:15:31 -0000	1.5
  @@ -81,4 +81,26 @@
        * @param name Name of the SecurityEntity.
        */
       void setName(String name);
  +
  +    /**
  +     * Get the Id of the SecurityEntity.
  +     *
  +     * @return The Id of the SecurityEntity.
  +     */
  +    int getId();
  +
  +    /**
  +     * Get the Id of the SecurityEntity as an
  +     * Integer object.
  +     *
  +     * @return The Id of the SecurityEntity.
  +     */
  +    Integer getIdAsObj();
  +
  +    /**
  +     * Sets the Id of the SecurityEntity.
  +     *
  +     * @param id The new Id of the SecurityEntity
  +     */
  +    void setId(int id);
   }
  
  
  
  1.5       +45 -5     jakarta-turbine-2/src/java/org/apache/turbine/om/security/SecurityObject.java
  
  Index: SecurityObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/om/security/SecurityObject.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SecurityObject.java	20 Mar 2003 00:28:35 -0000	1.4
  +++ SecurityObject.java	8 Apr 2003 13:15:31 -0000	1.5
  @@ -74,6 +74,9 @@
       /** The name of this object. */
       private String name;
   
  +    /** The id of this object */
  +    private int id;
  +
       /** The attributes of this object. */
       private Map attributes;
   
  @@ -90,9 +93,10 @@
        *
        * @param name The name of the new object.
        */
  -    public SecurityObject( String name )
  +    public SecurityObject(String name)
       {
           setName(name);
  +        setId(0);
           setAttributes(Collections.synchronizedMap(new HashMap()));
       }
   
  @@ -111,7 +115,7 @@
        *
        * @param attributes The new attributes of the object.
        */
  -    public void setAttributes( Map attributes )
  +    public void setAttributes(Map attributes)
       {
           this.attributes = attributes;
       }
  @@ -122,7 +126,7 @@
        * @param name the name of the attribute
        * @return the value of the attribute
        */
  -    public Object getAttribute( String name )
  +    public Object getAttribute(String name)
       {
           return attributes.get(name);
       }
  @@ -133,7 +137,7 @@
        * @param name the name of the attribute
        * @param value the value of the attribute
        */
  -    public void setAttribute( String name, Object value )
  +    public void setAttribute(String name, Object value)
       {
           attributes.put(name, value);
       }
  @@ -156,6 +160,42 @@
       public void setName(String name)
       {
           this.name = name;
  +    }
  +
  +    /**
  +     * Unused. There is an ID column in the 
  +     * database scheme but it doesn't seem
  +     * to be used.
  +     *
  +     * @return 0
  +     */
  +    public int getId()
  +    {
  +        return id;
  +    }
  +            
  +    /**
  +     * Unused. There is an ID column in the 
  +     * database scheme but it doesn't seem
  +     * to be used.
  +     *
  +     * @return null
  +     */
  +    public Integer getIdAsObj()
  +    {
  +        return new Integer(id);
  +    }
  +
  +    /**
  +     * Unused. There is an ID column in the 
  +     * database scheme but it doesn't seem
  +     * to be used.
  +     *
  +     * @param id The id of the User.
  +     */
  +    public void setId(int id)
  +    {
  +        this.id = id;
       }
   
       /**
  
  
  
  1.9       +1 -2      jakarta-turbine-2/src/java/org/apache/turbine/om/security/TurbineUser.java
  
  Index: TurbineUser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/om/security/TurbineUser.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TurbineUser.java	20 Mar 2003 15:09:31 -0000	1.8
  +++ TurbineUser.java	8 Apr 2003 13:15:31 -0000	1.9
  @@ -731,5 +731,4 @@
       {
           setPerm(User.USERNAME, name);
       }
  -
   }
  
  
  
  1.9       +32 -1     jakarta-turbine-2/src/java/org/apache/turbine/util/security/GroupSet.java
  
  Index: GroupSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/security/GroupSet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GroupSet.java	8 Apr 2003 11:19:51 -0000	1.8
  +++ GroupSet.java	8 Apr 2003 13:15:32 -0000	1.9
  @@ -109,6 +109,7 @@
       {
           boolean res = contains(group);
           nameMap.put(group.getName(), group);
  +        idMap.put(group.getIdAsObj(), group);
           return res;
       }
   
  @@ -161,6 +162,7 @@
       {
           boolean res = contains(group);
           nameMap.remove(group.getName());
  +        idMap.remove(group.getIdAsObj());
           return res;
       }
   
  @@ -186,11 +188,38 @@
        */
       public Group getGroup(String groupName)
       {
  +        return getGroupByName(groupName);
  +    }
  +
  +    /**
  +     * Returns a Group with the given name, if it is contained in
  +     * this GroupSet.
  +     *
  +     * @param groupName Name of Group.
  +     * @return Group if argument matched a Group in this
  +     * GroupSet; null if no match.
  +     */
  +    public Group getGroupByName(String groupName)
  +    {
           return (StringUtils.isNotEmpty(groupName))
                   ? (Group) nameMap.get(groupName) : null;
       }
   
       /**
  +     * Returns a Group with the given id, if it is contained in
  +     * this GroupSet.
  +     *
  +     * @param groupId Id of the group
  +     * @return Group if argument matched a Group in this
  +     * GroupSet; null if no match.
  +     */
  +    public Group getGroupById(int groupId)
  +    {
  +        return (groupId != 0)
  +                ? (Group) idMap.get(new Integer(groupId)) : null;
  +    }
  +
  +    /**
        * Returns an Array of Groups in this GroupSet.
        *
        * @return An Array of Group objects.
  @@ -216,6 +245,8 @@
               Group g = (Group) it.next();
               sb.append('[');
               sb.append(g.getName());
  +            sb.append(" -> ");
  +            sb.append(g.getIdAsObj());
               sb.append(']');
               if (it.hasNext())
               {
  
  
  
  1.9       +32 -1     jakarta-turbine-2/src/java/org/apache/turbine/util/security/PermissionSet.java
  
  Index: PermissionSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/security/PermissionSet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PermissionSet.java	8 Apr 2003 11:19:51 -0000	1.8
  +++ PermissionSet.java	8 Apr 2003 13:15:32 -0000	1.9
  @@ -110,6 +110,7 @@
       {
           boolean res = contains(permission);
           nameMap.put(permission.getName(), permission);
  +        idMap.put(permission.getIdAsObj(), permission);
           return res;
       }
   
  @@ -163,6 +164,7 @@
       {
           boolean res = contains(permission);
           nameMap.remove(permission.getName());
  +        idMap.remove(permission.getIdAsObj());
           return res;
       }
   
  @@ -188,11 +190,38 @@
        */
       public Permission getPermission(String permissionName)
       {
  +        return getPermissionByName(permissionName);
  +    }
  +
  +    /**
  +     * Returns a Permission with the given name, if it is contained in
  +     * this PermissionSet.
  +     *
  +     * @param permissionName Name of Permission.
  +     * @return Permission if argument matched a Permission in this
  +     * PermissionSet; null if no match.
  +     */
  +    public Permission getPermissionByName(String permissionName)
  +    {
           return (StringUtils.isNotEmpty(permissionName))
                   ? (Permission) nameMap.get(permissionName) : null;
       }
   
       /**
  +     * Returns a Permission with the given id, if it is contained in
  +     * this PermissionSet.
  +     *
  +     * @param permissionId Id of the Permission.
  +     * @return Permission if argument matched a Permission in this
  +     * PermissionSet; null if no match.
  +     */
  +    public Permission getPermissionById(int permissionId)
  +    {
  +        return (permissionId != 0) 
  +                ? (Permission) idMap.get(new Integer(permissionId)) : null;
  +    }
  +
  +    /**
        * Returns an Array of Permissions in this PermissionSet.
        *
        * @return An Array of Permission Objects.
  @@ -218,6 +247,8 @@
               Permission p = (Permission) it.next();
               sb.append('[');
               sb.append(p.getName());
  +            sb.append(" -> ");
  +            sb.append(p.getIdAsObj());
               sb.append(']');
               if (it.hasNext())
               {
  
  
  
  1.8       +32 -1     jakarta-turbine-2/src/java/org/apache/turbine/util/security/RoleSet.java
  
  Index: RoleSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/security/RoleSet.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RoleSet.java	8 Apr 2003 11:19:51 -0000	1.7
  +++ RoleSet.java	8 Apr 2003 13:15:32 -0000	1.8
  @@ -109,6 +109,7 @@
       {
           boolean res = contains(role);
           nameMap.put(role.getName(), role);
  +        idMap.put(role.getIdAsObj(), role);
           return res;
       }
   
  @@ -161,6 +162,7 @@
       {
           boolean res = contains(role);
           nameMap.remove(role.getName());
  +        idMap.remove(role.getIdAsObj());
           return res;
       }
   
  @@ -186,11 +188,38 @@
        */
       public Role getRole(String roleName)
       {
  +        return getRoleByName(roleName);
  +    }
  +
  +    /**
  +     * Returns a Role with the given name, if it is contained in
  +     * this RoleSet.
  +     *
  +     * @param roleName Name of Role.
  +     * @return Role if argument matched a Role in this
  +     * RoleSet; null if no match.
  +     */
  +    public Role getRoleByName(String roleName)
  +    {
           return (StringUtils.isNotEmpty(roleName))
                   ? (Role) nameMap.get(roleName) : null;
       }
   
       /**
  +     * Returns a Role with the given id, if it is contained in this
  +     * RoleSet.
  +     *
  +     * @param roleId id of the Role.
  +     * @return Role if argument matched a Role in this RoleSet; null
  +     * if no match.
  +     */
  +    public Role getRoleById(int roleId)
  +    {
  +        return (roleId != 0) 
  +                ? (Role) idMap.get(new Integer(roleId)) : null;
  +    }
  +
  +    /**
        * Returns an Array of Roles in this RoleSet.
        *
        * @return An Array of Role objects.
  @@ -216,6 +245,8 @@
               Role r = (Role) it.next();
               sb.append('[');
               sb.append(r.getName());
  +            sb.append(" -> ");
  +            sb.append(r.getIdAsObj());
               sb.append(']');
               if (it.hasNext())
               {
  
  
  
  1.2       +32 -6     jakarta-turbine-2/src/java/org/apache/turbine/util/security/SecuritySet.java
  
  Index: SecuritySet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/security/SecuritySet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SecuritySet.java	8 Apr 2003 11:19:51 -0000	1.1
  +++ SecuritySet.java	8 Apr 2003 13:15:32 -0000	1.2
  @@ -63,6 +63,8 @@
   import java.util.TreeMap;
   import java.util.TreeSet;
   
  +import org.apache.commons.lang.StringUtils;
  +
   import org.apache.turbine.om.security.SecurityEntity;
   
   /**
  @@ -84,12 +86,16 @@
       /** Map for "name" -> "security object" */
       protected Map nameMap = null;
   
  +    /** Map for "id" -> "security object" */
  +    protected Map idMap = null;
  +
       /**
        * Constructs an empty Set
        */
       public SecuritySet()
       {
           nameMap = new TreeMap();
  +        idMap = new TreeMap();
       }
   
       /**
  @@ -115,11 +121,23 @@
       }
   
       /**
  +     * Returns a set of Id values in this Object.
  +     *
  +     * @return The Set of Ids in this Object,
  +     *         backed by the actual data.
  +     */
  +    public Set getIds()
  +    {
  +        return idMap.keySet();
  +    }
  +
  +    /**
        * Removes all Objects from this Set.
        */
       public void clear()
       {
           nameMap.clear();
  +        idMap.clear();
       }
   
       /**
  @@ -146,12 +164,20 @@
        */
       public boolean containsName(String name)
       {
  -        if (name == null)
  -        {
  -            return false;
  -        }
  +        return (StringUtils.isNotEmpty(name)) ? nameMap.containsKey(name) : false;
  +    }
   
  -        return nameMap.containsKey(name);
  +    /**
  +     * Searches if an Object with a given Id is in the
  +     * Set
  +     *
  +     * @param id Id of the Security Object.
  +     * @return True if argument matched an Object in this Set; false
  +     * if no match.
  +     */
  +    public boolean containsId(int id)
  +    {
  +        return (id == 0) ? false:  idMap.containsKey(new Integer(id));
       }
   
       /**
  
  
  
  1.7       +10 -10    jakarta-turbine-2/src/java/org/apache/turbine/util/security/TurbineAccessControlList.java
  
  Index: TurbineAccessControlList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/security/TurbineAccessControlList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TurbineAccessControlList.java	9 Mar 2003 02:54:13 -0000	1.6
  +++ TurbineAccessControlList.java	8 Apr 2003 13:15:32 -0000	1.7
  @@ -238,8 +238,8 @@
       {
           try
           {
  -            return hasRole(TurbineSecurity.getRole(role),
  -                    TurbineSecurity.getGroup(group));
  +            return hasRole(TurbineSecurity.getRoleByName(role),
  +                    TurbineSecurity.getGroupByName(group));
           }
           catch (Exception e)
           {
  @@ -261,7 +261,7 @@
           Role role;
           try
           {
  -            role = TurbineSecurity.getRole(rolename);
  +            role = TurbineSecurity.getRoleByName(rolename);
           }
           catch (TurbineSecurityException e)
           {
  @@ -307,7 +307,7 @@
       {
           try
           {
  -            return hasRole(TurbineSecurity.getRole(role));
  +            return hasRole(TurbineSecurity.getRoleByName(role));
           }
           catch (Exception e)
           {
  @@ -373,8 +373,8 @@
       {
           try
           {
  -            return hasPermission(TurbineSecurity.getPermission(permission),
  -                    TurbineSecurity.getGroup(group));
  +            return hasPermission(TurbineSecurity.getPermissionByName(permission),
  +                    TurbineSecurity.getGroupByName(group));
           }
           catch (Exception e)
           {
  @@ -394,7 +394,7 @@
           try
           {
               return hasPermission(
  -                    TurbineSecurity.getPermission(permission), group);
  +                    TurbineSecurity.getPermissionByName(permission), group);
           }
           catch (Exception e)
           {
  @@ -416,7 +416,7 @@
           Permission permission;
           try
           {
  -            permission = TurbineSecurity.getPermission(permissionName);
  +            permission = TurbineSecurity.getPermissionByName(permissionName);
           }
           catch (TurbineSecurityException e)
           {
  @@ -462,7 +462,7 @@
       {
           try
           {
  -            return hasPermission(TurbineSecurity.getPermission(permission));
  +            return hasPermission(TurbineSecurity.getPermissionByName(permission));
           }
           catch (Exception e)
           {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org