tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/webapps/manager/WEB-INF web.xml
Date Mon, 08 Apr 2002 17:46:08 GMT
craigmcc    02/04/08 10:46:08

  Modified:    catalina/src/share/org/apache/catalina/servlets
                        LocalStrings.properties ManagerServlet.java
               webapps/manager manager.xml
               webapps/manager/WEB-INF web.xml
  Log:
  Implement a lookup mechanism to enumerate the security roles (and corresponding
  descriptions) defined in the user database.  This will be useful, for example,
  in deployment tools that wish to create <security-role-ref> elements in the
  web.xml file that link role names used in the web application to those that are
  actually defined in the container.
  
  Revision  Changes    Path
  1.15      +3 -0      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/LocalStrings.properties
  
  Index: LocalStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/LocalStrings.properties,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- LocalStrings.properties	12 Mar 2002 21:14:15 -0000	1.14
  +++ LocalStrings.properties	8 Apr 2002 17:46:08 -0000	1.15
  @@ -34,6 +34,7 @@
   managerServlet.removed=OK - Removed application at context path {0}
   managerServlet.resourcesAll=OK - Listed global resources of all types
   managerServlet.resourcesType=OK - Listed global resources of type {0}
  +managerServlet.rolesList=OK - Listed security roles
   managerServlet.sessiondefaultmax=Default maximum session inactive interval {0} minutes
   managerServlet.sessiontimeout={0} minutes:{1} sessions
   managerServlet.sessions=OK - Session information for application at context path {0}
  @@ -42,6 +43,8 @@
   managerServlet.stopped=OK - Stopped application at context path {0}
   managerServlet.undeployed=OK - Undeployed application at context path {0}
   managerServlet.unknownCommand=FAIL - Unknown command {0}
  +managerServlet.userDatabaseError=FAIL - Cannot resolve user database reference
  +managerServlet.userDatabaseMissing=FAIL - No user database is available
   webdavservlet.jaxpfailed=JAXP initialization failed
   directory.filename=Filename
   directory.lastModified=Last Modified
  
  
  
  1.19      +63 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java
  
  Index: ManagerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ManagerServlet.java	13 Mar 2002 01:26:49 -0000	1.18
  +++ ManagerServlet.java	8 Apr 2002 17:46:08 -0000	1.19
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
1.18 2002/03/13 01:26:49 craigmcc Exp $
  - * $Revision: 1.18 $
  - * $Date: 2002/03/13 01:26:49 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java,v
1.19 2002/04/08 17:46:08 craigmcc Exp $
  + * $Revision: 1.19 $
  + * $Date: 2002/04/08 17:46:08 $
    *
    * ====================================================================
    *
  @@ -73,8 +73,11 @@
   import java.io.PrintWriter;
   import java.net.URL;
   import java.util.Enumeration;
  +import java.util.Iterator;
  +import javax.naming.InitialContext;
   import javax.naming.NameClassPair;
   import javax.naming.NamingEnumeration;
  +import javax.naming.NamingException;
   import javax.naming.directory.DirContext;
   import javax.servlet.ServletException;
   import javax.servlet.ServletInputStream;
  @@ -88,9 +91,11 @@
   import org.apache.catalina.Deployer;
   import org.apache.catalina.Globals;
   import org.apache.catalina.Host;
  +import org.apache.catalina.Role;
   import org.apache.catalina.Server;
   import org.apache.catalina.ServerFactory;
   import org.apache.catalina.Session;
  +import org.apache.catalina.UserDatabase;
   import org.apache.catalina.Wrapper;
   import org.apache.catalina.core.StandardServer;
   import org.apache.catalina.util.StringManager;
  @@ -137,6 +142,9 @@
    * <li><b>/resources?type=xxxx</b> - Enumerate the available global JNDI
    *     resources, optionally limited to those of the specified type
    *     (fully qualified Java class name), if available.</li>
  + * <li><b>/roles</b> - Enumerate the available security role names and
  + *     descriptions from the user database connected to the <code>users</code>
  + *     resource reference.
    * <li><b>/sessions?path=/xxx</b> - List session information about the
