[jboss-cvs] JBossAS SVN: r79566 - in projects/security/security-jboss-sx/trunk/jbosssx/src: main/org/jboss/security/config and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 15 21:57:28 EDT 2008


Author: sguilhen at redhat.com
Date: 2008-10-15 21:57:27 -0400 (Wed, 15 Oct 2008)
New Revision: 79566

Added:
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigContainer.java
Removed:
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/RoleMappingConfigContainer.java
Modified:
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/authorization/config/SecurityConfigObjectModelFactory.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicy.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicyContainer.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigEntryHolder.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingModuleEntry.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/resources/schema/security-config_5_0.xsd
   projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/security/config/SecurityConfigurationUnitTestCase.java
   projects/security/security-jboss-sx/trunk/jbosssx/src/tests/resources/config/securityConfig5.xml
Log:
SECURITY-288: added a mapping element to security-config_5_0.xsd. An optional "type" attribute has also been added to the mapping-module element. All modules that don't specify their type are automatically included in a MappingInfo of type "role".
- ApplicationPolicy has now a getMappingInfo(String type) method that retrieves the MappingInfo that must be used to map objects of the specified type. The returned info contains the modules that have been configured with the same type. Also get/setRoleMappingInfo and get/setPrincipalMappingInfo methods have been marked as deprecated.
- Parsers and test classes have been updated accordingly.



Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/authorization/config/SecurityConfigObjectModelFactory.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/authorization/config/SecurityConfigObjectModelFactory.java	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/authorization/config/SecurityConfigObjectModelFactory.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -21,7 +21,9 @@
  */
 package org.jboss.security.authorization.config;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.jboss.logging.Logger;
@@ -87,6 +89,10 @@
       {
          child = new ACLInfo(aPolicy.getName());
       }
+      else if (child == null && "mapping".equals(localName))
+      {
+         child = new MappingInfo(aPolicy.getName());
+      }
       else if (child == null && "rolemapping".equals(localName))
       {
          child = new MappingInfo(aPolicy.getName());
@@ -263,21 +269,27 @@
          log.trace("Adding module-option " + option.getName() + " to ACLProviderEntry " + aclEntry.getAclProviderName());
    }
 
-   // RoleMapping
+   // Mapping
    public Object newChild(MappingInfo info, UnmarshallingContext navigator, String namespaceUri, String localName,
          Attributes attrs)
    {
       Object child = null;
       if (trace)
-         log.trace("newChild.RoleMappingInfo, localName: " + localName);
+         log.trace("newChild.MappingInfo, localName: " + localName);
       if ("mapping-module".equals(localName))
       {
          String code = attrs.getValue("code");
          code = StringPropertyReplacer.replaceProperties(code.trim());
-         MappingModuleEntry entry = new MappingModuleEntry(code);
-         child = entry;
+         String type = attrs.getValue("type");
+         if(type != null)
+            type = StringPropertyReplacer.replaceProperties(type.trim());
+         else
+            type = "role";
+
+         child = new MappingModuleEntry(code, new HashMap<String,Object>(), type);
          if (trace)
-            log.trace("newChild.RoleMappingInfo, mapping-module code: " + code);
+            log.trace("newChild.MappingInfo, mapping-module code: " + code + 
+                  ", mapping-module type: " + type);
       }
 
       return child;
@@ -303,7 +315,27 @@
    public void addChild(ApplicationPolicy aPolicy, MappingInfo authInfo, UnmarshallingContext navigator,
          String namespaceURI, String localName)
    {
-      aPolicy.setRoleMappingInfo(authInfo);
+      // first organize the mapping modules by type.
+      Map<String,List<MappingModuleEntry>> mappings = new HashMap<String,List<MappingModuleEntry>>();
+      for(MappingModuleEntry entry : authInfo.getModuleEntries())
+      {
+         String type = entry.getMappingModuleType();
+         if(mappings.containsKey(type))
+            mappings.get(type).add(entry);
+         else
+         {
+            List<MappingModuleEntry> entries = new ArrayList<MappingModuleEntry>();
+            entries.add(entry);
+            mappings.put(type, entries);
+         }
+      }
+      // now set all mapping infos by type.
+      for(Map.Entry<String,List<MappingModuleEntry>> entry : mappings.entrySet())
+      {
+         MappingInfo info = new MappingInfo(authInfo.getName());
+         info.add(entry.getValue());
+         aPolicy.setMappingInfo(entry.getKey(), info);
+      }
       if (trace)
          log.trace("addChild.ApplicationPolicy, name: " + aPolicy.getName());
    }

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicy.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicy.java	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicy.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -22,6 +22,8 @@
 package org.jboss.security.config;
 
 import java.security.Principal;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.jboss.security.auth.login.BaseAuthenticationInfo;
 import org.jboss.security.identity.RoleGroup;
@@ -47,10 +49,8 @@
 
    private AuditInfo auditInfo;
 
-   private MappingInfo roleMappingInfo;
+   private final Map<String, MappingInfo> mappingInfos = new HashMap<String, MappingInfo>();
 
-   private MappingInfo principalMappingInfo;
-
    private IdentityTrustInfo identityTrustInfo;
 
    // Base application policy (if any)
@@ -142,6 +142,15 @@
       this.authorizationInfo = authorizationInfo;
    }
 
