craigmcc    02/02/02 16:56:58

  Modified:    catalina/src/share/org/apache/catalina Group.java Role.java
                        User.java UserDatabase.java
               catalina/src/share/org/apache/catalina/mbeans
                        GlobalResourcesLifecycleListener.java
                        GroupMBean.java MBeanUtils.java
                        MemoryUserDatabaseMBean.java UserMBean.java
                        mbeans-descriptors.xml
               catalina/src/share/org/apache/catalina/realm
                        UserDatabaseRealm.java
               catalina/src/share/org/apache/catalina/users
                        AbstractGroup.java AbstractUser.java
                        MemoryGroup.java MemoryUser.java
                        MemoryUserDatabase.java
                        MemoryUserDatabaseFactory.java
  Added:       catalina/src/share/org/apache/catalina/mbeans RoleMBean.java
               catalina/src/share/org/apache/catalina/users
                        AbstractRole.java MemoryRole.java
  Removed:     catalina/src/share/org/apache/catalina/users BasicRole.java
  Log:
  Updates to the UserDatabase and related interfaces (and
  implementations) to make Role a first-class object in the
  user database.  This will allow the user interface for
  editing groups and users to list all the currently defined
  roles and let the user pick them with checkboxes, instead
  of having to type a comma-delimited list of names.
  
  Currently, the user and group admin screens are out-of-date
  with respect to the changes in the underlying MBeans.  That
  will be the next commit.
  
  Revision  Changes    Path
  1.4       +12 -16    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Group.java
  
  Index: Group.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Group.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Group.java        24 Jan 2002 22:45:54 -0000      1.3
  +++ Group.java        3 Feb 2002 00:56:57 -0000       1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Group.java,v 1.3 
2002/01/24 22:45:54 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/01/24 22:45:54 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Group.java,v 1.4 
2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -71,10 +71,10 @@
   /**
    * <p>Abstract representation of a group of {@link User}s in a
    * {@link UserDatabase}.  Each user that is a member of this group
  - * inherits the security roles assigned to the group.</p>
  + * inherits the {@link Role}s assigned to the group.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2002/01/24 22:45:54 $
  + * @version $Revision: 1.4 $ $Date: 2002/02/03 00:56:57 $
    * @since 4.1
    */
   
  @@ -115,8 +115,7 @@
   
   
       /**
  -     * Return the set of security roles assigned specifically to this group,
  -     * as Strings.
  +     * Return the set of {@link Role}s assigned specifically to this group.
        */
       public Iterator getRoles();
   
  @@ -137,30 +136,27 @@
   
   
       /**
  -     * Add a new security role to those assigned specifically to this group.
  +     * Add a new {@link Role} to those assigned specifically to this group.
        *
        * @param role The new role
        */
  -    public void addRole(String role);
  +    public void addRole(Role role);
   
   
       /**
  -     * Is this group specifically assigned the specified role?
  +     * Is this group specifically assigned the specified {@link Role}?
        *
        * @param role The role to check
        */
  -    public boolean isInRole(String role);
  +    public boolean isInRole(Role role);
   
   
       /**
  -     * Remove a security role from those assigned to this group.
  +     * Remove a {@link Role} from those assigned to this group.
        *
        * @param role The old role
        */
  -    public void removeRole(String role);
  -
  -
  -
  +    public void removeRole(Role role);
   
   
   }
  
  
  
  1.2       +41 -5     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Role.java
  
  Index: Role.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Role.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Role.java 24 Jan 2002 22:45:54 -0000      1.1
  +++ Role.java 3 Feb 2002 00:56:57 -0000       1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Role.java,v 1.1 
2002/01/24 22:45:54 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/01/24 22:45:54 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Role.java,v 1.2 
2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -72,14 +72,50 @@
    * environments like JAAS that want to deal with <code>Principals</code>.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2002/01/24 22:45:54 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/03 00:56:57 $
    * @since 4.1
    */
   
   public interface Role extends Principal {
   
   
  -    // No additional methods required
  +    // ------------------------------------------------------------- Properties
  +
  +
  +    /**
  +     * Return the description of this role.
  +     */
  +    public String getDescription();
  +
  +
  +    /**
  +     * Set the description of this role.
  +     *
  +     * @param description The new description
  +     */
  +    public void setDescription(String description);
  +
  +
  +    /**
  +     * Return the role name of this role, which must be unique
  +     * within the scope of a {@link UserDatabase}.
  +     */
  +    public String getRolename();
  +
  +
  +    /**
  +     * Set the role name of this role, which must be unique
  +     * within the scope of a {@link UserDatabase}.
  +     *
  +     * @param rolename The new role name
  +     */
  +    public void setRolename(String rolename);
  +
  +
  +    /**
  +     * Return the {@link UserDatabase} within which this Role is defined.
  +     */
  +    public UserDatabase getUserDatabase();
   
   
   }
  
  
  
  1.4       +15 -16    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/User.java
  
  Index: User.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/User.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- User.java 24 Jan 2002 22:45:54 -0000      1.3
  +++ User.java 3 Feb 2002 00:56:57 -0000       1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/User.java,v 1.3 