web
    *     application attached to context path <code>/xxx</code> for this
    *     virtual host.</li>
  @@ -188,7 +196,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.18 $ $Date: 2002/03/13 01:26:49 $
  + * @version $Revision: 1.19 $ $Date: 2002/04/08 17:46:08 $
    */
   
   public class ManagerServlet
  @@ -327,6 +335,8 @@
               remove(writer, path);
           } else if (command.equals("/resources")) {
               resources(writer, type);
  +        } else if (command.equals("/roles")) {
  +            roles(writer);
           } else if (command.equals("/sessions")) {
               sessions(writer, path);
           } else if (command.equals("/start")) {
  @@ -782,6 +792,55 @@
               writer.println(sm.getString("managerServlet.exception",
                                           t.toString()));
           }
  +
  +    }
  +
  +
  +    /**
  +     * Render a list of security role names (and corresponding descriptions)
  +     * from the <code>org.apache.catalina.UserDatabase</code> resource that
is
  +     * connected to the <code>users</code> resource reference.  Typically,
this
  +     * will be the global user database, but can be adjusted if you have
  +     * different user databases for different virtual hosts.
  +     *
  +     * @param writer Writer to render to
  +     */
  +    protected void roles(PrintWriter writer) {
  +
  +        if (debug >= 1) {
  +            log("roles:  List security roles from user database");
  +        }
  +
  +        // Look up the UserDatabase instance we should use
  +        UserDatabase database = null;
  +        try {
  +            InitialContext ic = new InitialContext();
  +            database = (UserDatabase) ic.lookup("java:comp/env/users");
  +        } catch (NamingException e) {
  +            writer.println(sm.getString("managerServlet.userDatabaseError"));
  +            log("java:comp/env/users", e);
  +            return;
  +        }
  +        if (database == null) {
  +            writer.println(sm.getString("managerServlet.userDatabaseMissing"));
  +            return;
  +        }
  +
  +        // Enumerate the available roles
  +        writer.println(sm.getString("managerServlet.rolesList"));
  +        Iterator roles = database.getRoles();
  +        if (roles != null) {
  +            while (roles.hasNext()) {
  +                Role role = (Role) roles.next();
  +                writer.print(role.getRolename());
  +                writer.print(':');
  +                if (role.getDescription() != null) {
  +                    writer.print(role.getDescription());
  +                }
  +                writer.println();
  +            }
  +        }
  +
   
       }
   
  
  
  
  1.2       +6 -1      jakarta-tomcat-4.0/webapps/manager/manager.xml
  
  Index: manager.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/manager/manager.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- manager.xml	27 Oct 2001 22:17:14 -0000	1.1
  +++ manager.xml	8 Apr 2002 17:46:08 -0000	1.2
  @@ -2,11 +2,16 @@
   
       Context configuration file for the Tomcat Manager Web App
   
  -    $Id: manager.xml,v 1.1 2001/10/27 22:17:14 craigmcc Exp $
  +    $Id: manager.xml,v 1.2 2002/04/08 17:46:08 craigmcc Exp $
   
   -->
   
   
   <Context path="/manager" docBase="../server/webapps/manager"
           debug="0" privileged="true">
  +
  +  <!-- Link to the user database we will get roles from -->
  +  <ResourceLink name="users" global="UserDatabase"
  +                type="org.apache.catalina.UserDatabase"/>
  +
   </Context>
  
  
  
  1.5       +14 -0     jakarta-tomcat-4.0/webapps/manager/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/manager/WEB-INF/web.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- web.xml	4 Apr 2002 20:30:34 -0000	1.4
  +++ web.xml	8 Apr 2002 17:46:08 -0000	1.5
  @@ -27,6 +27,20 @@
       <url-pattern>/*</url-pattern>
     </servlet-mapping>
   
  +  <!-- Define reference to the user database for looking up roles -->
  +  <resource-env-ref>
  +    <description>
  +      Link to the UserDatabase instance from which we request lists of
  +      defined role names.  Typically, this will be connected to the global
  +      user database with a ResourceLink element in server.xml or the context
  +      configuration file for the Manager web application.
  +    </description>
  +    <resource-env-ref-name>users</resource-env-ref-name>
  +    <resource-env-ref-type>
  +      org.apache.catalina.UserDatabase
  +    </resource-env-ref-type>
  +  </resource-env-ref>
  +
     <!-- Define a Security Constraint on this Application -->
     <security-constraint>
       <web-resource-collection>
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message