+   /**
+    * <p>
+    * Gets the {@code MappingInfo} object that contains the entries that will be used to map roles.
+    * </p>
+    * 
+    * @return the {@code MappingInfo} that must be used when mapping roles.
+    * @deprecated use {@link ApplicationPolicy#getMappingInfo("role")} instead.
+    */
+   @Deprecated
    public MappingInfo getRoleMappingInfo()
    {
       MappingInfo bai = null;
@@ -149,19 +158,38 @@
       if (ap != null)
          bai = ap.getRoleMappingInfo();
 
-      if (bai != null && roleMappingInfo == null)
+      MappingInfo roleMappings = this.mappingInfos.get("role");
+      if (bai != null && roleMappings == null)
          return bai;
       else if (bai != null)
-         return (MappingInfo) roleMappingInfo.merge(bai);
+         return (MappingInfo) roleMappings.merge(bai);
       else
-         return roleMappingInfo;
+         return roleMappings;
    }
 
+   /**
+    * <p>
+    * Sets the {@code MappingInfo} object that must be used when mapping roles.
+    * </p>
+    * 
+    * @param roleMappingInfo the {@code MappingInfo} instance to be set.
+    * @deprecated use {@link ApplicationPolicy#setMappingInfo("role", MappingInfo)} instead.
+    */
+   @Deprecated
    public void setRoleMappingInfo(MappingInfo roleMappingInfo)
    {
-      this.roleMappingInfo = roleMappingInfo;
+      this.mappingInfos.put("role", roleMappingInfo);
    }
 
+   /**
+    * <p>
+    * Gets the {@code MappingInfo} object that contains the entries that will be used to map principals.
+    * </p>
+    * 
+    * @return the {@code MappingInfo} that must be used when mapping principals.
+    * @deprecated use {@link ApplicationPolicy#getMappingInfo("principal")} instead.
+    */
+   @Deprecated
    public MappingInfo getPrincipalMappingInfo()
    {
       MappingInfo bai = null;
@@ -169,20 +197,40 @@
       if (ap != null)
          bai = ap.getPrincipalMappingInfo();
 
-      if (bai != null && principalMappingInfo == null)
+      MappingInfo principalMappings = this.mappingInfos.get("principal");
+      if (bai != null && principalMappings == null)
          return bai;
       else if (bai != null)
-         return (MappingInfo) principalMappingInfo.merge(bai);
+         return (MappingInfo) principalMappings.merge(bai);
       else
-         return principalMappingInfo;
+         return principalMappings;
 
    }
 