2002/01/24 22:45:54 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/01/24 22:45:54 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/User.java,v 1.4 
2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -72,10 +72,10 @@
    * <p>Abstract representation of a user in a {@link UserDatabase}.  Each user
    * is optionally associated with a set of {@link Group}s through which he or
    * she inherits additional security roles, and is optionally assigned a set
  - * of specific security roles.</p>
  + * of specific {@link Role}s.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2002/01/24 22:45:54 $
  + * @version $Revision: 1.4 $ $Date: 2002/02/03 00:56:57 $
    * @since 4.1
    */
   
  @@ -124,8 +124,7 @@
   
   
       /**
  -     * Return the set of security roles assigned specifically to this user,
  -     * as Strings.
  +     * Return the set of {@link Role}s assigned specifically to this user.
        */
       public Iterator getRoles();
   
  @@ -164,15 +163,15 @@
   
   
       /**
  -     * Add a new security role to those assigned specifically to this user.
  +     * Add a {@link Role} to those assigned specifically to this user.
        *
        * @param role The new role
        */
  -    public void addRole(String role);
  +    public void addRole(Role role);
   
   
       /**
  -     * Is this user in the specified group?
  +     * Is this user in the specified {@link Group}?
        *
        * @param group The group to check
        */
  @@ -180,13 +179,13 @@
   
   
       /**
  -     * Is this user specifically assigned the specified role?  This method
  -     * does <strong>NOT</strong> check for roles inherited based on group
  -     * membership.
  +     * Is this user specifically assigned the specified {@link Role}?  This
  +     * method does <strong>NOT</strong> check for roles inherited based on
  +     * {@link Group} membership.
        *
        * @param role The role to check
        */
  -    public boolean isInRole(String role);
  +    public boolean isInRole(Role role);
   
   
       /**
  @@ -198,11 +197,11 @@
   
   
       /**
  -     * Remove a security role from those assigned to this user.
  +     * Remove a {@link Role} from those assigned to this user.
        *
        * @param role The old role
        */
  -    public void removeRole(String role);
  +    public void removeRole(Role role);
   
   
   }
  
  
  
  1.3       +38 -6     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/UserDatabase.java
  
  Index: UserDatabase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/UserDatabase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UserDatabase.java 22 Jan 2002 23:22:23 -0000      1.2
  +++ UserDatabase.java 3 Feb 2002 00:56:57 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/UserDatabase.java,v
 1.2 2002/01/22 23:22:23 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/22 23:22:23 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/UserDatabase.java,v
 1.3 2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -69,11 +69,12 @@
   
   /**
    * <p>Abstract representation of a database of {@link User}s and
  - * {@link Group}s that can be maintained by an application, and
  + * {@link Group}s that can be maintained by an application,
  + * along with definitions of corresponding {@link Role}s, and
    * referenced by a {@link Realm} for authentication and access control.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/22 23:22:23 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:57 $
    * @since 4.1
    */
   
  @@ -96,12 +97,17 @@
   
   
       /**
  +     * Return the set of {@link Role}s defined in this user database.
  +     */
  +    public Iterator getRoles();
  +
  +
  +    /**
        * Return the set of {@link User}s defined in this user database.
        */
       public Iterator getUsers();
   
   
  -
       // --------------------------------------------------------- Public Methods
   
   
  @@ -123,6 +129,15 @@
   
   
       /**
  +     * Create and return a new {@link Role} defined in this user database.
  +     *
  +     * @param rolename The role name of the new role (must be unique)
  +     * @param description The description of this role
  +     */
  +    public Role createRole(String rolename, String description);
  +
  +
  +    /**
        * Create and return a new {@link User} defined in this user database.
        *
        * @param username The logon username of the new user (must be unique)
  @@ -143,6 +158,15 @@
   
   
       /**
  +     * Return the {@link Role} with the specified role name, if any;
  +     * otherwise return <code>null</code>.
  +     *
  +     * @param rolename Name of the role to return
  +     */
  +    public Role findRole(String rolename);
  +
  +
  +    /**
        * Return the {@link User} with the specified user name, if any;
        * otherwise return <code>null</code>.
        *
  @@ -165,6 +189,14 @@
        * @param group The group to be removed
        */
       public void removeGroup(Group group);
  +
  +
  +    /**
  +     * Remove the specified {@link Role} from this user database.
  +     *
  +     * @param role The role to be removed
  +     */
  +    public void removeRole(Role role);
   
   
       /**
  
  
  
  1.3       +39 -7     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java
  
  Index: GlobalResourcesLifecycleListener.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GlobalResourcesLifecycleListener.java     23 Jan 2002 02:38:01 -0000      1.2
  +++ GlobalResourcesLifecycleListener.java     3 Feb 2002 00:56:57 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java,v
 1.2 2002/01/23 02:38:01 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/23 02:38:01 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java,v
 1.3 2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    *
  @@ -77,6 +77,7 @@
   import org.apache.catalina.Lifecycle;
   import org.apache.catalina.LifecycleEvent;
   import org.apache.catalina.LifecycleListener;
  +import org.apache.catalina.Role;
   import org.apache.catalina.Server;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
  @@ -91,7 +92,7 @@
    * management.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/23 02:38:01 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:57 $
    * @since 4.1
    */
   
  @@ -241,6 +242,19 @@
                   ("Cannot create UserDatabase MBean for resource " + name);
           }
   
  +        // Create the MBeans for each defined Role
  +        Iterator roles = database.getRoles();
  +        while (roles.hasNext()) {
  +            Role role = (Role) roles.next();
  +            if (debug >= 3) {
  +                log("  Creating Role MBean for role " + role);
  +            }
  +            if (MBeanUtils.createMBean(role) == null) {
  +                throw new IllegalArgumentException
  +                    ("Cannot create Role MBean for role " + role);
  +            }
  +        }
  +
           // Create the MBeans for each defined Group
           Iterator groups = database.getGroups();
           while (groups.hasNext()) {
  @@ -282,6 +296,13 @@
       }
   
   
  +
  +    /**
  +     * The destination for log messages.
  +     */
  +    protected java.io.PrintStream  stream = System.out;
  +
  +
       /**
        * Log a message.
        *
  @@ -289,8 +310,19 @@
        */
       protected void log(String message) {
   
  -        System.out.print("GlobalResourcesLifecycleListener: ");
  -        System.out.println(message);
  +        /*
  +        if (stream == System.out) {
  +            try {
  +                stream = new java.io.PrintStream
  +                             (new java.io.FileOutputStream("grll.log"));
  +            } catch (Throwable t) {
  +                ;
  +            }
  +        }
  +        */
  +
  +        stream.print("GlobalResourcesLifecycleListener: ");
  +        stream.println(message);
   
       }
   
  @@ -304,7 +336,7 @@
       protected void log(String message, Throwable throwable) {
   
           log(message);
  -        throwable.printStackTrace(System.out);
  +        throwable.printStackTrace(stream);
   
       }
   
  
  
  
  1.2       +57 -5     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GroupMBean.java
  
  Index: GroupMBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GroupMBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GroupMBean.java   22 Jan 2002 23:22:23 -0000      1.1
  +++ GroupMBean.java   3 Feb 2002 00:56:57 -0000       1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GroupMBean.java,v
 1.1 2002/01/22 23:22:23 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/01/22 23:22:23 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GroupMBean.java,v
 1.2 2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   import javax.management.ObjectName;
   import javax.management.RuntimeOperationsException;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
   import org.apache.commons.modeler.BaseModelMBean;
  @@ -84,7 +85,7 @@
    * <code>org.apache.catalina.Group</code> component.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2002/01/22 23:22:23 $
  + * @version $Revision: 1.2 $ $Date: 2002/02/03 00:56:57 $
    */
   
   public class GroupMBean extends BaseModelMBean {
  @@ -136,7 +137,7 @@
   
   
       /**
  -     * Return the set of authorized roles for this group.
  +     * Return the MBean Names of all authorized roles for this group.
        */
       public String[] getRoles() {
   
  @@ -144,7 +145,16 @@
           ArrayList results = new ArrayList();
           Iterator roles = group.getRoles();
           while (roles.hasNext()) {
  -            results.add(roles.next());
  +            Role role = null;
  +            try {
  +                role = (Role) roles.next();
  +                ObjectName oname =
  +                    MBeanUtils.createObjectName(managed.getDomain(), role);
  +                results.add(oname.toString());
  +            } catch (MalformedObjectNameException e) {
  +                throw new IllegalArgumentException
  +                    ("Cannot create object name for role " + role);
  +            }
           }
           return ((String[]) results.toArray(new String[results.size()]));
   
  @@ -177,6 +187,48 @@
   
   
       // ------------------------------------------------------------- Operations
  +
  +
  +    /**
  +     * Add a new {@link Role} to those this group belongs to.
  +     *
  +     * @param rolename Role name of the new role
  +     */
  +    public void addRole(String rolename) {
  +
  +        Group group = (Group) this.resource;
  +        if (group == null) {
  +            return;
  +        }
  +        Role role = group.getUserDatabase().findRole(rolename);
  +        if (role == null) {
  +            throw new IllegalArgumentException
  +                ("Invalid role name '" + rolename + "'");
  +        }
  +        group.addRole(role);
  +
  +    }
  +
  +
  +    /**
  +     * Remove a {@link Role} from those this group belongs to.
  +     *
  +     * @param rolename Role name of the old role
  +     */
  +    public void removeRole(String rolename) {
  +
  +        Group group = (Group) this.resource;
  +        if (group == null) {
  +            return;
  +        }
  +        Role role = group.getUserDatabase().findRole(rolename);
  +        if (role == null) {
  +            throw new IllegalArgumentException
  +                ("Invalid role name '" + rolename + "'");
  +        }
  +        group.removeRole(role);
  +
  +    }
   
   
   }
  
  
  
  1.17      +83 -6     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java
  
  Index: MBeanUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- MBeanUtils.java   25 Jan 2002 23:15:09 -0000      1.16
  +++ MBeanUtils.java   3 Feb 2002 00:56:57 -0000       1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
 1.16 2002/01/25 23:15:09 amyroh Exp $
  - * $Revision: 1.16 $
  - * $Date: 2002/01/25 23:15:09 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
 1.17 2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.17 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    *
  @@ -89,6 +89,7 @@
   import org.apache.catalina.Logger;
   import org.apache.catalina.Manager;
   import org.apache.catalina.Realm;
  +import org.apache.catalina.Role;
   import org.apache.catalina.Server;
   import org.apache.catalina.ServerFactory;
   import org.apache.catalina.Service;
  @@ -106,7 +107,7 @@
    *
    * @author Craig R. McClanahan
    * @author Amy Roh
  - * @version $Revision: 1.16 $ $Date: 2002/01/25 23:15:09 $
  + * @version $Revision: 1.17 $ $Date: 2002/02/03 00:56:57 $
    */
   
   public class MBeanUtils {
  @@ -127,6 +128,8 @@
             "Http11Connector" },
           { "org.apache.catalina.users.MemoryGroup",
             "Group" },
  +        { "org.apache.catalina.users.MemoryRole",
  +          "Role" },
           { "org.apache.catalina.users.MemoryUser",
             "User" },
       };
  @@ -451,6 +454,33 @@
   
       /**
        * Create, register, and return an MBean for this
  +     * <code>Role</code> object.
  +     *
  +     * @param role The Role to be managed
  +     *
  +     * @exception Exception if an MBean cannot be created or registered
  +     */
  +    public static ModelMBean createMBean(Role role)
  +        throws Exception {
  +
  +        String mname = createManagedName(role);
  +        ManagedBean managed = registry.findManagedBean(mname);
  +        if (managed == null) {
  +            return null;
  +        }
  +        String domain = managed.getDomain();
  +        if (domain == null)
  +            domain = mserver.getDefaultDomain();
  +        ModelMBean mbean = managed.createMBean(role);
  +        ObjectName oname = createObjectName(domain, role);
  +        mserver.registerMBean(mbean, oname);
  +        return (mbean);
  +
  +    }
  +
  +
  +    /**
  +     * Create, register, and return an MBean for this
        * <code>Server</code> object.
        *
        * @param server The Server to be managed
  @@ -880,7 +910,7 @@
   
       }
   
  -    
  +
       /**
        * Create an <code>ObjectName</code> for this
        * <code>Realm</code> object.
  @@ -927,6 +957,28 @@
   
       /**
        * Create an <code>ObjectName</code> for this
  +     * <code>Role</code> object.
  +     *
  +     * @param domain Domain in which this name is to be created
  +     * @param role The Role to be named
  +     *
  +     * @exception MalformedObjectNameException if a name cannot be created
  +     */
  +    public static ObjectName createObjectName(String domain,
  +                                              Role role)
  +        throws MalformedObjectNameException {
  +
  +        ObjectName name = null;
  +        name = new ObjectName(domain + ":type=Role,rolename=" +
  +                              role.getRolename() + ",database=" +
  +                              role.getUserDatabase().getId());
  +        return (name);
  +
  +    }
  +
  +
  +    /**
  +     * Create an <code>ObjectName</code> for this
        * <code>Server</code> object.
        *
        * @param domain Domain in which this name is to be created
  @@ -1258,7 +1310,7 @@
           mserver.unregisterMBean(oname);
   
       }
  -    
  +
   
       /**
        * Deregister the MBean for this
  @@ -1354,6 +1406,31 @@
           if (domain == null)
               domain = mserver.getDefaultDomain();
           ObjectName oname = createObjectName(domain, realm);
  +        mserver.unregisterMBean(oname);
  +
  +    }
  +
  +
  +    /**
  +     * Deregister the MBean for this
  +     * <code>Role</code> object.
  +     *
  +     * @param role The Role to be managed
  +     *
  +     * @exception Exception if an MBean cannot be deregistered
  +     */
  +    public static void destroyMBean(Role role)
  +        throws Exception {
  +
  +        String mname = createManagedName(role);
  +        ManagedBean managed = registry.findManagedBean(mname);
  +        if (managed == null) {
  +            return;
  +        }
  +        String domain = managed.getDomain();
  +        if (domain == null)
  +            domain = mserver.getDefaultDomain();
  +        ObjectName oname = createObjectName(domain, role);
           mserver.unregisterMBean(oname);
   
       }
  
  
  
  1.3       +111 -7    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java
  
  Index: MemoryUserDatabaseMBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MemoryUserDatabaseMBean.java      23 Jan 2002 01:23:57 -0000      1.2
  +++ MemoryUserDatabaseMBean.java      3 Feb 2002 00:56:57 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java,v
 1.2 2002/01/23 01:23:57 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/23 01:23:57 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java,v
 1.3 2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   import javax.management.ObjectName;
   import javax.management.RuntimeOperationsException;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
   import org.apache.commons.modeler.BaseModelMBean;
  @@ -84,7 +85,7 @@
    * <code>org.apache.catalina.users.MemoryUserDatabase</code> component.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/23 01:23:57 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:57 $
    */
   
   public class MemoryUserDatabaseMBean extends BaseModelMBean {
  @@ -140,6 +141,13 @@
   
   
       /**
  +     * The <code>ManagedBean</code> information describing Group MBeans.
  +     */
  +    protected ManagedBean managedRole =
  +        registry.findManagedBean("Role");
  +
  +
  +    /**
        * The <code>ManagedBean</code> information describing User MBeans.
        */
       protected ManagedBean managedUser =
  @@ -167,6 +175,23 @@
   
   
       /**
  +     * Return the MBean Names of all roles defined in this database.
  +     */
  +    public String[] getRoles() {
  +
  +        UserDatabase database = (UserDatabase) this.resource;
  +        ArrayList results = new ArrayList();
  +        Iterator roles = database.getRoles();
  +        while (roles.hasNext()) {
  +            Role role = (Role) roles.next();
  +            results.add(findRole(role.getRolename()));
  +        }
  +        return ((String[]) results.toArray(new String[results.size()]));
  +
  +    }
  +
  +
  +    /**
        * Return the MBean Names of all users defined in this database.
        */
       public String[] getUsers() {
  @@ -179,7 +204,7 @@
               results.add(findUser(user.getUsername()));
           }
           return ((String[]) results.toArray(new String[results.size()]));
  -                                            
  +
       }
   
   
  @@ -200,7 +225,12 @@
           Group group = database.createGroup(groupname, description);
           if (roles != null) {
               for (int i = 0; i < roles.length; i++) {
  -                group.addRole(roles[i]);
  +                Role role = database.findRole(roles[i]);
  +                if (role == null) {
  +                    createRole(roles[i], null);
  +                    role = database.findRole(roles[i]);
  +                }
  +                group.addRole(role);
               }
           }
           try {
  @@ -215,6 +245,27 @@
   
   
       /**
  +     * Create a new Role and return the corresponding MBean Name.
  +     *
  +     * @param rolename Group name of the new group
  +     * @param description Description of the new group
  +     */
  +    public String createRole(String rolename, String description) {
  +
  +        UserDatabase database = (UserDatabase) this.resource;
  +        Role role = database.createRole(rolename, description);
  +        try {
  +            MBeanUtils.createMBean(role);
  +        } catch (Exception e) {
  +            throw new IllegalArgumentException("Exception creating role " +
  +                                               role + " MBean: " + e);
  +        }
  +        return (findRole(rolename));
  +
  +    }
  +
  +
  +    /**
        * Create a new User and return the corresponding MBean Name.
        *
        * @param username User name of the new user
  @@ -229,7 +280,12 @@
           User user = database.createUser(username, password, fullName);
           if (roles != null) {
               for (int i = 0; i < roles.length; i++) {
  -                user.addRole(roles[i]);
  +                Role role = database.findRole(roles[i]);
  +                if (role == null) {
  +                    createRole(roles[i], null);
  +                    role = database.findRole(roles[i]);
  +                }
  +                user.addRole(role);
               }
           }
           try {
  @@ -269,6 +325,31 @@
   
   
       /**
  +     * Return the MBean Name for the specified role name (if any);
  +     * otherwise return <code>null</code>.
  +     *
  +     * @param rolename Role name to look up
  +     */
  +    public String findRole(String rolename) {
  +
  +        UserDatabase database = (UserDatabase) this.resource;
  +        Role role = database.findRole(rolename);
  +        if (role == null) {
  +            return (null);
  +        }
  +        try {
  +            ObjectName oname =
  +                MBeanUtils.createObjectName(managedRole.getDomain(), role);
  +            return (oname.toString());
  +        } catch (MalformedObjectNameException e) {
  +            throw new IllegalArgumentException
  +                ("Cannot create object name for role " + role);
  +        }
  +
  +    }
  +
  +
  +    /**
        * Return the MBean Name for the specified user name (if any);
        * otherwise return <code>null</code>.
        *
  @@ -311,6 +392,29 @@
           } catch (Exception e) {
               throw new IllegalArgumentException("Exception destroying group " +
                                                  group + " MBean: " + e);
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Remove an existing role and destroy the corresponding MBean.
  +     *
  +     * @param rolename Role name to remove
  +     */
  +    public void removeRole(String rolename) {
  +
  +        UserDatabase database = (UserDatabase) this.resource;
  +        Role role = database.findRole(rolename);
  +        if (role == null) {
  +            return;
  +        }
  +        try {
  +            MBeanUtils.destroyMBean(role);
  +            database.removeRole(role);
  +        } catch (Exception e) {
  +            throw new IllegalArgumentException("Exception destroying role " +
  +                                               role + " MBean: " + e);
           }
   
       }
  
  
  
  1.3       +58 -22    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java
  
  Index: UserMBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UserMBean.java    30 Jan 2002 02:05:44 -0000      1.2
  +++ UserMBean.java    3 Feb 2002 00:56:57 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java,v
 1.2 2002/01/30 02:05:44 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/30 02:05:44 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java,v
 1.3 2002/02/03 00:56:57 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:57 $
    *
    * ====================================================================
    *
  @@ -72,6 +72,7 @@
   import javax.management.ObjectName;
   import javax.management.RuntimeOperationsException;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
   import org.apache.commons.modeler.BaseModelMBean;
  @@ -84,7 +85,7 @@
    * <code>org.apache.catalina.User</code> component.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/30 02:05:44 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:57 $
    */
   
   public class UserMBean extends BaseModelMBean {
  @@ -136,7 +137,7 @@
   
   
       /**
  -     * Return the MBean Names of all groups this user is a member of
  +     * Return the MBean Names of all groups this user is a member of.
        */
       public String[] getGroups() {
   
  @@ -161,7 +162,7 @@
   
   
       /**
  -     * Return the set of authorized roles for this user.
  +     * Return the MBean Names of all roles assigned to this user.
        */
       public String[] getRoles() {
   
  @@ -169,24 +170,18 @@
           ArrayList results = new ArrayList();
           Iterator roles = user.getRoles();
           while (roles.hasNext()) {
  -            results.add(roles.next());
  -        }
  -        return ((String[]) results.toArray(new String[results.size()]));
  -
  -    }
  -
  -
  -    /**
  -     * Update the set of authorized roles for this user.
  -     */
  -    public void setRoles(String roles[]) {
  -
  -        if (roles != null) {
  -            User user = (User) this.resource;
  -            for (int i = 0; i < roles.length; i++) {
  -                user.addRole(roles[i]);
  +            Role role = null;
  +            try {
  +                role = (Role) roles.next();
  +                ObjectName oname =
  +                    MBeanUtils.createObjectName(managed.getDomain(), role);
  +                results.add(oname.toString());
  +            } catch (MalformedObjectNameException e) {
  +                throw new IllegalArgumentException
  +                    ("Cannot create object name for role " + role);
               }
           }
  +        return ((String[]) results.toArray(new String[results.size()]));
   
       }
   
  @@ -216,6 +211,27 @@
   
   
       /**
  +     * Add a new {@link Role} to those this user belongs to.
  +     *
  +     * @param rolename Role name of the new role
  +     */
  +    public void addRole(String rolename) {
  +
  +        User user = (User) this.resource;
  +        if (user == null) {
  +            return;
  +        }
  +        Role role = user.getUserDatabase().findRole(rolename);
  +        if (role == null) {
  +            throw new IllegalArgumentException
  +                ("Invalid role name '" + rolename + "'");
  +        }
  +        user.addRole(role);
  +
  +    }
  +
  +
  +    /**
        * Remove a {@link Group} from those this user belongs to.
        *
        * @param groupname Group name of the old group
  @@ -235,6 +251,26 @@
   
       }
   
  +
  +    /**
  +     * Remove a {@link Role} from those this user belongs to.
  +     *
  +     * @param rolename Role name of the old role
  +     */
  +    public void removeRole(String rolename) {
  +
  +        User user = (User) this.resource;
  +        if (user == null) {
  +            return;
  +        }
  +        Role role = user.getUserDatabase().findRole(rolename);
  +        if (role == null) {
  +            throw new IllegalArgumentException
  +                ("Invalid role name '" + rolename + "'");
  +        }
  +        user.removeRole(role);
  +
  +    }
   
   
   }
  
  
  
  1.26      +63 -9     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml
  
  Index: mbeans-descriptors.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- mbeans-descriptors.xml    31 Jan 2002 23:02:41 -0000      1.25
  +++ mbeans-descriptors.xml    3 Feb 2002 00:56:57 -0000       1.26
  @@ -6,7 +6,7 @@
   <!--
        Descriptions of JMX MBeans for Catalina
   
  -     $Id: mbeans-descriptors.xml,v 1.25 2002/01/31 23:02:41 amyroh Exp $
  +     $Id: mbeans-descriptors.xml,v 1.26 2002/02/03 00:56:57 craigmcc Exp $
    -->
   
   <mbeans-descriptors>
  @@ -134,13 +134,14 @@
                    type="java.lang.String"/>
   
       <attribute   name="roles"
  -          description="Authorized roles for this group"
  +          description="MBean Names of roles for this group"
                    type="java.lang.String[]"
               writeable="false"/>
   
       <attribute   name="users"
             description="MBean Names of user members of this group"
  -                 type="java.lang.String[]"/>
  +                 type="java.lang.String[]"
  +            writeable="false"/>
   
       <operation   name="addRole"
             description="Add a new authorized role for this group"
  @@ -679,6 +680,11 @@
             description="Relative or absolute pathname to database file"
                    type="java.lang.String"/>
   
  +    <attribute   name="roles"
  +          description="MBean Names of all defined roles"
  +                 type="java.lang.String[]"
  +            writeable="false"/>
  +
       <attribute   name="users"
             description="MBean Names of all defined users"
                    type="java.lang.String[]"
  @@ -699,6 +705,18 @@
                    type="java.lang.String[]"/>
       </operation>
   
  +    <operation   name="createRole"
  +          description="Create new role and return MBean name"
  +               impact="ACTION"
  +           returnType="java.lang.String">
  +      <parameter name="rolename"
  +          description="Role name of the new role"
  +                 type="java.lang.String"/>
  +      <parameter name="description"
  +          description="Description of the new role"
  +                 type="java.lang.String"/>
  +    </operation>
  +
       <operation   name="createUser"
             description="Create new user and return MBean name"
                  impact="ACTION"
  @@ -726,6 +744,15 @@
                    type="java.lang.String"/>
       </operation>
   
  +    <operation   name="findRole"
  +          description="Return MBean Name of the specified role (if any)"
  +               impact="INFO"
  +           returnType="java.lang.String">
  +      <parameter name="rolename"
  +          description="Role name of the requested role"
  +                 type="java.lang.String"/>
  +    </operation>
  +
       <operation   name="findUser"
             description="Return MBean Name of the specified user (if any)"
                  impact="INFO"
  @@ -744,6 +771,15 @@
                    type="java.lang.String"/>
       </operation>
   
  +    <operation   name="removeRole"
  +          description="Remove existing role"
  +               impact="ACTION"
  +           returnType="void">
  +      <parameter name="rolename"
  +          description="Role name of the role to remove"
  +                 type="java.lang.String"/>
  +    </operation>
  +
       <operation   name="removeUser"
             description="Remove existing user (and all group memberships)"
                  impact="ACTION"
  @@ -835,6 +871,24 @@
     </mbean>
   
   
  +  <mbean         name="Role"
  +            className="org.apache.catalina.mbeans.RoleMBean"
  +          description="Security role from a user database"
  +               domain="Users"
  +                group="Role"
  +                 type="org.apache.catalina.Role">
  +
  +    <attribute   name="description"
  +          description="Description of this role"
  +                 type="java.lang.String"/>
  +
  +    <attribute   name="rolename"
  +          description="Role name of this role"
  +                 type="java.lang.String"/>
  +
  +  </mbean>
  +
  +
     <mbean         name="SingleSignOn"
               className="org.apache.catalina.mbeans.ClassNameMBean"
             description="A Valve that supports a 'single signon' user experience"
  @@ -981,7 +1035,7 @@
       <attribute   name="managedResource"
             description="The managed resource this MBean is associated with"
                    type="java.lang.Object"/>
  -                 
  +
       <attribute   name="name"
             description="Unique name of this Engine"
                    type="java.lang.String"/>
  @@ -1061,7 +1115,7 @@
       <attribute   name="managedResource"
             description="The managed resource this MBean is associated with"
                    type="java.lang.Object"/>
  -                 
  +
       <attribute   name="name"
             description="Unique name of this Host"
                    type="java.lang.String"/>
  @@ -1186,7 +1240,7 @@
       <attribute   name="managedResource"
             description="The managed resource this MBean is associated with"
                    type="java.lang.Object"/>
  -                 
  +
       <attribute   name="maxActiveSessions"
             description="The maximum number of active Sessions allowed, or -1 for no 
limit"
                    type="int"/>
  @@ -1221,7 +1275,7 @@
       <attribute   name="managedResource"
             description="The managed resource this MBean is associated with"
                    type="java.lang.Object"/>
  -                 
  +
       <attribute   name="port"
             description="TCP port for shutdown messages"
                    type="int"/>
  @@ -1257,7 +1311,7 @@
                  domain="Catalina"
                   group="Service"
                    type="org.apache.catalina.core.StandardService">
  -                 
  +
       <attribute   name="managedResource"
             description="The managed resource this MBean is associated with"
                    type="java.lang.Object"/>
  @@ -1353,7 +1407,7 @@
                    type="java.lang.String"/>
   
       <attribute   name="roles"
  -          description="Authorized roles for this user"
  +          description="MBean Names of roles for this user"
                    type="java.lang.String[]"
               writeable="false"/>
   
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/RoleMBean.java
  
  Index: RoleMBean.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/RoleMBean.java,v
 1.1 2002/02/03 00:56:57 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/03 00:56:57 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.catalina.mbeans;
  
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import javax.management.MalformedObjectNameException;
  import javax.management.MBeanException;
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  import javax.management.RuntimeOperationsException;
  import org.apache.catalina.Group;
  import org.apache.catalina.Role;
  import org.apache.catalina.User;
  import org.apache.catalina.UserDatabase;
  import org.apache.commons.modeler.BaseModelMBean;
  import org.apache.commons.modeler.ManagedBean;
  import org.apache.commons.modeler.Registry;
  
  
  /**
   * <p>A <strong>ModelMBean</strong> implementation for the
   * <code>org.apache.catalina.Role</code> component.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2002/02/03 00:56:57 $
   */
  
  public class RoleMBean extends BaseModelMBean {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a <code>ModelMBean</code> with default
       * <code>ModelMBeanInfo</code> information.
       *
       * @exception MBeanException if the initializer of an object
       *  throws an exception
       * @exception RuntimeOperationsException if an IllegalArgumentException
       *  occurs
       */
      public RoleMBean()
          throws MBeanException, RuntimeOperationsException {
  
          super();
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The configuration information registry for our managed beans.
       */
      protected Registry registry = MBeanUtils.createRegistry();
  
  
      /**
       * The <code>MBeanServer</code> in which we are registered.
       */
      protected MBeanServer mserver = MBeanUtils.createServer();
  
  
      /**
       * The <code>ManagedBean</code> information describing this MBean.
       */
      protected ManagedBean managed =
          registry.findManagedBean("Role");
  
  
      // ------------------------------------------------------------- Attributes
  
  
      // ------------------------------------------------------------- Operations
  
  
  }
  
  
  
  1.5       +14 -11    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/realm/UserDatabaseRealm.java
  
  Index: UserDatabaseRealm.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/realm/UserDatabaseRealm.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UserDatabaseRealm.java    23 Jan 2002 02:35:33 -0000      1.4
  +++ UserDatabaseRealm.java    3 Feb 2002 00:56:58 -0000       1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/realm/UserDatabaseRealm.java,v
 1.4 2002/01/23 02:35:33 remm Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/01/23 02:35:33 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/realm/UserDatabaseRealm.java,v
 1.5 2002/02/03 00:56:58 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/03 00:56:58 $
    *
    * ====================================================================
    *
  @@ -79,6 +79,7 @@
   import org.apache.catalina.Group;
   import org.apache.catalina.Logger;
   import org.apache.catalina.Realm;
  +import org.apache.catalina.Role;
   import org.apache.catalina.Server;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
  @@ -95,7 +96,7 @@
    * of <code>UserDatabase</code> that we should consult.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2002/01/23 02:35:33 $
  + * @version $Revision: 1.5 $ $Date: 2002/02/03 00:56:58 $
    * @since 4.1
    */
   
  @@ -225,9 +226,10 @@
           ArrayList combined = new ArrayList();
           Iterator roles = user.getRoles();
           while (roles.hasNext()) {
  -            String role = (String) roles.next();
  -            if (!combined.contains(role)) {
  -                combined.add(role);
  +            Role role = (Role) roles.next();
  +            String rolename = role.getRolename();
  +            if (!combined.contains(rolename)) {
  +                combined.add(rolename);
               }
           }
           Iterator groups = user.getGroups();
  @@ -235,9 +237,10 @@
               Group group = (Group) groups.next();
               roles = group.getRoles();
               while (roles.hasNext()) {
  -                String role = (String) roles.next();
  -                if (!combined.contains(role)) {
  -                    combined.add(role);
  +                Role role = (Role) roles.next();
  +                String rolename = role.getRolename();
  +                if (!combined.contains(rolename)) {
  +                    combined.add(rolename);
                   }
               }
           }
  @@ -294,7 +297,7 @@
       public synchronized void start() throws LifecycleException {
   
           try {
  -            database = 
  +            database =
                   (UserDatabase) (new InitialContext()).lookup(resourceName);
           } catch (Throwable e) {
               e.printStackTrace();
  
  
  
  1.3       +19 -44    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractGroup.java
  
  Index: AbstractGroup.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractGroup.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractGroup.java        24 Jan 2002 22:45:54 -0000      1.2
  +++ AbstractGroup.java        3 Feb 2002 00:56:58 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractGroup.java,v
 1.2 2002/01/24 22:45:54 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/24 22:45:54 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractGroup.java,v
 1.3 2002/02/03 00:56:58 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:58 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -64,16 +64,18 @@
   package org.apache.catalina.users;
   
   
  -import java.util.ArrayList;
   import java.util.Iterator;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
  +import org.apache.catalina.User;
  +import org.apache.catalina.UserDatabase;
   
   
   /**
    * <p>Convenience base class for {@link Group} implementations.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/24 22:45:54 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:58 $
    * @since 4.1
    */
   
  @@ -95,12 +97,6 @@
       protected String groupname = null;
   
   
  -    /**
  -     * The set of security roles associated with this group.
  -     */
  -    protected ArrayList roles = new ArrayList();
  -
  -
       // ------------------------------------------------------------- Properties
   
   
  @@ -151,16 +147,15 @@
   
   
       /**
  -     * Return the set of security roles assigned specifically to this group,
  -     * as Strings.
  +     * Return the set of {@link Role}s assigned specifically to this group.
        */
  -    public Iterator getRoles() {
  +    public abstract Iterator getRoles();
   
  -        synchronized (roles) {
  -            return (roles.iterator());
  -        }
   
  -    }
  +    /**
  +     * Return the {@link UserDatabase} within which this Group is defined.
  +     */
  +    public abstract UserDatabase getUserDatabase();
   
   
       /**
  @@ -173,47 +168,27 @@
   
   
       /**
  -     * Add a new security role to those assigned specifically to this group.
  +     * Add a new {@link Role} to those assigned specifically to this group.
        *
        * @param role The new role
        */
  -    public void addRole(String role) {
  -
  -        synchronized (roles) {
  -            if (!roles.contains(role)) {
  -                roles.add(role);
  -            }
  -        }
  -
  -    }
  +    public abstract void addRole(Role role);
   
   
       /**
  -     * Is this group specifically assigned the specified role?
  +     * Is this group specifically assigned the specified {@link Role}?
        *
        * @param role The role to check
        */
  -    public boolean isInRole(String role) {
  -
  -        synchronized (roles) {
  -            return (roles.contains(role));
  -        }
  -
  -    }
  +    public abstract boolean isInRole(Role role);
   
   
       /**
  -     * Remove a security role from those assigned to this group.
  +     * Remove a {@link Role} from those assigned to this group.
        *
        * @param role The old role
        */
  -    public void removeRole(String role) {
  -
  -        synchronized (roles) {
  -            roles.remove(role);
  -        }
  -
  -    }
  +    public abstract void removeRole(Role role);
   
   
       // ------------------------------------------------------ Principal Methods
  
  
  
  1.3       +16 -49    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractUser.java
  
  Index: AbstractUser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractUser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractUser.java 24 Jan 2002 22:45:54 -0000      1.2
  +++ AbstractUser.java 3 Feb 2002 00:56:58 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractUser.java,v
 1.2 2002/01/24 22:45:54 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/24 22:45:54 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractUser.java,v
 1.3 2002/02/03 00:56:58 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:58 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -64,9 +64,9 @@
   package org.apache.catalina.users;
   
   
  -import java.util.ArrayList;
   import java.util.Iterator;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
   import org.apache.catalina.User;
   
   
  @@ -74,7 +74,7 @@
    * <p>Convenience base class for {@link User} implementations.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/24 22:45:54 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:58 $
    * @since 4.1
    */
   
  @@ -97,12 +97,6 @@
   
   
       /**
  -     * The set of security roles associated with this user.
  -     */
  -    protected ArrayList roles = new ArrayList();
  -
  -
  -    /**
        * The logon username of this user.
        */
       protected String username = null;
  @@ -166,16 +160,9 @@
   
   
       /**
  -     * Return the set of security roles assigned specifically to this user,
  -     * as Strings.
  +     * Return the set of {@link Role}s assigned specifically to this user.
        */
  -    public Iterator getRoles() {
  -
  -        synchronized (roles) {
  -            return (roles.iterator());
  -        }
  -
  -    }
  +    public abstract Iterator getRoles();
   
   
       /**
  @@ -214,23 +201,15 @@
   
   
       /**
  -     * Add a new security role to those assigned specifically to this user.
  +     * Add a new {@link Role} to those assigned specifically to this user.
        *
        * @param role The new role
        */
  -    public void addRole(String role) {
  -
  -        synchronized (roles) {
  -            if (!roles.contains(role)) {
  -                roles.add(role);
  -            }
  -        }
  -
  -    }
  +    public abstract void addRole(Role role);
   
   
       /**
  -     * Is this user in the specified group?
  +     * Is this user in the specified {@link Group}?
        *
        * @param group The group to check
        */
  @@ -238,19 +217,13 @@
   
   
       /**
  -     * Is this user specifically assigned the specified role?  This method
  -     * does <strong>NOT</strong> check for roles inherited based on group
  -     * membership.
  +     * Is this user specifically assigned the specified {@link Role}?  This
  +     * method does <strong>NOT</strong> check for roles inherited based on
  +     * {@link Group} membership.
        *
        * @param role The role to check
        */
  -    public boolean isInRole(String role) {
  -
  -        synchronized (roles) {
  -            return (roles.contains(role));
  -        }
  -
  -    }
  +    public abstract boolean isInRole(Role role);
   
   
       /**
  @@ -262,17 +235,11 @@
   
   
       /**
  -     * Remove a security role from those assigned to this user.
  +     * Remove a {@link Role} from those assigned to this user.
        *
        * @param role The old role
        */
  -    public void removeRole(String role) {
  -
  -        synchronized (roles) {
  -            roles.remove(role);
  -        }
  -
  -    }
  +    public abstract void removeRole(Role role);
   
   
       // ------------------------------------------------------ Principal Methods
  
  
  
  1.3       +72 -7     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryGroup.java
  
  Index: MemoryGroup.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryGroup.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MemoryGroup.java  22 Jan 2002 23:22:24 -0000      1.2
  +++ MemoryGroup.java  3 Feb 2002 00:56:58 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryGroup.java,v
 1.2 2002/01/22 23:22:24 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/22 23:22:24 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryGroup.java,v
 1.3 2002/02/03 00:56:58 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:58 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -67,6 +67,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
   
  @@ -76,7 +77,7 @@
    * {@link MemoryUserDatabase} implementation of {@link UserDatabase}.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/22 23:22:24 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:58 $
    * @since 4.1
    */
   
  @@ -114,7 +115,25 @@
       protected MemoryUserDatabase database = null;
   
   
  -    // --------------------------------------------------------- Public Methods
  +    /**
  +     * The set of {@link Role}s associated with this group.
  +     */
  +    protected ArrayList roles = new ArrayList();
  +
  +
  +    // ------------------------------------------------------------- Properties
  +
  +
  +    /**
  +     * Return the set of {@link Role}s assigned specifically to this group.
  +     */
  +    public Iterator getRoles() {
  +
  +        synchronized (roles) {
  +            return (roles.iterator());
  +        }
  +
  +    }
   
   
       /**
  @@ -132,7 +151,6 @@
        */
       public Iterator getUsers() {
   
  -        String groupname = getGroupname();
           ArrayList results = new ArrayList();
           Iterator users = database.getUsers();
           while (users.hasNext()) {
  @@ -146,6 +164,53 @@
       }
   
   
  +    // --------------------------------------------------------- Public Methods
  +
  +
  +    /**
  +     * Add a new {@link Role} to those assigned specifically to this group.
  +     *
  +     * @param role The new role
  +     */
  +    public void addRole(Role role) {
  +
  +        synchronized (roles) {
  +            if (!roles.contains(role)) {
  +                roles.add(role);
  +            }
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Is this group specifically assigned the specified {@link Role}?
  +     *
  +     * @param role The role to check
  +     */
  +    public boolean isInRole(Role role) {
  +
  +        synchronized (roles) {
  +            return (roles.contains(role));
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Remove a {@link Role} from those assigned to this group.
  +     *
  +     * @param role The old role
  +     */
  +    public void removeRole(Role role) {
  +
  +        synchronized (roles) {
  +            roles.remove(role);
  +        }
  +
  +    }
  +
  +
       /**
        * <p>Return a String representation of this group in XML format.</p>
        */
  @@ -169,7 +234,7 @@
                           sb.append(',');
                       }
                       n++;
  -                    sb.append((String) values.next());
  +                    sb.append((String) ((Role) values.next()).getRolename());
                   }
                   sb.append("'");
               }
  
  
  
  1.3       +74 -6     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUser.java
  
  Index: MemoryUser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MemoryUser.java   22 Jan 2002 23:22:24 -0000      1.2
  +++ MemoryUser.java   3 Feb 2002 00:56:58 -0000       1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUser.java,v
 1.2 2002/01/22 23:22:24 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/22 23:22:24 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUser.java,v
 1.3 2002/02/03 00:56:58 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/03 00:56:58 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -67,6 +67,7 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
   
  @@ -76,7 +77,7 @@
    * {@link MemoryUserDatabase} implementation of {@link UserDatabase}.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/22 23:22:24 $
  + * @version $Revision: 1.3 $ $Date: 2002/02/03 00:56:58 $
    * @since 4.1
    */
   
  @@ -122,7 +123,13 @@
       protected ArrayList groups = new ArrayList();
   
   
  -    // --------------------------------------------------------- Public Methods
  +    /**
  +     * The set of {@link Role}s associated with this user.
  +     */
  +    protected ArrayList roles = new ArrayList();
  +
  +
  +    // ------------------------------------------------------------- Properties
   
   
       /**
  @@ -138,6 +145,18 @@
   
   
       /**
  +     * Return the set of {@link Role}s assigned specifically to this user.
  +     */
  +    public Iterator getRoles() {
  +
  +        synchronized (roles) {
  +            return (roles.iterator());
  +        }
  +
  +    }
  +
  +
  +    /**
        * Return the {@link UserDatabase} within which this User is defined.
        */
       public UserDatabase getUserDatabase() {
  @@ -147,6 +166,9 @@
       }
   
   
  +    // --------------------------------------------------------- Public Methods
  +
  +
       /**
        * Add a new {@link Group} to those this user belongs to.
        *
  @@ -164,6 +186,22 @@
   
   
       /**
  +     * Add a new {@link Role} to those assigned specifically to this user.
  +     *
  +     * @param role The new role
  +     */
  +    public void addRole(Role role) {
  +
  +        synchronized (roles) {
  +            if (!roles.contains(role)) {
  +                roles.add(role);
  +            }
  +        }
  +
  +    }
  +
  +
  +    /**
        * Is this user in the specified group?
        *
        * @param group The group to check
  @@ -178,6 +216,22 @@
   
   
       /**
  +     * Is this user specifically assigned the specified {@link Role}?  This
  +     * method does <strong>NOT</strong> check for roles inherited based on
  +     * {@link Group} membership.
  +     *
  +     * @param role The role to check
  +     */
  +    public boolean isInRole(Role role) {
  +
  +        synchronized (roles) {
  +            return (roles.contains(role));
  +        }
  +
  +    }
  +
  +
  +    /**
        * Remove a {@link Group} from those this user belongs to.
        *
        * @param group The old group
  @@ -192,6 +246,20 @@
   
   
       /**
  +     * Remove a {@link Role} from those assigned to this user.
  +     *
  +     * @param role The old role
  +     */
  +    public void removeRole(Role role) {
  +
  +        synchronized (roles) {
  +            roles.remove(role);
  +        }
  +
  +    }
  +
  +
  +    /**
        * <p>Return a String representation of this user in XML format.</p>
        *
        * <p><strong>IMPLEMENTATION NOTE</strong> - For backwards compatibility,
  @@ -236,7 +304,7 @@
                           sb.append(',');
                       }
                       n++;
  -                    sb.append((String) values.next());
  +                    sb.append(((Role) values.next()).getRolename());
                   }
                   sb.append("'");
               }
  
  
  
  1.5       +156 -22   
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabase.java
  
  Index: MemoryUserDatabase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MemoryUserDatabase.java   23 Jan 2002 01:23:57 -0000      1.4
  +++ MemoryUserDatabase.java   3 Feb 2002 00:56:58 -0000       1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabase.java,v
 1.4 2002/01/23 01:23:57 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/01/23 01:23:57 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabase.java,v
 1.5 2002/02/03 00:56:58 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/03 00:56:58 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -73,6 +73,7 @@
   import java.util.HashMap;
   import java.util.Iterator;
   import org.apache.catalina.Group;
  +import org.apache.catalina.Role;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
   import org.apache.catalina.util.StringManager;
  @@ -83,11 +84,11 @@
   
   /**
    * <p>Concrete implementation of {@link UserDatabase} that loads all
  - * defined users and groups into an in-memory data structure, and uses
  - * a specified XML file for its persistent storage.</p>
  + * defined users, groups, and roles into an in-memory data structure,
  + * and uses a specified XML file for its persistent storage.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2002/01/23 01:23:57 $
  + * @version $Revision: 1.5 $ $Date: 2002/02/03 00:56:58 $
    * @since 4.1
    */
   
  @@ -158,6 +159,13 @@
   
   
       /**
  +     * The set of {@link Role}s defined in this database, keyed by
  +     * role name.
  +     */
  +    protected HashMap roles = new HashMap();
  +
  +
  +    /**
        * The string manager for this package.
        */
       private static StringManager sm =
  @@ -221,6 +229,18 @@
   
   
       /**
  +     * Return the set of {@link Role}s defined in this user database.
  +     */
  +    public Iterator getRoles() {
  +
  +        synchronized (roles) {
  +            return (roles.values().iterator());
  +        }
  +
  +    }
  +
  +
  +    /**
        * Return the set of {@link User}s defined in this user database.
        */
       public Iterator getUsers() {
  @@ -273,6 +293,23 @@
   
   
       /**
  +     * Create and return a new {@link Role} defined in this user database.
  +     *
  +     * @param rolename The role name of the new group (must be unique)
  +     * @param description The description of this group
  +     */
  +    public Role createRole(String rolename, String description) {
  +
  +        MemoryRole role = new MemoryRole(this, rolename, description);
  +        synchronized (roles) {
  +            roles.put(role.getRolename(), role);
  +        }
  +        return (role);
  +
  +    }
  +
  +
  +    /**
        * Create and return a new {@link User} defined in this user database.
        *
        * @param username The logon username of the new user (must be unique)
  @@ -307,6 +344,21 @@
   
   
       /**
  +     * Return the {@link Role} with the specified role name, if any;
  +     * otherwise return <code>null</code>.
  +     *
  +     * @param rolename Name of the role to return
  +     */
  +    public Role findRole(String rolename) {
  +
  +        synchronized (roles) {
  +            return ((Role) roles.get(rolename));
  +        }
  +
  +    }
  +
  +
  +    /**
        * Return the {@link User} with the specified user name, if any;
        * otherwise return <code>null</code>.
        *
  @@ -334,6 +386,7 @@
                   // Erase any previous groups and users
                   users.clear();
                   groups.clear();
  +                roles.clear();
   
                   // Construct a reader for the XML input file (if it exists)
                   File file = new File(pathname);
  @@ -352,6 +405,9 @@
                       ("tomcat-users/group",
                        new MemoryGroupCreationFactory(this));
                   digester.addFactoryCreate
  +                    ("tomcat-users/role",
  +                     new MemoryRoleCreationFactory(this));
  +                digester.addFactoryCreate
                       ("tomcat-users/user",
                        new MemoryUserCreationFactory(this));
   
  @@ -394,6 +450,30 @@
   
   
       /**
  +     * Remove the specified {@link Role} from this user database.
  +     *
  +     * @param role The role to be removed
  +     */
  +    public void removeRole(Role role) {
  +
  +        synchronized (roles) {
  +            Iterator groups = getGroups();
  +            while (groups.hasNext()) {
  +                Group group = (Group) groups.next();
  +                group.removeRole(role);
  +            }
  +            Iterator users = getUsers();
  +            while (users.hasNext()) {
  +                User user = (User) users.next();
  +                user.removeRole(role);
  +            }
  +            roles.remove(role.getRolename());
  +        }
  +
  +    }
  +
  +
  +    /**
        * Remove the specified {@link User} from this user database.
        *
        * @param user The user to be removed
  @@ -433,8 +513,14 @@
               writer.println("<?xml version='1.0'?>");
               writer.println("<tomcat-users>");
   
  -            // Print entries for each defined group and user
  -            Iterator values = getGroups();
  +            // Print entries for each defined role, group, and user
  +            Iterator values = null;
  +            values = getRoles();
  +            while (values.hasNext()) {
  +                writer.print("  ");
  +                writer.println(values.next());
  +            }
  +            values = getGroups();
               while (values.hasNext()) {
                   writer.print("  ");
                   writer.println(values.next());
  @@ -509,6 +595,8 @@
           sb.append(pathname);
           sb.append(",groupCount=");
           sb.append(this.groups.size());
  +        sb.append(",roleCount=");
  +        sb.append(this.roles.size());
           sb.append(",userCount=");
           sb.append(this.users.size());
           sb.append("]");
  @@ -553,16 +641,22 @@
           Group group = database.createGroup(groupname, description);
           if (roles != null) {
               while (roles.length() > 0) {
  -                String role = null;
  +                String rolename = null;
                   int comma = roles.indexOf(',');
                   if (comma >= 0) {
  -                    role = roles.substring(0, comma).trim();
  +                    rolename = roles.substring(0, comma).trim();
                       roles = roles.substring(comma + 1);
                   } else {
  -                    role = roles.trim();
  +                    rolename = roles.trim();
                       roles = "";
                   }
  -                group.addRole(role);
  +                if (rolename.length() > 0) {
  +                    Role role = database.findRole(rolename);
  +                    if (role == null) {
  +                        role = database.createRole(rolename, null);
  +                    }
  +                    group.addRole(role);
  +                }
               }
           }
           return (group);
  @@ -584,6 +678,40 @@
   
   
   /**
  + * Digester object creation factory for role instances.
  + */
  +class MemoryRoleCreationFactory implements ObjectCreationFactory {
  +
  +    public MemoryRoleCreationFactory(MemoryUserDatabase database) {
  +        this.database = database;
  +    }
  +
  +    public Object createObject(Attributes attributes) {
  +        String rolename = attributes.getValue("rolename");
  +        if (rolename == null) {
  +            rolename = attributes.getValue("name");
  +        }
  +        String description = attributes.getValue("description");
  +        Role role = database.createRole(rolename, description);
  +        return (role);
  +    }
  +
  +    private MemoryUserDatabase database = null;
  +
  +    private Digester digester = null;
  +
  +    public Digester getDigester() {
  +        return (this.digester);
  +    }
  +
  +    public void setDigester(Digester digester) {
  +        this.digester = digester;
  +    }
  +
  +}
  +
  +
  +/**
    * Digester object creation factory for user instances.
    */
   class MemoryUserCreationFactory implements ObjectCreationFactory {
  @@ -613,27 +741,33 @@
                       groupname = groups.trim();
                       groups = "";
                   }
  -                Group group = database.findGroup(groupname);
  -                if (group == null) {
  -                    throw new IllegalArgumentException
  -                        (database.getStringManager().getString
  -                         ("memoryUserDatabase.invalidGroup", groupname));
  +                if (groupname.length() > 0) {
  +                    Group group = database.findGroup(groupname);
  +                    if (group == null) {
  +                        group = database.createGroup(groupname, null);
  +                    }
  +                    user.addGroup(group);
                   }
  -                user.addGroup(group);
               }
           }
           if (roles != null) {
               while (roles.length() > 0) {
  -                String role = null;
  +                String rolename = null;
                   int comma = roles.indexOf(',');
                   if (comma >= 0) {
  -                    role = roles.substring(0, comma).trim();
  +                    rolename = roles.substring(0, comma).trim();
                       roles = roles.substring(comma + 1);
                   } else {
  -                    role = roles.trim();
  +                    rolename = roles.trim();
                       roles = "";
                   }
  -                user.addRole(role);
  +                if (rolename.length() > 0) {
  +                    Role role = database.findRole(rolename);
  +                    if (role == null) {
  +                        role = database.createRole(rolename, null);
  +                    }
  +                    user.addRole(role);
  +                }
               }
           }
           return (user);
  
  
  
  1.4       +4 -5      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabaseFactory.java
  
  Index: MemoryUserDatabaseFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabaseFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MemoryUserDatabaseFactory.java    22 Jan 2002 23:41:38 -0000      1.3
  +++ MemoryUserDatabaseFactory.java    3 Feb 2002 00:56:58 -0000       1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabaseFactory.java,v
 1.3 2002/01/22 23:41:38 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/01/22 23:41:38 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryUserDatabaseFactory.java,v
 1.4 2002/02/03 00:56:58 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/03 00:56:58 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -65,7 +65,6 @@
   
   
   import java.util.Hashtable;
  -import java.security.AccessControlException;
   import javax.naming.Name;
   import javax.naming.Context;
   import javax.naming.NamingException;
  @@ -91,7 +90,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2002/01/22 23:41:38 $
  + * @version $Revision: 1.4 $ $Date: 2002/02/03 00:56:58 $
    * @since 4.1
    */
   
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractRole.java
  
  Index: AbstractRole.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/AbstractRole.java,v
 1.1 2002/02/03 00:56:58 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/03 00:56:58 $
   *
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.catalina.users;
  
  
  import java.util.Iterator;
  import org.apache.catalina.Group;
  import org.apache.catalina.Role;
  import org.apache.catalina.User;
  import org.apache.catalina.UserDatabase;
  
  
  /**
   * <p>Convenience base class for {@link Role} implementations.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2002/02/03 00:56:58 $
   * @since 4.1
   */
  
  public abstract class AbstractRole implements Role {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The description of this Role.
       */
      protected String description = null;
  
  
      /**
       * The role name of this Role.
       */
      protected String rolename = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the description of this role.
       */
      public String getDescription() {
  
          return (this.description);
  
      }
  
  
      /**
       * Set the description of this role.
       *
       * @param description The new description
       */
      public void setDescription(String description) {
  
          this.description = description;
  
      }
  
  
      /**
       * Return the role name of this role, which must be unique
       * within the scope of a {@link UserDatabase}.
       */
      public String getRolename() {
  
          return (this.rolename);
  
      }
  
  
      /**
       * Set the role name of this role, which must be unique
       * within the scope of a {@link UserDatabase}.
       *
       * @param rolename The new role name
       */
      public void setRolename(String rolename) {
  
          this.rolename = rolename;
  
      }
  
  
      /**
       * Return the {@link UserDatabase} within which this Role is defined.
       */
      public abstract UserDatabase getUserDatabase();
  
  
      // --------------------------------------------------------- Public Methods
  
  
      // ------------------------------------------------------ Principal Methods
  
  
      /**
       * Make the principal name the same as the role name.
       */
      public String getName() {
  
          return (getRolename());
  
      }
  
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryRole.java
  
  Index: MemoryRole.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/users/MemoryRole.java,v
 1.1 2002/02/03 00:56:58 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/03 00:56:58 $
   *
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.catalina.users;
  
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import org.apache.catalina.Group;
  import org.apache.catalina.Role;
  import org.apache.catalina.User;
  import org.apache.catalina.UserDatabase;
  
  
  /**
   * <p>Concrete implementation of {@link Role} for the
   * {@link MemoryUserDatabase} implementation of {@link UserDatabase}.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2002/02/03 00:56:58 $
   * @since 4.1
   */
  
  public class MemoryRole extends AbstractRole {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Package-private constructor used by the factory method in
       * {@link MemoryUserDatabase}.
       *
       * @param database The {@link MemoryUserDatabase} that owns this role
       * @param rolename Role name of this role
       * @param description Description of this role
       */
      MemoryRole(MemoryUserDatabase database,
                 String rolename, String description) {
  
          super();
          this.database = database;
          setRolename(rolename);
          setDescription(description);
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The {@link MemoryUserDatabase} that owns this role.
       */
      protected MemoryUserDatabase database = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the {@link UserDatabase} within which this role is defined.
       */
      public UserDatabase getUserDatabase() {
  
          return (this.database);
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * <p>Return a String representation of this role in XML format.</p>
       */
      public String toString() {
  
          StringBuffer sb = new StringBuffer("<role rolename='");
          sb.append(rolename);
          sb.append("'");
          if (description != null) {
              sb.append(" description='");
              sb.append(description);
              sb.append("'");
          }
          sb.append("/>");
          return (sb.toString());
  
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to