[jboss-cvs] JBossAS SVN: r61722 - in trunk/server/src/main/org/jboss/metadata: web and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 26 20:35:48 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-03-26 20:35:48 -0400 (Mon, 26 Mar 2007)
New Revision: 61722

Modified:
   trunk/server/src/main/org/jboss/metadata/WebMetaData.java
   trunk/server/src/main/org/jboss/metadata/web/JBossWebMetaDataObjectFactory.java
   trunk/server/src/main/org/jboss/metadata/web/Servlet.java
   trunk/server/src/main/org/jboss/metadata/web/WebMetaDataObjectFactory.java
Log:
Cleanup the run-as metadata parsing

Modified: trunk/server/src/main/org/jboss/metadata/WebMetaData.java
===================================================================
--- trunk/server/src/main/org/jboss/metadata/WebMetaData.java	2007-03-26 23:09:22 UTC (rev 61721)
+++ trunk/server/src/main/org/jboss/metadata/WebMetaData.java	2007-03-27 00:35:48 UTC (rev 61722)
@@ -122,9 +122,9 @@
    /** web.xml security-role-refs <String servlet-name, ArrayList<SecurityRoleRefMetaData>> */
    private HashMap securityRoleReferences = new HashMap();
    /** The web.xml servlet/run-as <String servlet-name, String role> */
-   private HashMap runAsNames = new HashMap();
+   private HashMap<String, String> runAsNames = new HashMap<String, String>();
    /** The jboss-web.xml servlet/run-as <String servlet-name, RunAsIdentity> */
-   private HashMap runAsIdentity = new HashMap();
+   private HashMap<String, RunAsIdentity> runAsIdentity = new HashMap<String, RunAsIdentity>();
    /** The web.xml distributable flag */
    private boolean distributable = false;
    /** The jboss-web.xml class-loading.java2ClassLoadingCompliance flag */
@@ -320,19 +320,49 @@
    {
       String servletName = servlet.getName();
       servlets.put(servletName, servlet);
+      // Index the run-as value
+      RunAs runAs = servlet.getRunAs();
+      if( runAs != null )
+      {
+         this.runAsNames.put(servletName, runAs.getRoleName());
+      }
    }
 
    public void updateServlet(Servlet updatedServlet)
    {
-      Servlet servlet = (Servlet)servlets.get(updatedServlet.getName());
+      String servletName = updatedServlet.getName();
+      Servlet servlet = (Servlet)servlets.get(servletName);
       if (servlet != null)
       {
-         servlet.setRunAsPrincipals(updatedServlet.getRunAsPrincipals());
+         servlet.setRunAsPrincipal(updatedServlet.getRunAsPrincipal());
       }
       else
       {
-         servlets.put(updatedServlet.getName(), updatedServlet);
+         servlets.put(servletName, updatedServlet);
+         servlet = updatedServlet;
       }
+
+      // Update run-as indentity for a run-as-principal
+      String principalName = servlet.getRunAsPrincipal();
+      // Get the web.xml run-as primary role
+      String webXmlRunAs = runAsNames.get(servletName);
+      if (principalName != null)
+      {
+         // Update the run-as indentity to use the principal name
+         if (webXmlRunAs == null)
+         {
+            throw new IllegalStateException("run-as-principal: " + principalName + " found in jboss-web.xml but there was no run-as in web.xml");
+         }
+         // See if there are any additional roles for this principal
+         Set extraRoles = getSecurityRoleNamesByPrincipal(principalName);
+         RunAsIdentity runAsId = new RunAsIdentity(webXmlRunAs, principalName, extraRoles);
+         runAsIdentity.put(servletName, runAsId);
+      }
+      else if (webXmlRunAs != null)
+      {
+         RunAsIdentity runAsId = new RunAsIdentity(webXmlRunAs, null);
+         runAsIdentity.put(servletName, runAsId);
+      }
    }
 
    public Collection getServletMappings()

Modified: trunk/server/src/main/org/jboss/metadata/web/JBossWebMetaDataObjectFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/metadata/web/JBossWebMetaDataObjectFactory.java	2007-03-26 23:09:22 UTC (rev 61721)
+++ trunk/server/src/main/org/jboss/metadata/web/JBossWebMetaDataObjectFactory.java	2007-03-27 00:35:48 UTC (rev 61722)
@@ -285,7 +285,7 @@
       }
       else if (localName.equals("run-as-principal"))
       {
-         servlet.addRunAsPrincipal(value);
+         servlet.setRunAsPrincipal(value);
       }
    }
 
@@ -305,7 +305,7 @@
    {
       if (localName.equals("principal-name"))
       {
-         role.setRoleName(value);
+         role.addPrincipalName(value);
       }
       else super.setValue(role, navigator, namespaceURI, localName, value);
    }

Modified: trunk/server/src/main/org/jboss/metadata/web/Servlet.java
===================================================================
--- trunk/server/src/main/org/jboss/metadata/web/Servlet.java	2007-03-26 23:09:22 UTC (rev 61721)
+++ trunk/server/src/main/org/jboss/metadata/web/Servlet.java	2007-03-27 00:35:48 UTC (rev 61722)
@@ -33,7 +33,7 @@
    private RunAs runAs;
    private HashMap<String, SecurityRoleRefMetaData> securityRoleRefs =
       new HashMap<String, SecurityRoleRefMetaData>();
-   private Collection<String> runAsPrincipals = new ArrayList<String>();
+   private String runAsPrincipal;
 
    public String getName()
    {
@@ -115,21 +115,16 @@
       securityRoleRefs.put(ref.getName(), ref);
    }
    
-   public Collection getRunAsPrincipals()
+   public String getRunAsPrincipal()
    {
-      return runAsPrincipals;
+      return runAsPrincipal;
    }
    
-   public void setRunAsPrincipals(Collection runAsPrincipals)
+   public void setRunAsPrincipal(String runAsPrincipal)
    {
-      this.runAsPrincipals = runAsPrincipals;
+      this.runAsPrincipal = runAsPrincipal;
    }
    
-   public void addRunAsPrincipal(String principal)
-   {
-      runAsPrincipals.add(principal);
-   }
-   
    public String toString()
    {
       StringBuffer sb = new StringBuffer(100);
@@ -137,6 +132,8 @@
       sb.append("name=" + name);
       sb.append(", class=" + clazz);
       sb.append(", jspFile=" + jspFile);
+      sb.append(", runAs=" + runAs);
+      sb.append(", runAsPrincipal=" + runAsPrincipal);
       sb.append(']');
       return sb.toString();
    }

Modified: trunk/server/src/main/org/jboss/metadata/web/WebMetaDataObjectFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/metadata/web/WebMetaDataObjectFactory.java	2007-03-26 23:09:22 UTC (rev 61721)
+++ trunk/server/src/main/org/jboss/metadata/web/WebMetaDataObjectFactory.java	2007-03-27 00:35:48 UTC (rev 61722)
@@ -716,7 +716,7 @@
       }
       else if (localName.equals("run-as-principal"))
       {
-         servlet.addRunAsPrincipal(value);
+         servlet.setRunAsPrincipal(value);
       }
       else if (localName.equals("jsp-file"))
       {




More information about the jboss-cvs-commits mailing list