+   /**
+    * <p>
+    * Sets the {@code MappingInfo} object that must be used when mapping principals.
+    * </p>
+    * 
+    * @param roleMappingInfo the {@code MappingInfo} instance to be set.
+    * @deprecated use {@link ApplicationPolicy#setMappingInfo("principal", MappingInfo)} instead.
+    */
+   @Deprecated
    public void setPrincipalMappingInfo(MappingInfo principalMappingInfo)
    {
-      this.principalMappingInfo = principalMappingInfo;
+      this.mappingInfos.put("principal", principalMappingInfo);
    }
 
+   /**
+    * <p>
+    * Gets the {@code MappingInfo} instance that can map objects of the specified class. 
+    * </p>
+    * 
+    * @param t the class of the objects that are to be mapped.
+    * @return the {@code MappingInfo} instance that must be used to map objects of the specified class.
+    * @deprecated use {@link ApplicationPolicy#getMappingInfo(String)} instead.
+    */
+   @Deprecated
    public <T> MappingInfo getMappingInfo(Class<T> t)
    {
       if (t == RoleGroup.class)
@@ -192,6 +240,66 @@
       throw new IllegalStateException("No mapping information available for type:" + t);
    }
 
+   /**
+    * <p>
+    * Gets the {@code MappingInfo} instance that can perform the mappings of the specified type.
+    * </p>
+    * 
+    * @param mappingType a {@code String} representing the type of the mappings that are to be performed. This
+    *            {@code String} must match the value of the {@code type} attribute of the {@code mapping-module} that
+    *            has been configured in the application policy. For example, consider the following mapping policy:
+    * 
+    * <pre>
+    * &lt;application-policy name=&quot;test&quot;&gt;
+    *    &lt;authentication&gt;
+    *    ...
+    *    &lt;/authentication&gt;
+    *    &lt;mapping&gt;
+    *       &lt;mapping-module code = &quot;org.jboss.test.mapping.MappingModule1&quot; type=&quot;role&quot;&gt;
+    *          &lt;module-option name = &quot;option1&quot;&gt;value1&lt;/module-option&gt;
+    *       &lt;/mapping-module&gt;
+    *       &lt;mapping-module code = &quot;org.jboss.test.mapping.MappingModule2&quot; type=&quot;principal&quot;&gt;
+    *          &lt;module-option name = &quot;option2&quot;&gt;value2&lt;/module-option&gt;
+    *       &lt;/mapping-module&gt;
+    *    &lt;/mapping&gt; while a
+    * &lt;/application-policy&gt;
+    * </pre>
+    * 
+    * Executing this method with {@code "role"} as parameter would return a {@code MappingInfo} that is capable of
+    * mapping roles using the {@code MappingModule1}. Likewise, executing this method with {@code "principal"} as
+    * parameter would return a {@code MappingInfo} that can map principals using the {@code MappingModule2}.
+    * @return the {@code MappingInfo} instance that can perform the mappings of the specified type, or {@code null} if
+    *         no suitable {@code MappingInfo} can be found.
+    */
+   public MappingInfo getMappingInfo(String mappingType)
+   {
+      MappingInfo bai = null;
+      ApplicationPolicy ap = this.getBaseApplicationPolicy();
+      if (ap != null)
+         bai = ap.getMappingInfo(mappingType);
+
+      MappingInfo mappings = this.mappingInfos.get(mappingType);
+      if (bai != null && mappings == null)
+         return bai;
+      else if (bai != null)
+         return (MappingInfo) mappings.merge(bai);
+      else
+         return mappings;
+   }
+
+   /**
+    * <p>
+    * Sets the {@code MappingInfo} that must be used to perform the mappings of the specified type.
+    * </p>
+    * 
+    * @param mappingType the type of mappings that can be performed by the {@code MappingInfo}.
+    * @param info a reference to the {@code MappingInfo} instance to be set.
+    */
+   public void setMappingInfo(String mappingType, MappingInfo info)
+   {
+      this.mappingInfos.put(mappingType, info);
+   }
+
    public AuditInfo getAuditInfo()
    {
       AuditInfo bai = null;

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicyContainer.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicyContainer.java	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicyContainer.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -30,7 +30,6 @@
 import javax.xml.namespace.QName;
 
 import org.jboss.logging.Logger;
-import org.jboss.security.acl.config.ACLProviderEntry;
 import org.jboss.security.audit.config.AuditProviderEntry;
 import org.jboss.security.auth.container.config.AuthModuleEntry;
 import org.jboss.security.auth.login.AppConfigurationEntryHolder;
@@ -85,7 +84,7 @@
    boolean containsRoleMapping = false;
 
    // Mapping Info Object
-   RoleMappingInfo roleMappingInfo = null;
+   Map<String,MappingInfo> mappingInfos = new HashMap<String,MappingInfo>();
 
    ACLInfo aclInfo = null;
 
@@ -158,13 +157,6 @@
             auditProviderEntries.add(ameEntry);
          containsAudit = true;
       }
