[jboss-cvs] JBossAS SVN: r99851 - in projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src: main/java/org/jboss/security/config and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 22 22:25:58 EST 2010
Author: anil.saldhana at jboss.com
Date: 2010-01-22 22:25:57 -0500 (Fri, 22 Jan 2010)
New Revision: 99851
Added:
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/config/StaxConfigParserUnitTestCase.java
Modified:
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/AuthenticationInfo.java
projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/MappingInfo.java
Log:
STAX based parser
Modified: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/AuthenticationInfo.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/AuthenticationInfo.java 2010-01-23 02:38:02 UTC (rev 99850)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/auth/login/AuthenticationInfo.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -21,8 +21,10 @@
*/
package org.jboss.security.auth.login;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -73,7 +75,16 @@
moduleEntries.addAll(Arrays.asList(loginModules));
}
+
+ public void setAppConfigurationEntry(List<AppConfigurationEntry> listOfEntries)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(SET_CONFIG_ENTRY_PERM);
+ moduleEntries.addAll(listOfEntries);
+ }
+
/**
*/
public CallbackHandler getAppCallbackHandler()
Modified: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/MappingInfo.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/MappingInfo.java 2010-01-23 02:38:02 UTC (rev 99850)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/MappingInfo.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -40,5 +40,5 @@
protected BaseSecurityInfo<MappingModuleEntry> create(String name)
{
return new MappingInfo(name);
- }
+ }
}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AclConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,110 @@
+/*
+ * 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.config.parser;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.acl.config.ACLProviderEntry;
+import org.jboss.security.config.ControlFlag;
+
+/**
+ * Stax based Parser to parse the acl configuration
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class AclConfigParser
+{
+ /**
+ * Parse the <acl> element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public Set<ACLProviderEntry> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ Set<ACLProviderEntry> entries = new LinkedHashSet<ACLProviderEntry>();
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ ACLProviderEntry entry = null;
+ if("acl-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ entry = this.getEntry(xmlEventReader);
+ }
+ else
+ break;
+ entries.add(entry);
+ }
+ return entries;
+ }
+
+ @SuppressWarnings("unchecked")
+ private ACLProviderEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+
+ String codeName = null;
+ ControlFlag controlFlag = ControlFlag.REQUIRED;
+
+ //We got the login-module element
+ StartElement policyModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = policyModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ else if("flag".equals(attQName.getLocalPart()))
+ {
+ controlFlag = ControlFlag.valueOf(attribute.getValue());
+ }
+ }
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ ACLProviderEntry entry = new ACLProviderEntry(codeName, options);
+ entry.setControlFlag(controlFlag);
+ return entry;
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ApplicationPolicyParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,187 @@
+/*
+ * 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.config.parser;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.acl.config.ACLProviderEntry;
+import org.jboss.security.audit.config.AuditProviderEntry;
+import org.jboss.security.auth.login.AuthenticationInfo;
+import org.jboss.security.auth.login.JASPIAuthenticationInfo;
+import org.jboss.security.authorization.config.AuthorizationModuleEntry;
+import org.jboss.security.config.ACLInfo;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.config.AuditInfo;
+import org.jboss.security.config.AuthorizationInfo;
+import org.jboss.security.config.IdentityTrustInfo;
+import org.jboss.security.config.MappingInfo;
+import org.jboss.security.identitytrust.config.IdentityTrustModuleEntry;
+import org.jboss.security.mapping.MappingType;
+import org.jboss.security.mapping.config.MappingModuleEntry;
+
+/**
+ * Stax based Application Policy Parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class ApplicationPolicyParser
+{
+ @SuppressWarnings("unchecked")
+ public List<ApplicationPolicy> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ List<ApplicationPolicy> policies = new ArrayList<ApplicationPolicy>();
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ int eventType = xmlEvent.getEventType();
+ switch(eventType)
+ {
+ case XMLStreamConstants.START_ELEMENT:
+ StartElement appPolicyElement = (StartElement) xmlEvent;
+ //We got the application-policy element. It just has one attribute "name"
+ Iterator<Attribute> attrs = appPolicyElement.getAttributes();
+ String extendsName = null;
+ String appPolicyName = null;
+
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+ if("name".equals(attribute.getName().getLocalPart()))
+ appPolicyName = attribute.getValue();
+ else if("extends".equals(attribute.getName().getLocalPart()))
+ extendsName = attribute.getValue();
+ }
+
+ ApplicationPolicy applicationPolicy = new ApplicationPolicy(appPolicyName);
+ if(extendsName != null)
+ applicationPolicy.setBaseApplicationPolicyName(extendsName);
+
+ route(xmlEventReader, applicationPolicy);
+ policies.add(applicationPolicy);
+ }
+ }
+ return policies;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void route(XMLEventReader xmlEventReader, ApplicationPolicy appPolicy) throws XMLStreamException
+ {
+ while(true)
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+ if(xmlEvent == null)
+ return;
+ StartElement startElement = xmlEvent.asStartElement();
+ String elementName = startElement.getName().getLocalPart();
+ if("authentication".equals(elementName))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ AuthenticationConfigParser parser = new AuthenticationConfigParser();
+ Set<AppConfigurationEntry> entries = parser.parse(xmlEventReader);
+ AuthenticationInfo authInfo = new AuthenticationInfo();
+
+ authInfo.setAppConfigurationEntry(new ArrayList(entries));
+ appPolicy.setAuthenticationInfo(authInfo);
+ }
+ else if("authentication-jaspi".equals(elementName))
+ {
+
+ xmlEvent = xmlEventReader.nextEvent();
+ AuthenticationJASPIConfigParser parser = new AuthenticationJASPIConfigParser();
+ JASPIAuthenticationInfo authInfo = parser.parse(xmlEventReader);
+ appPolicy.setAuthenticationInfo(authInfo);
+ }
+ else if("authorization".equals(elementName))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ AuthorizationConfigParser parser = new AuthorizationConfigParser();
+ Set<AuthorizationModuleEntry> entries = parser.parse(xmlEventReader);
+ AuthorizationInfo authInfo = new AuthorizationInfo(appPolicy.getName());
+ authInfo.add(new ArrayList(entries));
+ appPolicy.setAuthorizationInfo(authInfo);
+ }
+ else if("acl".equals(elementName))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ AclConfigParser parser = new AclConfigParser();
+ Set<ACLProviderEntry> entries = parser.parse(xmlEventReader);
+ ACLInfo aclInfo = new ACLInfo(appPolicy.getName());
+ aclInfo.add(new ArrayList(entries));
+ appPolicy.setAclInfo(aclInfo);
+ }
+ else if("rolemapping".equals(elementName))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ MappingConfigParser parser = new MappingConfigParser();
+ List<MappingModuleEntry> entries = parser.parse(xmlEventReader);
+ MappingInfo mappingInfo = new MappingInfo(appPolicy.getName());
+ mappingInfo.add(entries);
+ appPolicy.setMappingInfo(MappingType.ROLE.toString(), mappingInfo);
+ }
+ else if("mapping".equals(elementName))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ MappingConfigParser parser = new MappingConfigParser();
+ List<MappingModuleEntry> entries = parser.parse(xmlEventReader);
+ for(MappingModuleEntry entry: entries)
+ {
+ MappingInfo mappingInfo = new MappingInfo(appPolicy.getName());
+ mappingInfo.add(entry);
+ String moduleType = entry.getMappingModuleType();
+ appPolicy.setMappingInfo(moduleType, mappingInfo);
+ }
+ }
+ else if("audit".equals(elementName))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ AuditConfigParser parser = new AuditConfigParser();
+ List<AuditProviderEntry> entries = parser.parse(xmlEventReader);
+ AuditInfo authInfo = new AuditInfo(appPolicy.getName());
+ authInfo.add(entries);
+ appPolicy.setAuditInfo(authInfo);
+ }
+ else if("identity-trust".equals(elementName))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ IdentityTrustConfigParser parser = new IdentityTrustConfigParser();
+ List<IdentityTrustModuleEntry> entries = parser.parse(xmlEventReader);
+ IdentityTrustInfo authInfo = new IdentityTrustInfo(appPolicy.getName());
+ authInfo.add(entries);
+ appPolicy.setIdentityTrustInfo(authInfo);
+ }
+ else if("application-policy".equals(elementName))
+ break;
+ else throw new RuntimeException("Unknown " + elementName);
+ }
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuditConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,103 @@
+/*
+ * 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.config.parser;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.audit.config.AuditProviderEntry;
+
+/**
+ * Stax based audit configuration Parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class AuditConfigParser
+{
+ /**
+ * Parse the <audit> element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public List<AuditProviderEntry> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ List<AuditProviderEntry> entries = new ArrayList<AuditProviderEntry>();
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ AuditProviderEntry entry = null;
+ if("provider-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ entry = this.getEntry(xmlEventReader);
+ }
+ else
+ break;
+ entries.add(entry);
+ }
+ return entries;
+ }
+
+ @SuppressWarnings("unchecked")
+ private AuditProviderEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+
+ String codeName = null;
+
+ //We got the login-module element
+ StartElement policyModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = policyModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ }
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ AuditProviderEntry entry = new AuditProviderEntry(codeName, options);
+ return entry;
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,119 @@
+/*
+ * 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.config.parser;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+/**
+ * Stax based JAAS authentication configuration Parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class AuthenticationConfigParser
+{
+ /**
+ * Parse the <authentication> element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public Set<AppConfigurationEntry> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ Set<AppConfigurationEntry> entries = new LinkedHashSet<AppConfigurationEntry>();
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ AppConfigurationEntry entry = null;
+ if("login-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ entry = this.getEntry(xmlEventReader);
+ }
+ else
+ break;
+ entries.add(entry);
+ }
+ return entries;
+ }
+
+ @SuppressWarnings("unchecked")
+ private AppConfigurationEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+ String codeName = null;
+ LoginModuleControlFlag controlFlag = LoginModuleControlFlag.REQUIRED;
+
+ //We got the login-module element
+ StartElement loginModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = loginModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ else if("flag".equals(attQName.getLocalPart()))
+ {
+ controlFlag = getControlFlag(attribute.getValue());
+ }
+ }
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ return new AppConfigurationEntry(codeName, controlFlag, options);
+ }
+
+ private LoginModuleControlFlag getControlFlag(String flag)
+ {
+ if("required".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.REQUIRED;
+ if("sufficient".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.SUFFICIENT;
+ if("optional".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.OPTIONAL;
+ if("requisite".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.REQUISITE;
+ throw new RuntimeException(flag + " is not recognized");
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthenticationJASPIConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,187 @@
+/*
+ * 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.config.parser;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.auth.container.config.AuthModuleEntry;
+import org.jboss.security.auth.login.JASPIAuthenticationInfo;
+import org.jboss.security.auth.login.LoginModuleStackHolder;
+import org.jboss.security.config.ControlFlag;
+
+/**
+ * Stax based JASPI configuration Parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class AuthenticationJASPIConfigParser
+{
+ /**
+ * Parse the <authentication-jaspi> element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public JASPIAuthenticationInfo parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ JASPIAuthenticationInfo authInfo = new JASPIAuthenticationInfo();
+
+ LoginModuleStackHolder lmsh = null;
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ if("login-module-stack".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ StartElement lmshEvent = (StartElement) xmlEventReader.nextEvent();
+ Attribute nameAttribute = (Attribute) lmshEvent.getAttributes().next();
+ lmsh = new LoginModuleStackHolder(nameAttribute.getValue(), null);
+ authInfo.add(lmsh);
+
+ while(true)
+ {
+ //Get all the login modules
+ xmlEvent = xmlEventReader.peek();
+ peekedStartElement = (StartElement) xmlEvent;
+ if("login-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ lmsh.addAppConfigurationEntry(this.getJAASEntry(xmlEventReader) );
+ }
+ else
+ break;
+ }
+ }
+ else if("auth-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ AuthModuleEntry entry = getJaspiEntry(xmlEventReader);
+ if(lmsh != null)
+ entry.setLoginModuleStackHolder(lmsh);
+
+ authInfo.add(entry);
+ }
+ else break;
+
+ }
+ return authInfo;
+ }
+
+ @SuppressWarnings("unchecked")
+ private AppConfigurationEntry getJAASEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+
+ String codeName = null;
+ LoginModuleControlFlag controlFlag = LoginModuleControlFlag.REQUIRED;
+
+ //We got the login-module element
+ StartElement loginModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = loginModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ else if("flag".equals(attQName.getLocalPart()))
+ {
+ controlFlag = getControlFlag(attribute.getValue());
+ }
+ }
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ return new AppConfigurationEntry(codeName, controlFlag, options);
+ }
+
+ @SuppressWarnings("unchecked")
+ private AuthModuleEntry getJaspiEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+
+ String codeName = null;
+ ControlFlag flag = ControlFlag.REQUIRED;
+
+ //We got the login-module element
+ StartElement authModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = authModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ else if("flag".equals(attQName.getLocalPart()))
+ {
+ flag = ControlFlag.valueOf(attribute.getValue());
+ }
+ }
+
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ AuthModuleEntry entry = new AuthModuleEntry(codeName, options, null);
+ entry.setControlFlag(flag);
+ return entry;
+ }
+
+
+ private LoginModuleControlFlag getControlFlag(String flag)
+ {
+ if("required".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.REQUIRED;
+ if("sufficient".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.SUFFICIENT;
+ if("optional".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.OPTIONAL;
+ if("requisite".equalsIgnoreCase(flag))
+ return LoginModuleControlFlag.REQUISITE;
+ throw new RuntimeException(flag + " is not recognized");
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/AuthorizationConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,110 @@
+/*
+ * 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.config.parser;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.authorization.config.AuthorizationModuleEntry;
+import org.jboss.security.config.ControlFlag;
+
+/**
+ * Stax based authorization configuration Parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class AuthorizationConfigParser
+{
+ /**
+ * Parse the <authorization> element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public Set<AuthorizationModuleEntry> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ Set<AuthorizationModuleEntry> entries = new LinkedHashSet<AuthorizationModuleEntry>();
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ AuthorizationModuleEntry entry = null;
+ if("policy-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ entry = this.getEntry(xmlEventReader);
+ }
+ else
+ break;
+ entries.add(entry);
+ }
+ return entries;
+ }
+
+ @SuppressWarnings("unchecked")
+ private AuthorizationModuleEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+
+ String codeName = null;
+ ControlFlag controlFlag = ControlFlag.REQUIRED;
+
+ //We got the login-module element
+ StartElement policyModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = policyModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ else if("flag".equals(attQName.getLocalPart()))
+ {
+ controlFlag = ControlFlag.valueOf(attribute.getValue());
+ }
+ }
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ AuthorizationModuleEntry entry = new AuthorizationModuleEntry(codeName, options);
+ entry.setControlFlag(controlFlag);
+ return entry;
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/IdentityTrustConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,103 @@
+/*
+ * 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.config.parser;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.identitytrust.config.IdentityTrustModuleEntry;
+
+/**
+ * Stax based identity trust configuration Parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class IdentityTrustConfigParser
+{
+ /**
+ * Parse the <identity-trust> element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public List<IdentityTrustModuleEntry> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ List<IdentityTrustModuleEntry> entries = new ArrayList<IdentityTrustModuleEntry>();
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ IdentityTrustModuleEntry entry = null;
+ if("trust-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ entry = this.getEntry(xmlEventReader);
+ }
+ else
+ break;
+ entries.add(entry);
+ }
+ return entries;
+ }
+
+ @SuppressWarnings("unchecked")
+ private IdentityTrustModuleEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+
+ String codeName = null;
+
+ //We got the login-module element
+ StartElement policyModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = policyModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ }
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ IdentityTrustModuleEntry entry = new IdentityTrustModuleEntry(codeName, options);
+ return entry;
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/MappingConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,113 @@
+/*
+ * 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.config.parser;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.mapping.MappingType;
+import org.jboss.security.mapping.config.MappingModuleEntry;
+
+/**
+ * Stax based mapping configuration Parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class MappingConfigParser
+{
+ /**
+ * The mapping module by default can be ROLE type
+ * or it can be defined by the module with a 'type' attribute
+ */
+ private String typeName = MappingType.ROLE.toString();
+
+ /**
+ * Parse the <mapping> element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public List<MappingModuleEntry> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ List<MappingModuleEntry> entries = new ArrayList<MappingModuleEntry>();
+ while(xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ MappingModuleEntry entry = null;
+ if("mapping-module".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ entry = this.getEntry(xmlEventReader);
+ }
+ else
+ break;
+ entries.add(entry);
+ }
+ return entries;
+ }
+
+ @SuppressWarnings("unchecked")
+ private MappingModuleEntry getEntry(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ Map<String, Object> options = new HashMap<String,Object>();
+
+ String codeName = null;
+
+ //We got the login-module element
+ StartElement policyModuleElement = (StartElement) xmlEvent;
+ //We got the login-module element
+ Iterator<Attribute> attrs = policyModuleElement.getAttributes();
+ while(attrs.hasNext())
+ {
+ Attribute attribute = attrs.next();
+
+ QName attQName = attribute.getName();
+ if("code".equals(attQName.getLocalPart()))
+ {
+ codeName = attribute.getValue();
+
+ }
+ else if("type".equals(attQName.getLocalPart()))
+ {
+ typeName = attribute.getValue();
+
+ }
+ }
+ //See if there are options
+ ModuleOptionParser moParser = new ModuleOptionParser();
+ options.putAll(moParser.parse(xmlEventReader));
+
+ return new MappingModuleEntry(codeName, options,typeName);
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/ModuleOptionParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,69 @@
+/*
+ * 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.config.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+/**
+ * Parses the Module Option
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class ModuleOptionParser
+{
+ /**
+ * Parse the module-option element
+ * @param xmlEventReader
+ * @return
+ * @throws XMLStreamException
+ */
+ public Map<String, Object> parse(XMLEventReader xmlEventReader) throws XMLStreamException
+ {
+ Map<String, Object> options = new HashMap<String,Object>();
+
+ //See if there are options
+ while(true)
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+ if(xmlEvent instanceof EndElement) break;
+ StartElement peekedStartElement = (StartElement) xmlEvent;
+ if(xmlEvent == null)
+ break; //no module options
+ if("module-option".equals(peekedStartElement.getName().getLocalPart()))
+ {
+ xmlEvent = xmlEventReader.nextEvent();
+ Attribute attribute = (Attribute) peekedStartElement.getAttributes().next();
+ options.put(attribute.getValue(), xmlEventReader.getElementText());
+ }
+ else break;
+ }
+ return options;
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/config/parser/StaxBasedConfigParser.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,107 @@
+/*
+ * 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.config.parser;
+
+import java.io.InputStream;
+import java.util.List;
+
+import javax.xml.stream.EventFilter;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.auth.login.XMLLoginConfigImpl;
+import org.jboss.security.config.ApplicationPolicy;
+
+/**
+ * Configuration Parser based on Stax
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class StaxBasedConfigParser
+{
+ /**
+ * Whether schema validation is needed
+ */
+ protected boolean shouldValidate = true;
+
+ /**
+ * Return the flag indicating whether
+ * schema validation is enabled
+ * @return
+ */
+ public boolean isShouldValidate()
+ {
+ return shouldValidate;
+ }
+
+ /**
+ * Set the schema validation flag
+ * @param shouldValidate
+ */
+ public void setShouldValidate(boolean shouldValidate)
+ {
+ this.shouldValidate = shouldValidate;
+ }
+
+ /**
+ * Parse the Input stream of configuration
+ * @param configStream
+ * @throws XMLStreamException
+ */
+ public void parse(InputStream configStream) throws XMLStreamException
+ {
+ XMLLoginConfigImpl config = XMLLoginConfigImpl.getInstance();
+
+ XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+ XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(configStream);
+
+ xmlEventReader = xmlInputFactory.createFilteredReader(xmlEventReader, new EventFilter()
+ {
+ public boolean accept(XMLEvent xmlEvent)
+ {
+ return xmlEvent.isStartElement() ;
+ }
+ });
+
+ while (xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ int eventType = xmlEvent.getEventType();
+ switch (eventType)
+ {
+ case XMLStreamConstants.START_ELEMENT:
+ //We got the policy element. We can go over the attributes if we want
+ //But there is no immediate need.
+
+ ApplicationPolicyParser appPolicyParser = new ApplicationPolicyParser();
+ List<ApplicationPolicy> appPolicies = appPolicyParser.parse(xmlEventReader);
+ for(ApplicationPolicy appPolicy: appPolicies)
+ {
+ config.addApplicationPolicy(appPolicy.getName(), appPolicy);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Added: projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/config/StaxConfigParserUnitTestCase.java
===================================================================
--- projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/config/StaxConfigParserUnitTestCase.java (rev 0)
+++ projects/security/picketbox/fresh/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/config/StaxConfigParserUnitTestCase.java 2010-01-23 03:25:57 UTC (rev 99851)
@@ -0,0 +1,353 @@
+/*
+ * 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.config;
+
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.security.auth.login.AppConfigurationEntry;
+
+import junit.framework.Assert;
+
+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.BaseAuthenticationInfo;
+import org.jboss.security.auth.login.LoginModuleStackHolder;
+import org.jboss.security.auth.login.XMLLoginConfigImpl;
+import org.jboss.security.authorization.config.AuthorizationModuleEntry;
+import org.jboss.security.config.ACLInfo;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.config.AuditInfo;
+import org.jboss.security.config.AuthorizationInfo;
+import org.jboss.security.config.ControlFlag;
+import org.jboss.security.config.IdentityTrustInfo;
+import org.jboss.security.config.MappingInfo;
+import org.jboss.security.config.parser.StaxBasedConfigParser;
+import org.jboss.security.identitytrust.config.IdentityTrustModuleEntry;
+import org.jboss.security.mapping.MappingType;
+import org.jboss.security.mapping.config.MappingModuleEntry;
+import org.jboss.test.AbstractJBossSXTest;
+
+/**
+ * Unit test the stax based config parser
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 22, 2010
+ */
+public class StaxConfigParserUnitTestCase extends AbstractJBossSXTest
+{
+ public StaxConfigParserUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSecurityConfig5() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream is = tcl.getResourceAsStream("config/securityConfig5.xml");
+ StaxBasedConfigParser parser = new StaxBasedConfigParser();
+ parser.parse(is);
+
+ TestSecurityConfig5.validateJAASConfiguration();
+ TestSecurityConfig5.validateJASPIConfiguration();
+ TestSecurityConfig5.validateCompleteConfiguration();
+ TestSecurityConfig5.validateApplicationPolicyExtension();
+ }
+
+ public void testIdentityTrustConfig() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream is = tcl.getResourceAsStream("config/identitytrust-config.xml");
+ StaxBasedConfigParser parser = new StaxBasedConfigParser();
+ parser.parse(is);
+
+ TestIdentityTrustConfig.testConfJavaEE();
+ }
+
+ // Internal class to represent the securityConfig5.xml validation
+ private static class TestSecurityConfig5
+ {
+ public static void validateJAASConfiguration()
+ {
+ ApplicationPolicy jaasConfig = XMLLoginConfigImpl.getInstance().getApplicationPolicy("conf-jaas");
+ BaseAuthenticationInfo authInfo = jaasConfig.getAuthenticationInfo();
+ List<?> entries = authInfo.getModuleEntries();
+ assertEquals("Number of entries = 2", 2, entries.size());
+
+ // First Entry
+ Object entry = entries.get(0);
+ assertTrue("Entry instanceof AppConfigurationEntry", entry instanceof AppConfigurationEntry);
+ AppConfigurationEntry ace = (AppConfigurationEntry) entry;
+ assertEquals("LM Name", "org.jboss.test.TestLoginModule", ace.getLoginModuleName());
+ assertEquals("Required", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, ace.getControlFlag());
+ Map<String, ?> aceOptions = ace.getOptions();
+ assertEquals("Number of options = 3", 3, aceOptions.size());
+ assertEquals("name=1.1", "1.1", aceOptions.get("name"));
+ assertEquals("succeed=true", "true", aceOptions.get("succeed"));
+ assertEquals("throwEx=false", "false", aceOptions.get("throwEx"));
+
+ // Second Entry
+ entry = entries.get(1);
+ assertTrue("Entry instanceof AppConfigurationEntry", entry instanceof AppConfigurationEntry);
+ ace = (AppConfigurationEntry) entry;
+ assertEquals("LM Name", "org.jboss.test.TestLoginModule2", ace.getLoginModuleName());
+ assertEquals("Optional expected", AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, ace.getControlFlag());
+ aceOptions = ace.getOptions();
+ assertEquals("Number of options = 4", 4, aceOptions.size());
+ assertEquals("name=1.2", "1.2", aceOptions.get("name"));
+ assertEquals("succeed=false", "false", aceOptions.get("succeed"));
+ assertEquals("throwEx=true", "true", aceOptions.get("throwEx"));
+ assertEquals("dummy=d", "d", aceOptions.get("dummy"));
+
+ }
+
+ public static void validateJASPIConfiguration()
+ {
+ ApplicationPolicy jaspiConfig = XMLLoginConfigImpl.getInstance().getApplicationPolicy("conf-jaspi");
+ BaseAuthenticationInfo authInfo = jaspiConfig.getAuthenticationInfo();
+ List<?> entries = authInfo.getModuleEntries();
+ assertEquals("Number of entries = 2", 2, entries.size());
+
+ // First Entry
+ Object entry = entries.get(0);
+ assertTrue("Entry instanceof AppConfigurationEntry", entry instanceof AuthModuleEntry);
+ AuthModuleEntry ace = (AuthModuleEntry) entry;
+ assertEquals("LM Name", "TestAuthModule", ace.getAuthModuleName());
+ assertEquals("Required", ControlFlag.REQUIRED, ace.getControlFlag());
+ Map<String, ?> aceOptions = ace.getOptions();
+ assertEquals("Number of options = 3", 3, aceOptions.size());
+ assertEquals("usersProperties=u", "u", aceOptions.get("usersProperties"));
+ assertEquals("rolesProperties=r", "r", aceOptions.get("rolesProperties"));
+ assertEquals("unauthenticatedIdentity=anonymous", "anonymous", aceOptions.get("unauthenticatedIdentity"));
+
+ // Second Entry
+ entry = entries.get(1);
+ assertTrue("Entry instanceof AppConfigurationEntry", entry instanceof AuthModuleEntry);
+ ace = (AuthModuleEntry) entry;
+ assertEquals("LM Name", "TestAuthModule2", ace.getAuthModuleName());
+ assertEquals("Required", ControlFlag.REQUIRED, ace.getControlFlag());
+ aceOptions = ace.getOptions();
+ assertEquals("Number of options = 0", 0, aceOptions.size());
+ LoginModuleStackHolder lmsh = ace.getLoginModuleStackHolder();
+ assertEquals("lm-stack", "lm-stack", lmsh.getName());
+ AppConfigurationEntry[] appEntries = lmsh.getAppConfigurationEntry();
+ assertEquals("App Entries in LMSH=1", 1, appEntries.length);
+
+ Object appEntry = appEntries[0];
+ assertTrue("Entry instanceof AppConfigurationEntry", appEntry instanceof AppConfigurationEntry);
+ AppConfigurationEntry appace = (AppConfigurationEntry) appEntry;
+ assertEquals("LM Name", "org.jboss.security.auth.spi.UsersRolesLoginModule", appace.getLoginModuleName());
+ assertEquals("Optional", AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, appace.getControlFlag());
+ Map<String, ?> appaceOptions = appace.getOptions();
+ assertEquals("Number of options = 3", 3, appaceOptions.size());
+ assertEquals("usersProperties=u", "u", appaceOptions.get("usersProperties"));
+ assertEquals("rolesProperties=r", "r", appaceOptions.get("rolesProperties"));
+ assertEquals("unauthenticatedIdentity=anonymous", "anonymous", appaceOptions.get("unauthenticatedIdentity"));
+ }
+
+ public static void validateCompleteConfiguration()
+ {
+ ApplicationPolicy completeConfig = XMLLoginConfigImpl.getInstance().getApplicationPolicy("conf-complete");
+ BaseAuthenticationInfo authInfo = completeConfig.getAuthenticationInfo();
+ List<?> entries = authInfo.getModuleEntries();
+ assertEquals("Number of entries = 1", 1, entries.size());
+
+ // First Entry
+ Object entry = entries.get(0);
+ assertTrue("Entry instanceof AppConfigurationEntry", entry instanceof AppConfigurationEntry);
+ AppConfigurationEntry ace = (AppConfigurationEntry) entry;
+ assertEquals("LM Name", "org.jboss.test.TestLoginModule", ace.getLoginModuleName());
+ assertEquals("Required", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, ace.getControlFlag());
+ Map<String, ?> aceOptions = ace.getOptions();
+ assertEquals("Number of options = 3", 3, aceOptions.size());
+ assertEquals("name=1.1", "1.1", aceOptions.get("name"));
+ assertEquals("succeed=true", "true", aceOptions.get("succeed"));
+ assertEquals("throwEx=false", "false", aceOptions.get("throwEx"));
+
+ // Authorization
+ AuthorizationInfo authzInfo = completeConfig.getAuthorizationInfo();
+ assertNotNull("AuthorizationInfo is not null", authzInfo);
+ AuthorizationModuleEntry[] authzEntries = authzInfo.getAuthorizationModuleEntry();
+ assertEquals("Length of authorization entries = 1", 1, authzEntries.length);
+ AuthorizationModuleEntry authzEntry = authzEntries[0];
+ assertEquals("TestPolicyModule", "org.jboss.test.TestPolicyModule", authzEntry.getPolicyModuleName());
+ assertEquals("Required", ControlFlag.REQUIRED, authzEntry.getControlFlag());
+ Map<String, ?> authzoptions = authzEntry.getOptions();
+ assertEquals("Number of options = 2", 2, authzoptions.size());
+ assertEquals("name=authz", "authz", authzoptions.get("name"));
+ assertEquals("succeed=true", "true", authzoptions.get("succeed"));
+
+ // ACL (instance-based authorization)
+ ACLInfo aclInfo = completeConfig.getAclInfo();
+ assertNotNull("Unexpected null ACLInfo found", aclInfo);
+ ACLProviderEntry[] aclEntries = aclInfo.getACLProviderEntry();
+ assertNotNull("Unexpected null set of acl entries", aclEntries);
+ assertEquals("Invalid number of acl entries", 2, aclEntries.length);
+ // first entry should be org.jboss.security.authz.ACLModule1.
+ Assert.assertEquals("org.jboss.security.authz.ACLModule1", aclEntries[0].getAclProviderName());
+ Assert.assertEquals("REQUIRED", aclEntries[0].getControlFlag().toString());
+ Map<String, ?> options = aclEntries[0].getOptions();
+ Assert.assertNotNull("Unexpected null options map", options);
+ Assert.assertTrue("Option aclOption1 was not found", options.containsKey("aclOption1"));
+ Assert.assertEquals("value1", options.get("aclOption1"));
+ Assert.assertTrue("Option aclOption2 was not found", options.containsKey("aclOption2"));
+ Assert.assertEquals("value2", options.get("aclOption2"));
+ // second entry should be the org.jboss.security.authz.ACLModule2.
+ Assert.assertEquals("org.jboss.security.authz.ACLModule2", aclEntries[1].getAclProviderName());
+ Assert.assertEquals("REQUIRED", aclEntries[1].getControlFlag().toString());
+ options = aclEntries[1].getOptions();
+ Assert.assertNotNull("Unexpected null options map", options);
+ Assert.assertTrue("Option aclOption3 was not found", options.containsKey("aclOption3"));
+ Assert.assertEquals("value3", options.get("aclOption3"));
+ Assert.assertTrue("Option aclOption4 was not found", options.containsKey("aclOption4"));
+ Assert.assertEquals("value4", options.get("aclOption4"));
+
+ // Mapping
+ MappingInfo mappingInfo = completeConfig.getMappingInfo(MappingType.PRINCIPAL.toString());
+ 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 = completeConfig.getMappingInfo(MappingType.ROLE.toString());
+ assertNotNull("MappingInfo is not null", mappingInfo);
+ MappingModuleEntry[] mmearr = mappingInfo.getMappingModuleEntry();
+ assertEquals("Mapping entry length=1", 1, mmearr.length);
+ MappingModuleEntry mme = mmearr[0];
+ assertEquals("TestMappingModule", "org.jboss.test.TestMappingModule", mme.getMappingModuleName());
+ Map<String, ?> mmOptions = mme.getOptions();
+ assertEquals("Number of options = 2", 2, mmOptions.size());
+ assertEquals("name=rolemap", "rolemap", mmOptions.get("name"));
+ assertEquals("succeed=true", "true", mmOptions.get("succeed"));
+
+ // Audit
+ AuditInfo ai = completeConfig.getAuditInfo();
+ assertNotNull("AuditInfo", ai);
+ AuditProviderEntry[] apelist = ai.getAuditProviderEntry();
+ assertEquals("Audit entry length=1", 1, apelist.length);
+ AuditProviderEntry ape = apelist[0];
+ assertEquals("TestMappingModule", "org.jboss.test.TestMappingModule", mme.getMappingModuleName());
+ Map<String, ?> auditOptions = ape.getOptions();
+ assertEquals("Number of options = 2", 2, auditOptions.size());
+ assertEquals("name=auditprovider", "auditprovider", auditOptions.get("name"));
+ assertEquals("succeed=false", "false", auditOptions.get("succeed"));
+
+ // Identity Trust
+ IdentityTrustInfo iti = completeConfig.getIdentityTrustInfo();
+ assertNotNull("IdentityTrustInfo", iti);
+ IdentityTrustModuleEntry[] itilist = iti.getIdentityTrustModuleEntry();
+ assertEquals("IdentityTrustModuleEntry length=1", 1, itilist.length);
+ IdentityTrustModuleEntry itie = itilist[0];
+ assertEquals("TestMappingModule", "org.jboss.test.TestMappingModule", mme.getMappingModuleName());
+ Map<String, ?> itieOptions = itie.getOptions();
+ assertEquals("Number of options = 3", 3, itieOptions.size());
+ assertEquals("name=trustprovider", "trustprovider", itieOptions.get("name"));
+ assertEquals("succeed=true", "true", itieOptions.get("succeed"));
+ assertEquals("dummy=dr", "dr", itieOptions.get("dummy"));
+ }
+
+ public static void validateApplicationPolicyExtension()
+ {
+ ApplicationPolicy completeConfig = XMLLoginConfigImpl.getInstance().getApplicationPolicy("conf-jaas-extend");
+ assertNotNull("conf-jaas-extend is not null", completeConfig);
+ BaseAuthenticationInfo bai = completeConfig.getAuthenticationInfo();
+ assertNotNull("BaseAuthenticationInfo is not null", bai);
+ assertEquals("3 login modules", 3, bai.getModuleEntries().size());
+
+ // Authorization
+ AuthorizationInfo azi = completeConfig.getAuthorizationInfo();
+ assertNotNull("AuthorizationInfo is not null", azi);
+ assertEquals("3 authz modules", 3, azi.getModuleEntries().size());
+
+ // ACL
+ ACLInfo aclInfo = completeConfig.getAclInfo();
+ assertNotNull("Unexpected null ACLInfo", aclInfo);
+ assertEquals("Unexpected number of acl modules", 3, aclInfo.getModuleEntries().size());
+
+ // Role Mapping
+ MappingInfo mappingInfo = completeConfig.getMappingInfo(MappingType.ROLE.toString());
+ assertNotNull("MappingInfo is not null", mappingInfo);
+ // 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(MappingType.PRINCIPAL.toString());
+ 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());
+ // same test as above: we expect 2 role-mapping modules: 1 from rolemapping and 1 from mapping with type "role".
+ mappingInfo = completeConfig.getMappingInfo(MappingType.ROLE.toString());
+ assertNotNull("MappingInfo is not null", mappingInfo);
+ mappingEntries = mappingInfo.getMappingModuleEntry();
+ 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();
+ assertNotNull("AuditInfo", ai);
+ AuditProviderEntry[] apelist = ai.getAuditProviderEntry();
+ assertEquals("Audit entry length=1", 1, apelist.length);
+
+ // Identity Trust
+ IdentityTrustInfo iti = completeConfig.getIdentityTrustInfo();
+ assertNotNull("IdentityTrustInfo", iti);
+ IdentityTrustModuleEntry[] itilist = iti.getIdentityTrustModuleEntry();
+ assertEquals("IdentityTrustModuleEntry length=1", 1, itilist.length);
+
+ // JASPI authentication policy extension
+ ApplicationPolicy jaspiPolicy = XMLLoginConfigImpl.getInstance().getApplicationPolicy("conf-jaspi-extend");
+ assertNotNull("Unexpected null conf-jaspi-extend application policy", jaspiPolicy);
+ BaseAuthenticationInfo authInfo = jaspiPolicy.getAuthenticationInfo();
+ assertNotNull("Unexpected null jaspi configuration", authInfo);
+ List<?> entries = authInfo.getModuleEntries();
+ assertEquals("Invalid number of auth modules", 3, entries.size());
+ }
+ } //End class TestSecurityConfig5
+
+
+ //Validate the identitytrust-config.xml
+ private static class TestIdentityTrustConfig
+ {
+ public static void testConfJavaEE()
+ {
+ ApplicationPolicy javaeeConfig = XMLLoginConfigImpl.getInstance().getApplicationPolicy("conf-javaee");
+ IdentityTrustInfo identityTrust = javaeeConfig.getIdentityTrustInfo();
+ assertNotNull("IdentityTrustInfo", identityTrust);
+
+ IdentityTrustModuleEntry[] itilist = identityTrust.getIdentityTrustModuleEntry();
+ assertEquals("IdentityTrustModuleEntry length=1", 1, itilist.length);
+
+ IdentityTrustModuleEntry itme = itilist[0];
+ assertEquals("org.jboss.security.identitytrust.modules.JavaEETrustModule", itme.getName());
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list