[jboss-cvs] JBossAS SVN: r79599 - in projects/security/security-jboss-sx/trunk: jbosssx/src/tests/org/jboss/test/security/config and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 16 14:12:12 EDT 2008
Author: sguilhen at redhat.com
Date: 2008-10-16 14:12:12 -0400 (Thu, 16 Oct 2008)
New Revision: 79599
Added:
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyBean.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyModule.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingMetaData.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingModuleMetaData.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/resources/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.xml
Removed:
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/RoleMappingPolicyBean.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/RoleMappingMetaData.java
Modified:
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/ApplicationPolicyBean.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/ApplicationPolicyMetaDataFactory.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/BasePolicyMetaData.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/resources/schema/security-beans_1_0.xsd
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ACLPolicyTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyExtendsTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyTestSuite.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuditPolicyTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuthorizationPolicyTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/BeanValidator.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/IdentityTrustPolicyTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ManagersInjectionTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/PolicyValidator.java
projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/RoleMappingPolicyTestCase.java
projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicy.java
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 the <mapping> element to the jbosssx-mc-integration project, allowing users to specify their mapping modules using this element in -jboss-beans.xml files.
- Fixed the implementations of get/setRoleMappingInfo and get/set/PrincipalMappingInfo: they now delegate their execution to get/setMappingInfo(String).
- Small fix to SecurityConfigurationUnitTestCase: it now tests a policy that has both rolemapping and mapping with type="role" elements, checking that the final MappingInfo contains the modules from both elements.
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 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/org/jboss/security/config/ApplicationPolicy.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -153,18 +153,7 @@
@Deprecated
public MappingInfo getRoleMappingInfo()
{
- MappingInfo bai = null;
- ApplicationPolicy ap = this.getBaseApplicationPolicy();
- if (ap != null)
- bai = ap.getRoleMappingInfo();
-
- MappingInfo roleMappings = this.mappingInfos.get("role");
- if (bai != null && roleMappings == null)
- return bai;
- else if (bai != null)
- return (MappingInfo) roleMappings.merge(bai);
- else
- return roleMappings;
+ return this.getMappingInfo("role");
}
/**
@@ -178,7 +167,7 @@
@Deprecated
public void setRoleMappingInfo(MappingInfo roleMappingInfo)
{
- this.mappingInfos.put("role", roleMappingInfo);
+ this.setMappingInfo("role", roleMappingInfo);
}
/**
@@ -192,19 +181,7 @@
@Deprecated
public MappingInfo getPrincipalMappingInfo()
{
- MappingInfo bai = null;
- ApplicationPolicy ap = this.getBaseApplicationPolicy();
- if (ap != null)
- bai = ap.getPrincipalMappingInfo();
-
- MappingInfo principalMappings = this.mappingInfos.get("principal");
- if (bai != null && principalMappings == null)
- return bai;
- else if (bai != null)
- return (MappingInfo) principalMappings.merge(bai);
- else
- return principalMappings;
-
+ return this.getMappingInfo("principal");
}
/**
@@ -218,7 +195,7 @@
@Deprecated
public void setPrincipalMappingInfo(MappingInfo principalMappingInfo)
{
- this.mappingInfos.put("principal", principalMappingInfo);
+ this.setMappingInfo("principal", principalMappingInfo);
}
/**
@@ -297,7 +274,11 @@
*/
public void setMappingInfo(String mappingType, MappingInfo info)
{
- this.mappingInfos.put(mappingType, info);
+ // if there is a registered info for the specified type, merge the modules.
+ if(this.mappingInfos.containsKey(mappingType))
+ this.mappingInfos.get(mappingType).add(info.getModuleEntries());
+ else
+ this.mappingInfos.put(mappingType, info);
}
public AuditInfo getAuditInfo()
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 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/security/config/SecurityConfigurationUnitTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -243,9 +243,9 @@
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 = completeConfig.getRoleMappingInfo();
+ mappingInfo = completeConfig.getMappingInfo("role");
assertNotNull("MappingInfo is not null", mappingInfo);
MappingModuleEntry[] mmearr = mappingInfo.getMappingModuleEntry();
assertEquals("Mapping entry length=1", 1, mmearr.length);
@@ -301,9 +301,10 @@
assertEquals("Unexpected number of acl modules", 3, aclInfo.getModuleEntries().size());
// Role Mapping
- MappingInfo mappingInfo = completeConfig.getRoleMappingInfo();
+ MappingInfo mappingInfo = completeConfig.getMappingInfo("role");
assertNotNull("MappingInfo is not null", mappingInfo);
- assertEquals("1 map modules", 1, mappingInfo.getModuleEntries().size());
+ // we expect 2 modules because one has been configured as a mapping of type "role"
+ assertEquals("2 map modules", 2, mappingInfo.getModuleEntries().size());
// Mapping
mappingInfo = completeConfig.getMappingInfo("principal");
@@ -312,12 +313,13 @@
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");
+ // same test as above: we expect 2 role-mapping modules: 1 from rolemapping and 1 from mapping with type "role".
+ mappingInfo = completeConfig.getMappingInfo("role");
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());
-
+ assertEquals("Invalid number of entries", 2, mappingEntries.length);
+ assertEquals("org.jboss.test.TestMappingModule", mappingEntries[0].getMappingModuleName());
+ assertEquals("org.jboss.test.mapping.MappingModule2", mappingEntries[1].getMappingModuleName());
// Audit
AuditInfo ai = completeConfig.getAuditInfo();
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 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/resources/config/securityConfig5.xml 2008-10-16 18:12:12 UTC (rev 79599)
@@ -130,7 +130,7 @@
</acl-module>
</acl>
<mapping>
- <mapping-module code = "org.jboss.test.mapping.MappingModule2" type="identity">
+ <mapping-module code = "org.jboss.test.mapping.MappingModule2" type="role">
<module-option name = "option2">value2</module-option>
</mapping-module>
<mapping-module code = "org.jboss.test.mapping.MappingModule3" type="principal">
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/ApplicationPolicyBean.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/ApplicationPolicyBean.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/ApplicationPolicyBean.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -21,6 +21,8 @@
*/
package org.jboss.security.microcontainer.beans;
+import java.util.Map;
+
import org.jboss.logging.Logger;
import org.jboss.security.AuthenticationManager;
import org.jboss.security.AuthorizationManager;
@@ -29,6 +31,7 @@
import org.jboss.security.auth.login.XMLLoginConfigImpl;
import org.jboss.security.config.ApplicationPolicy;
import org.jboss.security.config.ApplicationPolicyRegistration;
+import org.jboss.security.config.MappingInfo;
import org.jboss.security.identitytrust.IdentityTrustManager;
import org.jboss.security.mapping.MappingManager;
@@ -47,7 +50,7 @@
* @see org.jboss.security.microcontainer.beans.BaseAuthenticationPolicy
* @see org.jboss.security.microcontainer.beans.AuthorizationPolicyBean
* @see org.jboss.security.microcontainer.beans.ACLPolicyBean
- * @see org.jboss.security.microcontainer.beans.RoleMappingPolicyBean
+ * @see org.jboss.security.microcontainer.beans.MappingPolicyBean
* @see org.jboss.security.microcontainer.beans.AuditPolicyBean
* @see org.jboss.security.microcontainer.beans.IdentityTrustPolicyBean
*
@@ -73,7 +76,10 @@
private ACLPolicyBean aclPolicy;
/** the role-mapping policy configured as part of this application policy. */
- private RoleMappingPolicyBean roleMappingPolicy;
+ private MappingPolicyBean roleMappingPolicy;
+
+ /** the generic mapping policy configured as part of this application policy. */
+ private MappingPolicyBean mappingPolicy;
/** the audit policy configured as part of this application policy. */
private AuditPolicyBean auditPolicy;
@@ -213,9 +219,9 @@
* Obtains the role-mapping policy that has been configured as part of this application policy.
* </p>
*
- * @return a {@code RoleMappingPolicyBean} representing the configured role-mapping policy.
+ * @return a {@code MappingPolicyBean} representing the configured role-mapping policy.
*/
- public RoleMappingPolicyBean getRoleMappingPolicy()
+ public MappingPolicyBean getRoleMappingPolicy()
{
return roleMappingPolicy;
}
@@ -225,15 +231,39 @@
* Sets the role-mapping policy to be used by this application policy.
* </p>
*
- * @param roleMappingPolicy a {@code RoleMappingPolicyBean} representing the policy to be set.
+ * @param roleMappingPolicy a {@code MappingPolicyBean} representing the policy to be set.
*/
- public void setRoleMappingPolicy(RoleMappingPolicyBean roleMappingPolicy)
+ public void setRoleMappingPolicy(MappingPolicyBean roleMappingPolicy)
{
this.roleMappingPolicy = roleMappingPolicy;
}
/**
* <p>
+ * Obtains the generic mapping policy that has been configured as part of this application policy.
+ * </p>
+ *
+ * @return a {@code MappingPolicyBean} representing the configured mapping policy.
+ */
+ public MappingPolicyBean getMappingPolicy()
+ {
+ return this.mappingPolicy;
+ }
+
+ /**
+ * <p>
+ * Sets the generic mapping policy to be used by this application policy.
+ * </p>
+ *
+ * @param mappingPolicy a {@code MappingPolicyBean} representing the policy to be set.
+ */
+ public void setMappingPolicy(MappingPolicyBean mappingPolicy)
+ {
+ this.mappingPolicy = mappingPolicy;
+ }
+
+ /**
+ * <p>
* Obtains the audit policy that has been configured as part of this application policy.
* </p>
*
@@ -430,7 +460,17 @@
if (this.aclPolicy != null)
policy.setAclInfo(this.aclPolicy.getPolicyInfo(this.name));
if (this.roleMappingPolicy != null)
- policy.setRoleMappingInfo(this.roleMappingPolicy.getPolicyInfo(this.name));
+ {
+ Map<String,MappingInfo> infosByType = this.roleMappingPolicy.getMappingInfoByType(this.name);
+ for(String type : infosByType.keySet())
+ policy.setMappingInfo(type, infosByType.get(type));
+ }
+ if (this.mappingPolicy != null)
+ {
+ Map<String,MappingInfo> infosByType = this.mappingPolicy.getMappingInfoByType(this.name);
+ for(String type : infosByType.keySet())
+ policy.setMappingInfo(type, infosByType.get(type));
+ }
if (this.auditPolicy != null)
policy.setAuditInfo(this.auditPolicy.getPolicyInfo(this.name));
if (this.identityTrustPolicy != null)
@@ -456,6 +496,8 @@
buffer.append(this.aclPolicy.toString());
if (this.roleMappingPolicy != null)
buffer.append(this.roleMappingPolicy.toString());
+ if (this.mappingPolicy != null)
+ buffer.append(this.mappingPolicy.toString());
if (this.auditPolicy != null)
buffer.append(this.auditPolicy.toString());
if (this.identityTrustPolicy != null)
Copied: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyBean.java (from rev 79551, projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/RoleMappingPolicyBean.java)
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyBean.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyBean.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.microcontainer.beans;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.security.config.MappingInfo;
+import org.jboss.security.mapping.config.MappingModuleEntry;
+
+/**
+ * <p>
+ * This class represents a mapping policy.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
+ */
+public class MappingPolicyBean extends BasePolicyBean<MappingPolicyModule, MappingInfo>
+{
+
+ /**
+ * <p>
+ * Groups the mapping modules according to their types, and creates a {@code MappingInfo} object for each group of
+ * mapping modules.
+ * </p>
+ *
+ * @param domainName the name of the application-policy where the mappings where specified.
+ * @return a {@code Map<String,MappingInfo>} containing the generated {@code MappingInfo} objects keyed by the type
+ * of their modules.
+ */
+ public Map<String, MappingInfo> getMappingInfoByType(String domainName)
+ {
+ // get the mapping info that contains all mapping modules.
+ MappingInfo completeInfo = this.getPolicyInfo(domainName);
+ // now group the modules by type and create a mapping info for each group.
+ Map<String, MappingInfo> result = new HashMap<String, MappingInfo>();
+ for (MappingModuleEntry entry : completeInfo.getModuleEntries())
+ {
+ String type = entry.getMappingModuleType();
+ if (result.containsKey(type))
+ result.get(type).add(entry);
+ else
+ {
+ MappingInfo info = new MappingInfo(domainName);
+ info.add(entry);
+ result.put(type, info);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.security.microcontainer.beans.BasePolicyBean#getPolicyInfo(java.lang.String)
+ */
+ @Override
+ public MappingInfo getPolicyInfo(String domainName)
+ {
+ MappingInfo info = new MappingInfo(domainName);
+ for (MappingPolicyModule module : super.modules)
+ {
+ MappingModuleEntry entry = new MappingModuleEntry(module.getCode(), module.getOptions(), module.getType());
+ info.add(entry);
+ }
+ return info;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer("Role-Mapping Policy:\n");
+ for (int i = 0; i < super.modules.size(); i++)
+ {
+ MappingPolicyModule module = super.modules.get(i);
+ buffer.append("Module[" + i + "]\n");
+ buffer.append(module.toString());
+ }
+ return buffer.toString();
+ }
+}
Added: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyModule.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyModule.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/MappingPolicyModule.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.microcontainer.beans;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * This class represents a mapping module in an application policy configuration.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
+ */
+public class MappingPolicyModule extends BasePolicyModule
+{
+
+ /** The type of mapping provided by the module. */
+ private String type;
+
+ /**
+ * <p>
+ * Obtains the type of mapping provided by the module.
+ * </p>
+ *
+ * @return a {@code String} representing the type of mapping performed by the module.
+ */
+ public String getType()
+ {
+ return type;
+ }
+
+ /**
+ * <p>
+ * Sets the type of mapping provided by the mapping module.
+ * </p>
+ *
+ * @param type a {@code String} that represents the type of mapping performed by the module.
+ */
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.security.microcontainer.beans.BasePolicyModule#toString()
+ */
+ @Override
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Mapping module class: " + super.code);
+ buffer.append("\nMapping module type: " + this.type);
+ buffer.append("\nMapping module options: \n");
+ for (Map.Entry<String, Object> entry : super.options.entrySet())
+ buffer.append("\tname= " + entry.getKey() + ", value= " + entry.getValue() + "\n");
+ return buffer.toString();
+ }
+}
Deleted: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/RoleMappingPolicyBean.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/RoleMappingPolicyBean.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/RoleMappingPolicyBean.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -1,71 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.microcontainer.beans;
-
-import org.jboss.security.config.RoleMappingInfo;
-import org.jboss.security.mapping.config.MappingModuleEntry;
-
-/**
- * <p>
- * This class represents a role-mapping policy.
- * </p>
- *
- * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
- */
-public class RoleMappingPolicyBean extends BasePolicyBean<BasePolicyModule, RoleMappingInfo>
-{
-
- /*
- * (non-Javadoc)
- *
- * @see org.jboss.security.microcontainer.beans.BasePolicyBean#getPolicyInfo(java.lang.String)
- */
- @Override
- public RoleMappingInfo getPolicyInfo(String domainName)
- {
- RoleMappingInfo info = new RoleMappingInfo(domainName);
- for (BasePolicyModule module : super.modules)
- {
- MappingModuleEntry entry = new MappingModuleEntry(module.getCode(), module.getOptions());
- info.add(entry);
- }
- return info;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- StringBuffer buffer = new StringBuffer("Role-Mapping Policy:\n");
- for (int i = 0; i < super.modules.size(); i++)
- {
- BasePolicyModule module = super.modules.get(i);
- buffer.append("Module[" + i + "]\n");
- buffer.append(module.toString());
- }
- return buffer.toString();
- }
-}
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/ApplicationPolicyMetaDataFactory.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/ApplicationPolicyMetaDataFactory.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/ApplicationPolicyMetaDataFactory.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -43,7 +43,7 @@
import org.jboss.security.microcontainer.beans.AuthorizationPolicyBean;
import org.jboss.security.microcontainer.beans.IdentityTrustPolicyBean;
import org.jboss.security.microcontainer.beans.JASPIAuthenticationPolicyBean;
-import org.jboss.security.microcontainer.beans.RoleMappingPolicyBean;
+import org.jboss.security.microcontainer.beans.MappingPolicyBean;
import org.jboss.xb.annotations.JBossXmlSchema;
/**
@@ -82,7 +82,7 @@
@JBossXmlSchema(namespace = "urn:jboss:security-beans:1.0", elementFormDefault = XmlNsForm.QUALIFIED)
@XmlRootElement(name = "application-policy")
@XmlType(name = "applicationPolicyType", propOrder = {"authentication", "jaspiAuthentication", "authorization", "acl",
- "roleMapping", "audit", "identityTrust"})
+ "roleMapping", "mapping", "audit", "identityTrust"})
public class ApplicationPolicyMetaDataFactory implements BeanMetaDataFactory
{
@@ -110,8 +110,11 @@
private ACLMetaData aclMetaData;
/** the metadata of the role-mapping policy. */
- private RoleMappingMetaData mappingMetaData;
+ private MappingMetaData roleMappingMetaData;
+ /** the metadata of the generic mapping policy. */
+ private MappingMetaData mappingMetaData;
+
/** the metadata of the audit policy. */
private AuditMetaData auditMetaData;
@@ -227,11 +230,25 @@
* configuration.
* </p>
*
- * @param mappingMetaData a reference to the generated {@code RoleMappingMetaData}.
+ * @param mappingMetaData a reference to the generated {@code MappingMetaData}.
*/
- @XmlElement(name = "rolemapping", type = RoleMappingMetaData.class)
- public void setRoleMapping(RoleMappingMetaData mappingMetaData)
+ @XmlElement(name = "rolemapping", type = MappingMetaData.class)
+ public void setRoleMapping(MappingMetaData mappingMetaData)
{
+ this.roleMappingMetaData = mappingMetaData;
+ }
+
+ /**
+ * <p>
+ * Sets the metadata generated as a result of parsing the <mapping> element in an application policy
+ * configuration.
+ * </p>
+ *
+ * @param mappingMetaData a reference to the generated {@code MappingMetaData}.
+ */
+ @XmlElement(name = "mapping", type = MappingMetaData.class)
+ public void setMapping(MappingMetaData mappingMetaData)
+ {
this.mappingMetaData = mappingMetaData;
}
@@ -337,19 +354,32 @@
policyBuilder.addPropertyMetaData("aclPolicy", injectACLPolicy);
}
- // role-mappoing metadata.
- if (this.mappingMetaData != null)
+ // role-mapping metadata.
+ if (this.roleMappingMetaData != null)
{
logger.trace("Generating role-mapping metadata for policy " + this.policyName);
// get the metadata for the role-mapping policy bean.
String mappingPolicyName = this.policyName + "$RoleMappingPolicy";
- result.addAll(this.mappingMetaData.getBeans(mappingPolicyName, RoleMappingPolicyBean.class.getName()));
+ result.addAll(this.roleMappingMetaData.getBeans(mappingPolicyName, MappingPolicyBean.class.getName()));
// inject the role-mapping policy into the application policy.
ValueMetaData injectMappingPolicy = policyBuilder.createInject(mappingPolicyName);
policyBuilder.addPropertyMetaData("roleMappingPolicy", injectMappingPolicy);
}
+ // generic mapping metadata.
+ if (this.mappingMetaData != null)
+ {
+ logger.trace("Generating mapping metadata for policy " + this.policyName);
+ // get the metadata for the mapping policy bean.
+ String mappingPolicyName = this.policyName + "$MappingPolicy";
+ result.addAll(this.mappingMetaData.getBeans(mappingPolicyName, MappingPolicyBean.class.getName()));
+
+ // inject the mapping policy into the application policy.
+ ValueMetaData injectMappingPolicy = policyBuilder.createInject(mappingPolicyName);
+ policyBuilder.addPropertyMetaData("mappingPolicy", injectMappingPolicy);
+ }
+
// audit metadata.
if (this.auditMetaData != null)
{
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/BasePolicyMetaData.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/BasePolicyMetaData.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/BasePolicyMetaData.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -45,7 +45,7 @@
* Obtains the metadata of the modules that have been specified for the policy.
* </p>
*
- * @return a {@code List<BaseModuleMetaData>} containig the metadata of the modules.
+ * @return a {@code List<BaseModuleMetaData>} containing the metadata of the modules.
*/
public List<BaseModuleMetaData> getModules()
{
Copied: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingMetaData.java (from rev 79551, projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/RoleMappingMetaData.java)
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingMetaData.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingMetaData.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.microcontainer.beans.metadata;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * <p>
+ * This class represents a {@code <rolemapping>} or a {@code <mapping>} configuration in an application policy and
+ * contains the mapping metadata information extracted by the XB parser.
+ * </p>
+ * <p>
+ * The following policy excerpt shows an example of {@code <rolemapping>} configuration:
+ *
+ * <pre>
+ * <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
+ * <authentication>
+ * ...
+ * </authentication>
+ * ...
+ * <rolemapping>
+ * <mapping-module code="org.jboss.security.mapping.RoleMappingModule">
+ * <module-option name="mappingOption1">mapping.value1</module-option>
+ * <module-option name="mappingOption2">mapping.value2</module-option>
+ * </mapping-module>
+ * </rolemapping>
+ * ...
+ * </application-policy>
+ * </pre>
+ *
+ * Now an example of a {@code <mapping>} configuration:
+ *
+ * <pre>
+ * <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
+ * <authentication>
+ * ...
+ * </authentication>
+ * ...
+ * <mapping>
+ * <mapping-module code="org.jboss.security.mapping.RoleMappingModule" type="role">
+ * <module-option name="mappingOption1">mapping.value1</module-option>
+ * <module-option name="mappingOption2">mapping.value2</module-option>
+ * </mapping-module>
+ * </mapping>
+ * ...
+ * </application-policy>
+ * </pre>
+ *
+ * As can be noticed, both configurations are very similar. As a matter of fact, any module in a {@code <rolemapping>}
+ * configuration is actually registered as a {@code <mapping>} module of type {@code "role"}.
+ *
+ * The metadata that results from the XB parsing is used by the microcontainer to create an instance of
+ * {@code IdentityTrustPolicyBean} and inject this instance into the {@code ApplicationPolicyBean} that represents the
+ * application policy as a whole.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
+ */
+public class MappingMetaData extends BasePolicyMetaData
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.security.microcontainer.beans.metadata.BasePolicyMetaData#setModules(java.util.List)
+ */
+ @Override
+ @XmlElement(name = "mapping-module", type = MappingModuleMetaData.class)
+ public void setModules(List<BaseModuleMetaData> modules)
+ {
+ super.modules = modules;
+ }
+
+}
Added: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingModuleMetaData.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingModuleMetaData.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/MappingModuleMetaData.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.microcontainer.beans.metadata;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.security.microcontainer.beans.MappingPolicyModule;
+
+/**
+ * <p>
+ * This class extends the {@code BaseModuleMetaData} to add the metadata needed to build a {@code MappingPolicyModule}.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
+ */
+public class MappingModuleMetaData extends BaseModuleMetaData
+{
+
+ private static final String DEFAULT_TYPE = "role";
+
+ /** The type of mapping performed by the mapping module. */
+ private String type = DEFAULT_TYPE;
+
+ /**
+ * <p>
+ * Obtains the type of mapping performed by the mapping module.
+ * </p>
+ *
+ * @return a {@code String} representing the type of mapping executed by the mapping module.
+ */
+ public String getType()
+ {
+ return type;
+ }
+
+ /**
+ * <p>
+ * Sets the type of mapping performed by the mapping module.
+ * </p>
+ *
+ * @param type a {@code String} representing the type of mapping.
+ */
+ @XmlAttribute(name = "type", required = false)
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * <p>
+ * Overrides the superclass method to create a {@code BeanMetaDataObject} that will be used by the microcontainer to
+ * generate an instance of {@code MappingPolicyModule}.
+ * </p>
+ */
+ @Override
+ public BeanMetaData getBean(String moduleName)
+ {
+ // create the metadata for the module bean.
+ BeanMetaDataBuilder moduleBuilder = BeanMetaDataBuilder.createBuilder(moduleName, MappingPolicyModule.class
+ .getName());
+ moduleBuilder.addPropertyMetaData("code", this.code);
+ moduleBuilder.addPropertyMetaData("type", this.type);
+
+ // add the options map to the metadata.
+ if (this.moduleOptions != null)
+ {
+ Map<String, String> optionsMap = new HashMap<String, String>();
+ for (ModuleOptionMetaData optionMetaData : this.moduleOptions)
+ optionsMap.put(optionMetaData.getName(), optionMetaData.getValue());
+ moduleBuilder.addPropertyMetaData("options", optionsMap);
+ }
+
+ return moduleBuilder.getBeanMetaData();
+ }
+
+}
Deleted: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/RoleMappingMetaData.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/RoleMappingMetaData.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/java/org/jboss/security/microcontainer/beans/metadata/RoleMappingMetaData.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -1,73 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.microcontainer.beans.metadata;
-
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlElement;
-
-/**
- * <p>
- * This class represents the {@code <rolemapping>} configuration in an application policy and contains the role-mapping
- * metadata information extracted by the XB parser.
- * </p>
- * <p>
- * The following policy excerpt shows an example of {@code <rolemapping>} configuration:
- *
- * <pre>
- * <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
- * <authentication>
- * ...
- * </authentication>
- * ...
- * <rolemapping>
- * <mapping-module code="org.jboss.security.mapping.RoleMappingModule">
- * <module-option name="mappingOption1">mapping.value1</module-option>
- * <module-option name="mappingOption2">mapping.value2</module-option>
- * </mapping-module>
- * </rolemapping>
- * ...
- * </application-policy>
- * </pre>
- *
- * The metadata that results from the XB parsing is used by the microcontainer to create an instance of
- * {@code IdentityTrustPolicyBean} and inject this instance into the {@code ApplicationPolicyBean} that represents the
- * application policy as a whole.
- * </p>
- *
- * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
- */
-public class RoleMappingMetaData extends BasePolicyMetaData
-{
-
- /*
- * (non-Javadoc)
- *
- * @see org.jboss.security.microcontainer.beans.metadata.BasePolicyMetaData#setModules(java.util.List)
- */@Override
- @XmlElement(name = "mapping-module", type = BaseModuleMetaData.class)
- public void setModules(List<BaseModuleMetaData> modules)
- {
- super.modules = modules;
- }
-
-}
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/resources/schema/security-beans_1_0.xsd
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/resources/schema/security-beans_1_0.xsd 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/main/resources/schema/security-beans_1_0.xsd 2008-10-16 18:12:12 UTC (rev 79599)
@@ -40,6 +40,7 @@
<xsd:element ref="authorization" minOccurs="0"/>
<xsd:element ref="acl" minOccurs="0"/>
<xsd:element ref="rolemapping" minOccurs="0"/>
+ <xsd:element ref="mapping" minOccurs="0"/>
<xsd:element ref="audit" minOccurs="0"/>
<xsd:element ref="identity-trust" minOccurs="0"/>
</xsd:sequence>
@@ -98,8 +99,9 @@
</xsd:sequence>
</xsd:complexType>
- <xsd:element name="rolemapping" type="roleMappingType"/>
- <xsd:complexType name="roleMappingType">
+ <xsd:element name="rolemapping" type="mappingType"/>
+ <xsd:element name="mapping" type="mappingType"/>
+ <xsd:complexType name="mappingType">
<xsd:annotation>
<xsd:documentation>
<![CDATA[A Role-Mapping Policy Configuration]]>
@@ -265,6 +267,7 @@
<xsd:element ref="module-option" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="code" type="xsd:string" use="required"/>
+ <xsd:attribute name="type" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ACLPolicyTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ACLPolicyTestCase.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ACLPolicyTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -32,7 +32,7 @@
* policies along with the basic authentication policies.
* </p>
* <p>
- * The first scenario tests the configuration of an acl policy toghether with an authentication policy:
+ * The first scenario tests the configuration of an acl policy together with an authentication policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
@@ -59,7 +59,7 @@
* </application-policy>
* </pre>
*
- * while the second scenario tests the configuration of the acl policy toghether with an authentication-jaspi policy:
+ * while the second scenario tests the configuration of the acl policy together with an authentication-jaspi policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy2">
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyExtendsTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyExtendsTestCase.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyExtendsTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -25,7 +25,6 @@
import org.jboss.security.auth.login.JASPIAuthenticationInfo;
import org.jboss.security.auth.login.XMLLoginConfigImpl;
import org.jboss.security.config.ApplicationPolicy;
-import org.jboss.security.config.RoleMappingInfo;
import org.jboss.security.microcontainer.beans.ApplicationPolicyBean;
import org.jboss.test.kernel.junit.MicrocontainerTest;
import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
@@ -197,7 +196,7 @@
// validate the constructed acl policy.
PolicyValidator.validateACLPolicy("TestPolicy2", policy.getAclInfo());
// validate the constructed role-mapping policy, whose configuration comes exclusively from the parent policy.
- PolicyValidator.validateRoleMappingPolicy("TestPolicy1", (RoleMappingInfo) policy.getRoleMappingInfo());
+ PolicyValidator.validateRoleMappingPolicy("TestPolicy1", policy.getMappingInfo("role"));
// validate the constructed audit policy.
PolicyValidator.validateAuditPolicy("TestPolicy2", policy.getAuditInfo());
// validate the constructed identity-trust policy.
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyTestSuite.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyTestSuite.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ApplicationPolicyTestSuite.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -47,6 +47,7 @@
suite.addTestSuite(AuthorizationPolicyTestCase.class);
suite.addTestSuite(ACLPolicyTestCase.class);
suite.addTestSuite(RoleMappingPolicyTestCase.class);
+ suite.addTestSuite(MappingPolicyTestCase.class);
suite.addTestSuite(AuditPolicyTestCase.class);
suite.addTestSuite(IdentityTrustPolicyTestCase.class);
suite.addTestSuite(ApplicationPolicyMixedTestCase.class);
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuditPolicyTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuditPolicyTestCase.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuditPolicyTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -32,7 +32,7 @@
* authentication policies.
* </p>
* <p>
- * The first scenario tests the configuration of an audit policy toghether with an authentication policy:
+ * The first scenario tests the configuration of an audit policy together with an authentication policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
@@ -57,7 +57,7 @@
* </application-policy>
* </pre>
*
- * while the second scenario tests the configuration of the audit policy toghether with an authentication-jaspi policy:
+ * while the second scenario tests the configuration of the audit policy together with an authentication-jaspi policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy2">
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuthorizationPolicyTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuthorizationPolicyTestCase.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/AuthorizationPolicyTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -32,7 +32,7 @@
* basic authentication policies.
* </p>
* <p>
- * The first scenario tests the configuration of an authorization policy toghether with an authentication policy:
+ * The first scenario tests the configuration of an authorization policy together with an authentication policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
@@ -59,7 +59,7 @@
* </application-policy>
* </pre>
*
- * while the second scenario tests the configuration of the authorization policy toghether with an authentication-jaspi
+ * while the second scenario tests the configuration of the authorization policy together with an authentication-jaspi
* policy:
*
* <pre>
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/BeanValidator.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/BeanValidator.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/BeanValidator.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -35,7 +35,8 @@
import org.jboss.security.microcontainer.beans.IdentityTrustPolicyBean;
import org.jboss.security.microcontainer.beans.JASPIAuthenticationPolicyBean;
import org.jboss.security.microcontainer.beans.LoginModuleStackBean;
-import org.jboss.security.microcontainer.beans.RoleMappingPolicyBean;
+import org.jboss.security.microcontainer.beans.MappingPolicyBean;
+import org.jboss.security.microcontainer.beans.MappingPolicyModule;
import org.jboss.security.microcontainer.beans.StackRefPolicyModule;
/**
@@ -308,7 +309,7 @@
/**
* <p>
- * Validates the contents of a {@code RoleMappingPolicyBean} generated by the metadata factory from a role-mapping
+ * Validates the contents of a {@code MappingPolicyBean} generated by the metadata factory from a role-mapping
* configuration like the following:
*
* <pre>
@@ -326,20 +327,21 @@
*
* </p>
*
- * @param bean the {@code RoleMappingPolicyBean} instance being validated.
+ * @param bean the {@code MappingPolicyBean} instance being validated.
* @throws Exception if an error occurs while running the validation tests.
*/
- public static void validateRoleMappingBean(RoleMappingPolicyBean bean) throws Exception
+ public static void validateRoleMappingBean(MappingPolicyBean bean) throws Exception
{
Assert.assertNotNull("Invalid null bean", bean);
// check the policy-modules that have been specified in the role-mapping configuration.
- List<BasePolicyModule> modules = bean.getModules();
+ List<MappingPolicyModule> modules = bean.getModules();
Assert.assertNotNull("Invalid null list of modules found", modules);
Assert.assertEquals("Invalid number of modules", 2, modules.size());
// first module should be the org.jboss.security.mapping.RoleMappingModule1.
Assert.assertEquals("org.jboss.security.mapping.RoleMappingModule1", modules.get(0).getCode());
+ Assert.assertEquals("role", modules.get(0).getType());
Map<String, ?> options = modules.get(0).getOptions();
Assert.assertNotNull("Unexpected null options map", options);
Assert.assertTrue("Option mappingOption1 was not found", options.containsKey("mappingOption1"));
@@ -349,6 +351,7 @@
// second module should be the org.jboss.security.mapping.RoleMappingModule2.
Assert.assertEquals("org.jboss.security.mapping.RoleMappingModule2", modules.get(1).getCode());
+ Assert.assertEquals("role", modules.get(1).getType());
options = modules.get(1).getOptions();
Assert.assertNotNull("Unexpected null options map", options);
Assert.assertTrue("Option mappingOption3 was not found", options.containsKey("mappingOption3"));
@@ -359,6 +362,59 @@
/**
* <p>
+ * Validates the contents of a {@code MappingPolicyBean} generated by the metadata factory from a mapping
+ * configuration like the following:
+ *
+ * <pre>
+ * <mapping>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule1" type="role">
+ * <module-option name="mappingOption1">value1</module-option>
+ * <module-option name="mappingOption2">value2</module-option>
+ * </mapping-module>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule2" type="principal">
+ * <module-option name="mappingOption3">value3</module-option>
+ * <module-option name="mappingOption4">value4</module-option>
+ * </mapping-module>
+ * </mapping>
+ * </pre>
+ *
+ * </p>
+ *
+ * @param bean the {@code MappingPolicyBean} instance being validated.
+ * @throws Exception if an error occurs while running the validation tests.
+ */
+ public static void validateMappingBean(MappingPolicyBean bean) throws Exception
+ {
+ Assert.assertNotNull("Invalid null bean", bean);
+
+ // check the policy-modules that have been specified in the mapping configuration.
+ List<MappingPolicyModule> modules = bean.getModules();
+ Assert.assertNotNull("Invalid null list of modules found", modules);
+ Assert.assertEquals("Invalid number of modules", 2, modules.size());
+
+ // first module should be the org.jboss.security.mapping.MappingModule1.
+ Assert.assertEquals("org.jboss.security.mapping.MappingModule1", modules.get(0).getCode());
+ Assert.assertEquals("role", modules.get(0).getType());
+ Map<String, ?> options = modules.get(0).getOptions();
+ Assert.assertNotNull("Unexpected null options map", options);
+ Assert.assertTrue("Option mappingOption1 was not found", options.containsKey("mappingOption1"));
+ Assert.assertEquals("value1", options.get("mappingOption1"));
+ Assert.assertTrue("Option authOption2 was not found", options.containsKey("mappingOption2"));
+ Assert.assertEquals("value2", options.get("mappingOption2"));
+
+ // second module should be the org.jboss.security.mapping.MappingModule2.
+ Assert.assertEquals("org.jboss.security.mapping.MappingModule2", modules.get(1).getCode());
+ Assert.assertEquals("principal", modules.get(1).getType());
+ options = modules.get(1).getOptions();
+ Assert.assertNotNull("Unexpected null options map", options);
+ Assert.assertTrue("Option mappingOption3 was not found", options.containsKey("mappingOption3"));
+ Assert.assertEquals("value3", options.get("mappingOption3"));
+ Assert.assertTrue("Option mappingOption4 was not found", options.containsKey("mappingOption4"));
+ Assert.assertEquals("value4", options.get("mappingOption4"));
+ }
+
+ /**
+ * <p>
* Validates the contents of an {@code AuditPolicyBean} generated by the metadata factory from an audit configuration
* like the following:
*
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/IdentityTrustPolicyTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/IdentityTrustPolicyTestCase.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/IdentityTrustPolicyTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -32,7 +32,7 @@
* the basic authentication policies.
* </p>
* <p>
- * The first scenario tests the configuration of an identity-trust policy toghether with an authentication policy:
+ * The first scenario tests the configuration of an identity-trust policy together with an authentication policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
@@ -55,7 +55,7 @@
* </application-policy>
* </pre>
*
- * while the second scenario tests the configuration of the trust policy toghether with an authentication-jaspi policy:
+ * while the second scenario tests the configuration of the trust policy together with an authentication-jaspi policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy2">
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ManagersInjectionTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ManagersInjectionTestCase.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/ManagersInjectionTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -70,8 +70,8 @@
* configuration to authenticate users.</li>
* <li>authorizationManager - retrieves the {@code AuthorizationManager} that uses the {@code <authorization>}
* configuration to authorize access to resources.</li>
- * <li>mappingManager - retrieves the {@code MappingManager} that uses the {@code <rolemapping>} configuration to map
- * roles and identities.</li>
+ * <li>mappingManager - retrieves the {@code MappingManager} that uses the {@code <rolemapping>} and {@code <mapping>}
+ * configurations to map roles and identities.</li>
* <li>auditManager - retrieves the {@code AuditManager} that uses the {@code <audit>} configuration to perform
* auditing.</li>
* <li>identityTrustManager - retrieves the {@code IdentityTrustManager} that uses the {@code <identity-trust>}
Added: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.security.microcontainer.metadata;
+
+import org.jboss.security.auth.login.XMLLoginConfigImpl;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.microcontainer.beans.ApplicationPolicyBean;
+import org.jboss.security.microcontainer.beans.MappingPolicyBean;
+
+/**
+ * <p>
+ * Extends the {@code BasicApplicationPolicyTestCase} to test the configuration of mapping policies along with the basic
+ * authentication policies.
+ * </p>
+ * <p>
+ * The first scenario tests the configuration of a mapping policy together with an authentication policy:
+ *
+ * <pre>
+ * <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
+ * <authentication>
+ * <login-module code="org.jboss.security.auth.AuthModule1" flag="required">
+ * <module-option name="authOption1">value1</module-option>
+ * <module-option name="authOption2">value2</module-option>
+ * </login-module>
+ * <login-module code="org.jboss.security.auth.AuthModule2" flag="optional">
+ * <module-option name="authOption3">value3</module-option>
+ * <module-option name="authOption4">value4</module-option>
+ * </login-module>
+ * </authentication>
+ * <mapping>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule1" type="role">
+ * <module-option name="mappingOption1">value1</module-option>
+ * <module-option name="mappingOption2">value2</module-option>
+ * </mapping-module>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule2" type="principal">
+ * <module-option name="mappingOption3">value3</module-option>
+ * <module-option name="mappingOption4">value4</module-option>
+ * </mapping-module>
+ * </mapping>
+ * </application-policy>
+ * </pre>
+ *
+ * while the second scenario tests the configuration of the mapping policy together with an authentication-jaspi policy:
+ *
+ * <pre>
+ * <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy2">
+ * <authentication-jaspi>
+ * <login-module-stack name="ModuleStack1">
+ * <login-module code="org.jboss.security.auth.AuthModule3" flag="required">
+ * <module-option name="authOption5">value5</module-option>
+ * </login-module>
+ * <login-module code="org.jboss.security.auth.AuthModule4" flag="optional"/>
+ * </login-module-stack>
+ * <login-module-stack name="ModuleStack2">
+ * <login-module code="org.jboss.security.auth.AuthModule5" flag="required">
+ * <module-option name="authOption6">value6</module-option>
+ * <module-option name="authOption7">value7</module-option>
+ * </login-module>
+ * </login-module-stack>
+ * <auth-module code="org.jboss.security.auth.AuthModule1" login-module-stack-ref="ModuleStack2">
+ * <module-option name="authOption1">value1</module-option>
+ * <module-option name="authOption2">value2</module-option>
+ * </auth-module>
+ * </authentication-jaspi>
+ * <mapping>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule1" type="role">
+ * <module-option name="mappingOption1">value1</module-option>
+ * <module-option name="mappingOption2">value2</module-option>
+ * </mapping-module>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule2" type="principal">
+ * <module-option name="mappingOption3">value3</module-option>
+ * <module-option name="mappingOption4">value4</module-option>
+ * </mapping-module>
+ * </mapping>
+ * </application-policy>
+ *
+ * </pre>
+ *
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
+ */
+public class MappingPolicyTestCase extends BasicApplicationPolicyTestCase
+{
+
+ /**
+ * <p>
+ * Creates an instance of {@code MappingPolicyTestCase} with the specified name.
+ * </p>
+ *
+ * @param name a {@code String} representing the name of this test case.
+ */
+ public MappingPolicyTestCase(String name)
+ {
+ super(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.test.security.microcontainer.beans.BasicApplicationPolicyTestCase#testApplicationPoliciesCreation()
+ */
+ @Override
+ public void testApplicationPoliciesCreation() throws Exception
+ {
+ super.testApplicationPoliciesCreation();
+
+ // validate the mapping policy beans have been properly created.
+ ApplicationPolicyBean policyBean1 = (ApplicationPolicyBean) super.getBean("TestPolicy1");
+ assertNotNull("Unexpected null mapping policy found", policyBean1.getMappingPolicy());
+
+ ApplicationPolicyBean policyBean2 = (ApplicationPolicyBean) super.getBean("TestPolicy2");
+ assertNotNull("Unexpected null mapping policy found", policyBean2.getMappingPolicy());
+
+ MappingPolicyBean mappingBean = (MappingPolicyBean) super.getBean("TestPolicy1$MappingPolicy");
+ // assert the bean retrieved from the microcontainer is the same that has been injected into the app policy.
+ assertEquals(policyBean1.getMappingPolicy(), mappingBean);
+ BeanValidator.validateMappingBean(mappingBean);
+
+ mappingBean = (MappingPolicyBean) super.getBean("TestPolicy2$MappingPolicy");
+ assertEquals(policyBean2.getMappingPolicy(), mappingBean);
+ BeanValidator.validateMappingBean(mappingBean);
+
+ // verify the contents of the mapping policies.
+ ApplicationPolicy policy = XMLLoginConfigImpl.getInstance().getApplicationPolicy("TestPolicy1");
+ PolicyValidator.validateMappingPolicy("TestPolicy1", policy.getMappingInfo("role"), "role");
+ PolicyValidator.validateMappingPolicy("TestPolicy1", policy.getMappingInfo("principal"), "principal");
+
+ policy = XMLLoginConfigImpl.getInstance().getApplicationPolicy("TestPolicy2");
+ PolicyValidator.validateMappingPolicy("TestPolicy2", policy.getMappingInfo("role"), "role");
+ PolicyValidator.validateMappingPolicy("TestPolicy2", policy.getMappingInfo("principal"), "principal");
+
+ }
+}
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/PolicyValidator.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/PolicyValidator.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/PolicyValidator.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -39,7 +39,7 @@
import org.jboss.security.config.AuditInfo;
import org.jboss.security.config.AuthorizationInfo;
import org.jboss.security.config.IdentityTrustInfo;
-import org.jboss.security.config.RoleMappingInfo;
+import org.jboss.security.config.MappingInfo;
import org.jboss.security.identitytrust.config.IdentityTrustModuleEntry;
import org.jboss.security.mapping.config.MappingModuleEntry;
@@ -325,8 +325,8 @@
/**
* <p>
- * Validates the contents of a {@code RoleMappingInfo} object that has been generated by the
- * {@code RoleMappingPolicyBean} that corresponds to the following rolemapping configuration:
+ * Validates the contents of a {@code MappingInfo} object that has been generated by the {@code MappingPolicyBean}
+ * that corresponds to the following rolemapping configuration:
*
* <pre>
* <rolemapping>
@@ -344,10 +344,10 @@
* </p>
*
* @param appPolicyName the name of the application-policy that specifies the rolemapping configuration.
- * @param mappingInfo the {@code RoleMappingInfo} instance being validated.
+ * @param mappingInfo the {@code MappingInfo} instance being validated.
* @throws Exception if an error occurs while running the validation tests.
*/
- public static void validateRoleMappingPolicy(String appPolicyName, RoleMappingInfo mappingInfo) throws Exception
+ public static void validateRoleMappingPolicy(String appPolicyName, MappingInfo mappingInfo) throws Exception
{
Assert.assertNotNull("Role-mapping policy not found", mappingInfo);
Assert.assertEquals("Role-mapping policy has unexpected name", appPolicyName, mappingInfo.getName());
@@ -358,6 +358,7 @@
// first entry should be the org.jboss.security.mapping.RoleMappingModule1.
Assert.assertEquals("org.jboss.security.mapping.RoleMappingModule1", entries[0].getMappingModuleName());
+ Assert.assertEquals("role", entries[0].getMappingModuleType());
Map<String, ?> options = entries[0].getOptions();
Assert.assertNotNull("Unexpected null options map", options);
Assert.assertTrue("Option mappingOption1 was not found", options.containsKey("mappingOption1"));
@@ -367,6 +368,7 @@
// second entry should be the org.jboss.security.mapping.RoleMappingModule2.
Assert.assertEquals("org.jboss.security.mapping.RoleMappingModule2", entries[1].getMappingModuleName());
+ Assert.assertEquals("role", entries[1].getMappingModuleType());
options = entries[1].getOptions();
Assert.assertNotNull("Unexpected null options map", options);
Assert.assertTrue("Option mappingOption3 was not found", options.containsKey("mappingOption3"));
@@ -377,6 +379,71 @@
/**
* <p>
+ * Validates the contents of a {@code MappingInfo} object that has been generated by the {@code MappingPolicyBean}
+ * that corresponds to the following mapping configuration:
+ *
+ * <pre>
+ * <mapping>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule1" type="role">
+ * <module-option name="mappingOption1">value1</module-option>
+ * <module-option name="mappingOption2">value2</module-option>
+ * </mapping-module>
+ * <mapping-module code="org.jboss.security.mapping.MappingModule2" type="principal">
+ * <module-option name="mappingOption3">value3</module-option>
+ * <module-option name="mappingOption4">value4</module-option>
+ * </mapping-module>
+ * </mapping>
+ * </pre>
+ *
+ * </p>
+ *
+ * @param appPolicyName the name of the application-policy that specifies the mapping configuration.
+ * @param mappingInfo the {@code MappingInfo} instance being validated.
+ * @param mappingType the type of mapping provided by the {@code MappingInfo}.
+ * @throws Exception if an error occurs while running the validation tests.
+ */
+ public static void validateMappingPolicy(String appPolicyName, MappingInfo mappingInfo, String mappingType)
+ throws Exception
+ {
+ Assert.assertNotNull("Mapping policy not found", mappingInfo);
+ Assert.assertEquals("Mapping policy has unexpected name", appPolicyName, mappingInfo.getName());
+
+ MappingModuleEntry[] entries = mappingInfo.getMappingModuleEntry();
+ Assert.assertNotNull("Invalid null MappingModuleEntry array", entries);
+ Assert.assertEquals("Unexpected number of mapping entries", 1, entries.length);
+
+ if (mappingType.equals("role"))
+ {
+ // entry should be the org.jboss.security.mapping.MappingModule1.
+ Assert.assertEquals("org.jboss.security.mapping.MappingModule1", entries[0].getMappingModuleName());
+ Assert.assertEquals("role", entries[0].getMappingModuleType());
+ Map<String, ?> options = entries[0].getOptions();
+ Assert.assertNotNull("Unexpected null options map", options);
+ Assert.assertTrue("Option mappingOption1 was not found", options.containsKey("mappingOption1"));
+ Assert.assertEquals("value1", options.get("mappingOption1"));
+ Assert.assertTrue("Option mappingOption2 was not found", options.containsKey("mappingOption2"));
+ Assert.assertEquals("value2", options.get("mappingOption2"));
+ }
+ else if (mappingType.equals("principal"))
+ {
+ // entry should be the org.jboss.security.mapping.MappingModule2.
+ Assert.assertEquals("org.jboss.security.mapping.MappingModule2", entries[0].getMappingModuleName());
+ Assert.assertEquals("principal", entries[0].getMappingModuleType());
+ Map<String, ?> options = entries[0].getOptions();
+ Assert.assertNotNull("Unexpected null options map", options);
+ Assert.assertTrue("Option mappingOption3 was not found", options.containsKey("mappingOption3"));
+ Assert.assertEquals("value3", options.get("mappingOption3"));
+ Assert.assertTrue("Option mappingOption4 was not found", options.containsKey("mappingOption4"));
+ Assert.assertEquals("value4", options.get("mappingOption4"));
+ }
+ else
+ {
+ Assert.fail("Cannot validate MappingInfo of type " + mappingType);
+ }
+ }
+
+ /**
+ * <p>
* Validates the contents of an {@code AuditInfo} object that has been generated by the {@code AuditPolicyBean} that
* corresponds to the following audit configuration:
*
Modified: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/RoleMappingPolicyTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/RoleMappingPolicyTestCase.java 2008-10-16 17:55:42 UTC (rev 79598)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/java/org/jboss/test/security/microcontainer/metadata/RoleMappingPolicyTestCase.java 2008-10-16 18:12:12 UTC (rev 79599)
@@ -23,9 +23,8 @@
import org.jboss.security.auth.login.XMLLoginConfigImpl;
import org.jboss.security.config.ApplicationPolicy;
-import org.jboss.security.config.RoleMappingInfo;
import org.jboss.security.microcontainer.beans.ApplicationPolicyBean;
-import org.jboss.security.microcontainer.beans.RoleMappingPolicyBean;
+import org.jboss.security.microcontainer.beans.MappingPolicyBean;
/**
* <p>
@@ -33,7 +32,7 @@
* basic authentication policies.
* </p>
* <p>
- * The first scenario tests the configuration of a role-mapping policy toghether with an authentication policy:
+ * The first scenario tests the configuration of a role-mapping policy together with an authentication policy:
*
* <pre>
* <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
@@ -60,7 +59,7 @@
* </application-policy>
* </pre>
*
- * while the second scenario tests the configuration of the role-mapping policy toghether with an authentication-jaspi
+ * while the second scenario tests the configuration of the role-mapping policy together with an authentication-jaspi
* policy:
*
* <pre>
@@ -133,21 +132,21 @@
ApplicationPolicyBean policyBean2 = (ApplicationPolicyBean) super.getBean("TestPolicy2");
assertNotNull("Unexpected null role-mapping policy found", policyBean2.getRoleMappingPolicy());
- RoleMappingPolicyBean mappingBean = (RoleMappingPolicyBean) super.getBean("TestPolicy1$RoleMappingPolicy");
+ MappingPolicyBean mappingBean = (MappingPolicyBean) super.getBean("TestPolicy1$RoleMappingPolicy");
// assert the bean retrieved from the microcontainer is the same that has been injected into the app policy.
assertEquals(policyBean1.getRoleMappingPolicy(), mappingBean);
BeanValidator.validateRoleMappingBean(mappingBean);
- mappingBean = (RoleMappingPolicyBean) super.getBean("TestPolicy2$RoleMappingPolicy");
+ mappingBean = (MappingPolicyBean) super.getBean("TestPolicy2$RoleMappingPolicy");
assertEquals(policyBean2.getRoleMappingPolicy(), mappingBean);
BeanValidator.validateRoleMappingBean(mappingBean);
// verify the contents of the role-mapping policies.
ApplicationPolicy policy = XMLLoginConfigImpl.getInstance().getApplicationPolicy("TestPolicy1");
- PolicyValidator.validateRoleMappingPolicy("TestPolicy1", (RoleMappingInfo) policy.getRoleMappingInfo());
+ PolicyValidator.validateRoleMappingPolicy("TestPolicy1", policy.getMappingInfo("role"));
policy = XMLLoginConfigImpl.getInstance().getApplicationPolicy("TestPolicy2");
- PolicyValidator.validateRoleMappingPolicy("TestPolicy2", (RoleMappingInfo) policy.getRoleMappingInfo());
+ PolicyValidator.validateRoleMappingPolicy("TestPolicy2", policy.getMappingInfo("role"));
}
}
Added: projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/resources/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.xml
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/resources/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.xml (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx-mc-int/src/test/resources/org/jboss/test/security/microcontainer/metadata/MappingPolicyTestCase.xml 2008-10-16 18:12:12 UTC (rev 79599)
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- the security management bean -->
+ <bean name="JNDIBasedSecurityManagement"
+ class="org.jboss.test.security.microcontainer.metadata.support.MockSecurityManagement"/>
+
+ <!-- an application policy that specifies authentication and mapping configurations -->
+ <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy1">
+ <authentication>
+ <login-module code="org.jboss.security.auth.AuthModule1" flag="required">
+ <module-option name="authOption1">value1</module-option>
+ <module-option name="authOption2">value2</module-option>
+ </login-module>
+ <login-module code="org.jboss.security.auth.AuthModule2" flag="optional">
+ <module-option name="authOption3">value3</module-option>
+ <module-option name="authOption4">value4</module-option>
+ </login-module>
+ </authentication>
+ <mapping>
+ <mapping-module code="org.jboss.security.mapping.MappingModule1" type="role">
+ <module-option name="mappingOption1">value1</module-option>
+ <module-option name="mappingOption2">value2</module-option>
+ </mapping-module>
+ <mapping-module code="org.jboss.security.mapping.MappingModule2" type="principal">
+ <module-option name="mappingOption3">value3</module-option>
+ <module-option name="mappingOption4">value4</module-option>
+ </mapping-module>
+ </mapping>
+ </application-policy>
+
+ <!-- an application policy that specifies authentication-jaspi and role-mapping configurations -->
+ <application-policy xmlns="urn:jboss:security-beans:1.0" name="TestPolicy2">
+ <authentication-jaspi>
+ <login-module-stack name="ModuleStack1">
+ <login-module code="org.jboss.security.auth.AuthModule3" flag="required">
+ <module-option name="authOption5">value5</module-option>
+ </login-module>
+ <login-module code="org.jboss.security.auth.AuthModule4" flag="optional"/>
+ </login-module-stack>
+ <login-module-stack name="ModuleStack2">
+ <login-module code="org.jboss.security.auth.AuthModule5" flag="required">
+ <module-option name="authOption6">value6</module-option>
+ <module-option name="authOption7">value7</module-option>
+ </login-module>
+ </login-module-stack>
+ <auth-module code="org.jboss.security.auth.AuthModule1" login-module-stack-ref="ModuleStack1"/>
+ <auth-module code="org.jboss.security.auth.AuthModule2" login-module-stack-ref="ModuleStack2">
+ <module-option name="authOption1">value1</module-option>
+ <module-option name="authOption2">value2</module-option>
+ </auth-module>
+ </authentication-jaspi>
+ <mapping>
+ <mapping-module code="org.jboss.security.mapping.MappingModule1" type="role">
+ <module-option name="mappingOption1">value1</module-option>
+ <module-option name="mappingOption2">value2</module-option>
+ </mapping-module>
+ <mapping-module code="org.jboss.security.mapping.MappingModule2" type="principal">
+ <module-option name="mappingOption3">value3</module-option>
+ <module-option name="mappingOption4">value4</module-option>
+ </mapping-module>
+ </mapping>
+ </application-policy>
+
+</deployment>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list