-      else if (value instanceof ACLProviderEntry)
-      {
-         AuditProviderEntry ameEntry = (AuditProviderEntry) value;
-         if (!auditProviderEntries.contains(ameEntry))
-            auditProviderEntries.add(ameEntry);
-         containsAudit = true;
-      }
       else if (value instanceof IdentityTrustModuleEntry)
       {
          IdentityTrustModuleEntry ameEntry = (IdentityTrustModuleEntry) value;
@@ -179,13 +171,15 @@
     * 
     * @param obj
     */
+   @SuppressWarnings("unchecked")
    public void addMappingInfo(Object obj)
    {
       log.debug(obj);
-      if (obj instanceof RoleMappingInfo)
+      if (obj instanceof Map)
       {
-         this.roleMappingInfo = (RoleMappingInfo) obj;
-         roleMappingInfo.setName(authName);
+         this.mappingInfos.putAll((Map) obj);
+         for(MappingInfo info: this.mappingInfos.values())
+            info.setName(authName);
          this.containsRoleMapping = true;
       }
    }
@@ -245,7 +239,8 @@
       }
       if (containsRoleMapping)
       {
-         info.setRoleMappingInfo(roleMappingInfo);
+         for(String type : this.mappingInfos.keySet())
+            info.setMappingInfo(type, this.mappingInfos.get(type));
       }
       if (containsAudit)
       {

Copied: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigContainer.java (from rev 79426, projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/RoleMappingConfigContainer.java)
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigContainer.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigContainer.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.security.mapping.config;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.logging.Logger;
+import org.jboss.security.config.MappingInfo;
+import org.jboss.xb.binding.GenericValueContainer;
+
+// $Id: RoleMappingConfigContainer.java 45942 2006-06-28 02:14:46Z asaldhana $
+
+/**
+ * A container for creating RoleMappingConfig during jbxb parse.
+ * 
+ * @author Anil.Saldhana at jboss.org
+ * @version $Revision: 45942 $
+ */
+public class MappingConfigContainer implements GenericValueContainer
+{
+   private static Logger MappingConfigContainer = Logger.getLogger(MappingConfigContainer.class);
+
+   private final Map<String, List<MappingModuleEntry>> moduleEntries = new HashMap<String, List<MappingModuleEntry>>();
+
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.jboss.xb.binding.GenericValueContainer#addChild(javax.xml.namespace.QName, java.lang.Object)
+    */
+   public void addChild(QName name, Object value)
+   {
+      if (MappingConfigContainer.isTraceEnabled())
+         MappingConfigContainer.trace("addChild:Qname=" + name + ":value=" + value);
+      if (value instanceof MappingModuleEntry)
+      {
+         MappingModuleEntry mme = (MappingModuleEntry) value;
+         String type = mme.getMappingModuleType();
+         // organize the mapping modules in groups according to their type.
+         if (this.moduleEntries.containsKey(type))
+         {
+            this.moduleEntries.get(type).add(mme);
+         }
+         else
+         {
+            List<MappingModuleEntry> entries = new ArrayList<MappingModuleEntry>();
+            entries.add(mme);
+            this.moduleEntries.put(type, entries);
+         }
+      }
+   }
+
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.jboss.xb.binding.GenericValueContainer#instantiate()
+    */
+   public Object instantiate()
+   {
+      Map<String, MappingInfo> infos = new HashMap<String, MappingInfo>();
+
+      // create a MappingInfo instance of each group of mapping modules.
+      for (String type : this.moduleEntries.keySet())
+      {
+         // application policy name will be reset in ApplicationPolicyContainer.
+         MappingInfo mapping = new MappingInfo("dummy");
+         mapping.add(this.moduleEntries.get(type));
+         infos.put(type, mapping);
+      }
+      return infos;
+   }
+
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.jboss.xb.binding.GenericValueContainer#getTargetClass()
+    */
+   public Class<?> getTargetClass()
+   {
+      return MappingInfo.class;
+   }
+}

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigEntryHolder.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigEntryHolder.java	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingConfigEntryHolder.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -39,8 +39,9 @@
  */
 public class MappingConfigEntryHolder implements GenericValueContainer
 {
-   private Map<String,Object> moduleOptions = new HashMap<String,Object>();
+   private final Map<String,Object> moduleOptions = new HashMap<String,Object>();
    String moduleName = null;  
+   String type = "role";
    
    public void addChild(QName name, Object value)
    {
@@ -48,6 +49,10 @@
       {
          moduleName = (String)value; 
       } 
+      else if("type".equals(name.getLocalPart()))
+      {
+         this.type = (String) value;
+      }
       if(value instanceof ModuleOption)
       {
          ModuleOption mo = (ModuleOption)value;
@@ -67,7 +72,7 @@
    
    public Object instantiate()
    { 
-      MappingModuleEntry entry = new MappingModuleEntry( moduleName,moduleOptions ); 
+      MappingModuleEntry entry = new MappingModuleEntry(this.moduleName, this.moduleOptions, this.type); 
       return entry;
    }
    

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingModuleEntry.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingModuleEntry.java	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/MappingModuleEntry.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -1,24 +1,24 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.security.mapping.config;
 
 import java.util.HashMap;
@@ -26,48 +26,69 @@
 
 import org.jboss.security.config.ModuleOption;
 
-//$Id: MappingModuleEntry.java 45985 2006-06-29 20:56:57Z asaldhana $
+// $Id: MappingModuleEntry.java 45985 2006-06-29 20:56:57Z asaldhana $
 
 /**
- *  Represents configuration for a single Mapping Module
- *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
- *  @since  August 24, 2006 
- *  @version $Revision: 45985 $
+ * Represents configuration for a single Mapping Module
+ * 
+ * @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ * @since August 24, 2006
+ * @version $Revision: 45985 $
  */
 public class MappingModuleEntry
 {
-   private String mappingModuleName; 
-   private Map<String,Object> options = new HashMap<String,Object>();
-   
-   /** 
+   private final String mappingModuleName;
+
+   private final String mappingModuleType;
+
+   private final Map<String, Object> options;
+
+   /**
     * Create a new MappingModuleEntry.
     * 
-    * @param name Policy Module Name 
+    * @param name Policy Module Name
     */
    public MappingModuleEntry(String name)
    {
-      this.mappingModuleName = name; 
+      this(name, new HashMap<String, Object>());
    }
-   
-   /** 
+
+   /**
     * Create a new MappingModuleEntry.
     * 
     * @param name Policy Module Name
     * @param options Options
     */
-   public MappingModuleEntry(String name, Map<String,Object> options)
+   public MappingModuleEntry(String name, Map<String, Object> options)
    {
+      this(name, options, "role");
+   }
+
+   /**
+    * <p>
+    * Creates a new {@code MappingModuleEntry} with the specified module name, module type and module options.
+    * </p>
+    * 
+    * @param name a {@code String} representing the fully-qualified class name of the mapping module.
+    * @param options a {@code Map<String,Object>} containing the options configured for the mapping module.
+    * @param type a {@code String} representing the type of mapping performed by the mapping module (e.g. role,
+    *            identity, principal).
+    */
+   public MappingModuleEntry(String name, Map<String, Object> options, String type)
+   {
       this.mappingModuleName = name;
+      this.mappingModuleType = type;
       this.options = options;
    }
-   
+
    public void add(ModuleOption option)
-   { 
+   {
       options.put(option.getName(), option.getValue());
    }
 
    /**
     * Get the Policy Module Name
+    * 
     * @return
     */
    public String getMappingModuleName()
@@ -76,21 +97,35 @@
    }
 
    /**
+    * <p>
+    * Gets the type of mapping performed by the mapping module.
+    * </p>
+    * 
+    * @return a {@code String} representing the type of mapping performed.
+    */
+   public String getMappingModuleType()
+   {
+      return this.mappingModuleType;
+   }
+
+   /**
     * Get the options
+    * 
     * @return
     */
-   public Map<String,Object> getOptions()
+   public Map<String, Object> getOptions()
    {
       return options;
    }
-   
+
    @Override
    public String toString()
    {
       StringBuilder builder = new StringBuilder();
       builder.append(getClass().getName()).append("{");
-      builder.append(this.mappingModuleName).append(":").append(this.options);
-      builder.append("}"); 
+      builder.append(this.mappingModuleName).append("-").append(this.mappingModuleType);
+      builder.append(":").append(this.options);
+      builder.append("}");
       return builder.toString();
-   } 
+   }
 }
\ No newline at end of file

Deleted: projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/RoleMappingConfigContainer.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/RoleMappingConfigContainer.java	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/mapping/config/RoleMappingConfigContainer.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -1,84 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.security.mapping.config;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.namespace.QName;
-
-import org.jboss.logging.Logger;
-import org.jboss.security.config.MappingInfo;
-import org.jboss.security.config.RoleMappingInfo;
-import org.jboss.xb.binding.GenericValueContainer;
-
-//$Id: RoleMappingConfigContainer.java 45942 2006-06-28 02:14:46Z asaldhana $
-
-/**
- * A container for creating RoleMappingConfig during jbxb parse.
- *  
- * @author Anil.Saldhana at jboss.org 
- * @version $Revision: 45942 $
- */
-public class RoleMappingConfigContainer
-   implements GenericValueContainer
-{
-   private static Logger log = Logger.getLogger(RoleMappingConfigContainer.class); 
- 
-   private List<MappingModuleEntry> moduleEntries = new ArrayList<MappingModuleEntry>();
-   
-   /**
-    * @see GenericValueContainer#addChild(javax.xml.namespace.QName, java.lang.Object)
-    */
-   public void addChild(QName name, Object value)
-   {
-      if(log.isTraceEnabled())
-         log.trace("addChild:Qname="+name+":value="+value);
-      if(value instanceof MappingModuleEntry)
-      {
-         MappingModuleEntry mme = (MappingModuleEntry) value;
-         this.moduleEntries.add(mme);
-      }   
-   }  
-
-   /**
-    * @see GenericValueContainer#instantiate()
-    */
-   public Object instantiate()
-   { 
-      /**
-       * Currently we do not have the name of the application policy
-       * This will be rectified in the ApplicationPolicyContainer
-       */
-      MappingInfo ri = new RoleMappingInfo("dummy");
-      ri.add(moduleEntries);
-      return ri;
-   }
-
-   /**
-    * @see GenericValueContainer#getTargetClass()
-    */
-   public Class<?> getTargetClass()
-   {
-      return RoleMappingInfo.class;
-   } 
-}

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/resources/schema/security-config_5_0.xsd
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/resources/schema/security-config_5_0.xsd	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/resources/schema/security-config_5_0.xsd	2008-10-16 01:57:27 UTC (rev 79566)
@@ -40,8 +40,10 @@
                <xsd:element ref="jbsx:authentication-jaspi"/>
             </xsd:choice>
             <xsd:element ref="jbsx:authorization" minOccurs="0"/>
-            <xsd:element ref="acl" minOccurs="0"/>
+            <xsd:element ref="jbsx:acl" minOccurs="0"/>
+            <!-- rolemapping is here for backwards compatibility -->
             <xsd:element ref="jbsx:rolemapping" minOccurs="0"/>
+            <xsd:element ref="jbsx:mapping" minOccurs="0"/>
             <xsd:element ref="jbsx:audit" minOccurs="0"/>
             <xsd:element ref="jbsx:identity-trust" minOccurs="0"/>
          </xsd:sequence>
@@ -52,8 +54,9 @@
    <xsd:element name="authentication" type="jbsx:authenticationInfo"/>
    <xsd:element name="authentication-jaspi" type="jbsx:authenticationJaspiInfo"/>
    <xsd:element name="authorization" type="jbsx:authorizationInfo"/>
-   <xsd:element name="acl" type="aclInfo"/>
-   <xsd:element name="rolemapping" type="jbsx:roleMappingInfo"/>
+   <xsd:element name="acl" type="jbsx:aclInfo"/>
+   <xsd:element name="rolemapping" type="jbsx:mappingInfo"/>
+   <xsd:element name="mapping" type="jbsx:mappingInfo"/>
    <xsd:element name="audit" type="jbsx:auditInfo"/>
    <xsd:element name="identity-trust" type="jbsx:identityTrustInfo"/>
    <xsd:complexType name="authenticationInfo">
@@ -95,13 +98,13 @@
          </xsd:appinfo>
       </xsd:annotation>
       <xsd:sequence>
-         <xsd:element ref="acl-module"  maxOccurs="unbounded"/>
+         <xsd:element ref="jbsx:acl-module"  maxOccurs="unbounded"/>
       </xsd:sequence>
    </xsd:complexType>
-   <xsd:complexType name="roleMappingInfo">
+   <xsd:complexType name="mappingInfo">
       <xsd:annotation>
          <xsd:appinfo>
-            <jbxb:class impl="org.jboss.security.mapping.config.RoleMappingConfigContainer"/>
+            <jbxb:class impl="org.jboss.security.mapping.config.MappingConfigContainer"/>
             <jbxb:addMethod name="addMappingInfo"/>
          </xsd:appinfo>
       </xsd:annotation>
@@ -250,7 +253,7 @@
             </xsd:appinfo>
          </xsd:annotation>
          <xsd:sequence>
-            <xsd:element ref="module-option" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element ref="jbsx:module-option" minOccurs="0" maxOccurs="unbounded"/>
          </xsd:sequence>
          <xsd:attribute name="code" type="xsd:string" use="required"/>
          <xsd:attribute name="flag" type="module-option-flag" use="required"/>
@@ -266,6 +269,7 @@
          <xsd:sequence>
             <xsd:element ref="jbsx:module-option" minOccurs="0" maxOccurs="unbounded"/>
          </xsd:sequence>
+         <xsd:attribute name="type" type="xsd:string" use="optional"/>
          <xsd:attribute name="code" type="xsd:string" use="required"/>
       </xsd:complexType>
    </xsd:element>

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/security/config/SecurityConfigurationUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/security/config/SecurityConfigurationUnitTestCase.java	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/security/config/SecurityConfigurationUnitTestCase.java	2008-10-16 01:57:27 UTC (rev 79566)
@@ -232,8 +232,20 @@
       Assert.assertTrue("Option aclOption4 was not found", options.containsKey("aclOption4"));
       Assert.assertEquals("value4", options.get("aclOption4"));
 
+      // Mapping
+      MappingInfo mappingInfo = completeConfig.getMappingInfo("principal");
+      assertNotNull("MappingInfo is not null", mappingInfo);
+      MappingModuleEntry[] mappingEntries = mappingInfo.getMappingModuleEntry();
+      assertEquals("Invalid number of entries", 1, mappingEntries.length);
+      MappingModuleEntry mappingEntry = mappingEntries[0];
+      assertEquals("org.jboss.test.mapping.MappingModule1", mappingEntry.getMappingModuleName());
+      Map<String, ?> mappingOptions = mappingEntry.getOptions();
+      assertEquals("Invalid number of options", 1, mappingOptions.size());
+      Assert.assertTrue("Option option1 was not found", mappingOptions.containsKey("option1"));
+      assertEquals("value1", mappingOptions.get("option1"));
+      
       // Role Mapping
-      MappingInfo mappingInfo = completeConfig.getRoleMappingInfo();
+      mappingInfo = completeConfig.getRoleMappingInfo();
       assertNotNull("MappingInfo is not null", mappingInfo);
       MappingModuleEntry[] mmearr = mappingInfo.getMappingModuleEntry();
       assertEquals("Mapping entry length=1", 1, mmearr.length);
@@ -293,6 +305,20 @@
       assertNotNull("MappingInfo is not null", mappingInfo);
       assertEquals("1 map modules", 1, mappingInfo.getModuleEntries().size());
 
+      // Mapping
+      mappingInfo = completeConfig.getMappingInfo("principal");
+      assertNotNull("MappingInfo is not null", mappingInfo);
+      MappingModuleEntry[] mappingEntries = mappingInfo.getMappingModuleEntry();
+      assertEquals("Invalid number of entries", 2, mappingEntries.length);
+      assertEquals("org.jboss.test.mapping.MappingModule1", mappingEntries[0].getMappingModuleName());
+      assertEquals("org.jboss.test.mapping.MappingModule3", mappingEntries[1].getMappingModuleName());
+      mappingInfo = completeConfig.getMappingInfo("identity");
+      assertNotNull("MappingInfo is not null", mappingInfo);
+      mappingEntries = mappingInfo.getMappingModuleEntry();
+      assertEquals("Invalid number of entries", 1, mappingEntries.length);
+      assertEquals("org.jboss.test.mapping.MappingModule2", mappingEntries[0].getMappingModuleName());
+      
+
       // Audit
       AuditInfo ai = completeConfig.getAuditInfo();
       assertNotNull("AuditInfo", ai);

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/tests/resources/config/securityConfig5.xml
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/tests/resources/config/securityConfig5.xml	2008-10-16 01:22:41 UTC (rev 79565)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/resources/config/securityConfig5.xml	2008-10-16 01:57:27 UTC (rev 79566)
@@ -73,7 +73,12 @@
              <module-option name = "name">rolemap</module-option>
              <module-option name = "succeed">true</module-option> 
           </mapping-module> 
-       </rolemapping>
+       </rolemapping>
+       <mapping>
+          <mapping-module code = "org.jboss.test.mapping.MappingModule1" type="principal">
+             <module-option name = "option1">value1</module-option>
+          </mapping-module>
+       </mapping>
        <audit>
           <provider-module code = "org.jboss.test.TestProviderModule"
              flag = "required"> 
@@ -124,6 +129,14 @@
              <module-option name="aclOption6">value6</module-option>
           </acl-module>
        </acl>
+       <mapping>
+          <mapping-module code = "org.jboss.test.mapping.MappingModule2" type="identity">
+             <module-option name = "option2">value2</module-option>
+          </mapping-module>
+          <mapping-module code = "org.jboss.test.mapping.MappingModule3" type="principal">
+             <module-option name = "option3">value3</module-option>
+          </mapping-module>
+       </mapping>
     </application-policy>
     
     <application-policy name="conf-jaspi-extend" extends="conf-jaspi">




More information about the jboss-cvs-commits mailing list