Author: anil.saldhana(a)jboss.com
Date: 2011-03-15 12:32:05 -0400 (Tue, 15 Mar 2011)
New Revision: 810
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/constants/AttributeConstants.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/X500SAMLProfileConstants.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/StatementUtil.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/saml/v2/X500AttributeUnitTestCase.java
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java
Log:
fix the x500 attribute handling
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/constants/AttributeConstants.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/constants/AttributeConstants.java 2011-03-15
15:51:49 UTC (rev 809)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/constants/AttributeConstants.java 2011-03-15
16:32:05 UTC (rev 810)
@@ -28,18 +28,5 @@
*/
public interface AttributeConstants
{
- String COUNTRY = "country";
- String EMAIL_ADDRESS = "email";
- String EMPLOYEE_TYPE = "employeeType";
- String EMPLOYEE_NUMBER = "employeeNumber";
- String GIVEN_NAME = "givenName";
- String PREFERRED_LANGUAGE = "preferredLanguage";
- String PO_BOX = "postOfficeBox";
- String POSTAL_CODE = "postalCode";
- String POSTAL_ADDRESS ="postalAddress";
- String SURNAME = "surname";
- String STREET = "street";
- String TITLE = "title";
- String TELEPHONE = "telephoneNumber";
String ROLES = "roles";
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/X500SAMLProfileConstants.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/X500SAMLProfileConstants.java 2011-03-15
15:51:49 UTC (rev 809)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/X500SAMLProfileConstants.java 2011-03-15
16:32:05 UTC (rev 810)
@@ -21,6 +21,10 @@
*/
package org.picketlink.identity.federation.core.saml.v2.constants;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* X500 SAML Profile Constants
* Adapted from
http://code.google.com/p/simplesamlphp/source/browse/trunk/attributemap/n...
@@ -190,13 +194,21 @@
X121_ADDRESS("x121Address" , "urn:oid:2.5.4.24"),
X500_UNIQUE_IDENTIFIER("x500UniqueIdentifier" ,
"urn:oid:2.5.4.45");
- private final String friendlyName = null;
+ private String friendlyName = null;
private String uri = null;
+ private static final Map<String,String> lookup = new
HashMap<String,String>();
+
+ static {
+ for(X500SAMLProfileConstants s : EnumSet.allOf(X500SAMLProfileConstants.class))
+ lookup.put(s.friendlyName, s.uri);
+ }
+
private X500SAMLProfileConstants(String friendlyName,
String uristr)
{
- this.uri = uristr;
+ this.uri = uristr;
+ this.friendlyName = friendlyName;
}
public String get()
@@ -208,4 +220,9 @@
{
return friendlyName;
}
+
+ public static String getOID( final String key)
+ {
+ return lookup.get(key);
+ }
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/StatementUtil.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/StatementUtil.java 2011-03-15
15:51:49 UTC (rev 809)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/StatementUtil.java 2011-03-15
16:32:05 UTC (rev 810)
@@ -33,6 +33,7 @@
import org.picketlink.identity.federation.core.constants.AttributeConstants;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import
org.picketlink.identity.federation.core.saml.v2.constants.X500SAMLProfileConstants;
+import org.picketlink.identity.federation.core.util.StringUtil;
import
org.picketlink.identity.federation.newmodel.saml.v2.assertion.AttributeStatementType;
import
org.picketlink.identity.federation.newmodel.saml.v2.assertion.AttributeStatementType.ASTChoiceType;
import org.picketlink.identity.federation.newmodel.saml.v2.assertion.AttributeType;
@@ -116,27 +117,12 @@
AttributeType att;
Object value = attributes.get(key);
- if (AttributeConstants.EMAIL_ADDRESS.equals(key))
+ String uri = X500SAMLProfileConstants.getOID(key);
+ if (StringUtil.isNotNull(uri))
{
- att = getX500Attribute(X500SAMLProfileConstants.EMAIL_ADDRESS.get());
-
att.setFriendlyName(X500SAMLProfileConstants.EMAIL_ADDRESS.getFriendlyName());
+ att = getX500Attribute(uri);
+ att.setFriendlyName(key);
}
- else if (AttributeConstants.EMPLOYEE_NUMBER.equals(key))
- {
- att = getX500Attribute(X500SAMLProfileConstants.EMPLOYEE_NUMBER.get());
-
att.setFriendlyName(X500SAMLProfileConstants.EMPLOYEE_NUMBER.getFriendlyName());
- }
- else if (AttributeConstants.GIVEN_NAME.equals(key))
- {
- att = getX500Attribute(X500SAMLProfileConstants.GIVEN_NAME.get());
-
att.setFriendlyName(X500SAMLProfileConstants.GIVEN_NAME.getFriendlyName());
- }
- else if (AttributeConstants.TELEPHONE.equals(key))
- {
- att = getX500Attribute(X500SAMLProfileConstants.TELEPHONE_NUMBER.get());
-
att.setFriendlyName(X500SAMLProfileConstants.TELEPHONE_NUMBER.getFriendlyName());
- att.setName(X500SAMLProfileConstants.TELEPHONE_NUMBER.get());
- }
else
throw new RuntimeException("Unknown:" + key);
Modified:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/saml/v2/X500AttributeUnitTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/saml/v2/X500AttributeUnitTestCase.java 2011-03-15
15:51:49 UTC (rev 809)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/saml/v2/X500AttributeUnitTestCase.java 2011-03-15
16:32:05 UTC (rev 810)
@@ -27,9 +27,9 @@
import junit.framework.TestCase;
-import org.picketlink.identity.federation.core.constants.AttributeConstants;
import org.picketlink.identity.federation.core.saml.v2.common.IDGenerator;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
+import
org.picketlink.identity.federation.core.saml.v2.constants.X500SAMLProfileConstants;
import
org.picketlink.identity.federation.core.saml.v2.factories.JBossSAMLAuthnResponseFactory;
import org.picketlink.identity.federation.core.saml.v2.holders.IDPInfoHolder;
import org.picketlink.identity.federation.core.saml.v2.holders.IssuerInfoHolder;
@@ -55,53 +55,50 @@
{
public void testX500Marshalling() throws Exception
{
- Map<String,Object> attributes = new HashMap<String, Object>();
- attributes.put(AttributeConstants.EMAIL_ADDRESS, "test@a");
- attributes.put(AttributeConstants.GIVEN_NAME, "anil");
-
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(X500SAMLProfileConstants.EMAIL_ADDRESS.getFriendlyName(),
"test@a");
+ attributes.put(X500SAMLProfileConstants.GIVEN_NAME.getFriendlyName(),
"anil");
+
AttributeStatementType attrStat =
StatementUtil.createAttributeStatement(attributes);
-
+
IssuerInfoHolder issuerHolder = new IssuerInfoHolder("http://idp");
issuerHolder.setStatusCode(JBossSAMLURIConstants.STATUS_SUCCESS.get());
-
+
IDPInfoHolder idp = new IDPInfoHolder();
idp.setNameIDFormatValue(IDGenerator.create());
-
- ResponseType rt =
JBossSAMLAuthnResponseFactory.createResponseType("response111",
- new SPInfoHolder(), idp, issuerHolder);
+
+ ResponseType rt =
JBossSAMLAuthnResponseFactory.createResponseType("response111", new
SPInfoHolder(), idp,
+ issuerHolder);
assertNotNull(rt);
-
- AssertionType assertion = (AssertionType)
rt.getAssertions().get(0).getAssertion();
- assertion.addStatement( attrStat );
-
+
+ AssertionType assertion = rt.getAssertions().get(0).getAssertion();
+ assertion.addStatement(attrStat);
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- SAMLResponseWriter writer = new SAMLResponseWriter(
StaxUtil.getXMLStreamWriter(baos) );
+
+ SAMLResponseWriter writer = new
SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(rt);
-
+
/*Marshaller marshaller =
JBossSAMLAuthnResponseFactory.getValidatingMarshaller(false);
JAXBElement<ResponseType> jaxb =
SAMLProtocolFactory.getObjectFactory().createResponse(rt);
marshaller.marshal(jaxb, baos);
*///marshaller.marshal(jaxb, System.out);
-
+
Document samlDom = DocumentUtil.getDocument(new String(baos.toByteArray()));
- System.out.println( DocumentUtil.getDocumentAsString(samlDom));
-
- NodeList nl =
samlDom.getElementsByTagNameNS(JBossSAMLURIConstants.ASSERTION_NSURI.get()
,"Attribute");
+ System.out.println(DocumentUtil.getDocumentAsString(samlDom));
+
+ NodeList nl =
samlDom.getElementsByTagNameNS(JBossSAMLURIConstants.ASSERTION_NSURI.get(),
"Attribute");
assertEquals("nodes = 2", 2, nl.getLength());
-
+
String x500NS = JBossSAMLURIConstants.X500_NSURI.get();
String encodingLocalName = "Encoding";
-
+
Element attrib = (Element) nl.item(0);
- assertTrue("Has ldap encoding?", attrib.hasAttributeNS( x500NS,
encodingLocalName));
- assertEquals("LDAP",
- attrib.getAttributeNodeNS(x500NS, encodingLocalName).getNodeValue());
-
- NodeList nla =
- attrib.getElementsByTagNameNS(JBossSAMLURIConstants.ASSERTION_NSURI.get(),
- "AttributeValue");
-
+ assertTrue("Has ldap encoding?", attrib.hasAttributeNS(x500NS,
encodingLocalName));
+ assertEquals("LDAP", attrib.getAttributeNodeNS(x500NS,
encodingLocalName).getNodeValue());
+
+ NodeList nla =
attrib.getElementsByTagNameNS(JBossSAMLURIConstants.ASSERTION_NSURI.get(),
"AttributeValue");
+
Node attribNode = nla.item(0);
String nodeValue = attribNode.getTextContent();
assertTrue(nodeValue.equals("test@a") ||
nodeValue.equals("anil"));
Modified:
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java
===================================================================
---
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java 2011-03-15
15:51:49 UTC (rev 809)
+++
federation/trunk/picketlink-web/src/test/java/org/picketlink/test/identity/federation/web/saml/handlers/SAML2AttributeHandlerUnitTestCase.java 2011-03-15
16:32:05 UTC (rev 810)
@@ -29,9 +29,9 @@
import junit.framework.TestCase;
import org.picketlink.identity.federation.core.config.IDPType;
-import org.picketlink.identity.federation.core.constants.AttributeConstants;
import org.picketlink.identity.federation.core.interfaces.AttributeManager;
import org.picketlink.identity.federation.core.saml.v2.common.SAMLDocumentHolder;
+import
org.picketlink.identity.federation.core.saml.v2.constants.X500SAMLProfileConstants;
import org.picketlink.identity.federation.core.saml.v2.holders.IssuerInfoHolder;
import
org.picketlink.identity.federation.core.saml.v2.impl.DefaultSAML2HandlerChainConfig;
import org.picketlink.identity.federation.core.saml.v2.impl.DefaultSAML2HandlerConfig;
@@ -59,66 +59,69 @@
public class SAML2AttributeHandlerUnitTestCase extends TestCase
{
private static String name = "anil";
+
private static String email = "anil@test";
-
+
@SuppressWarnings("unchecked")
public void testAttributes() throws Exception
{
SAML2AttributeHandler handler = new SAML2AttributeHandler();
-
+
SAML2HandlerChainConfig chainConfig = new DefaultSAML2HandlerChainConfig();
SAML2HandlerConfig handlerConfig = new DefaultSAML2HandlerConfig();
-
- Map<String,Object> chainOptions = new HashMap<String, Object>();
+
+ Map<String, Object> chainOptions = new HashMap<String, Object>();
IDPType idpType = new IDPType();
idpType.setAttributeManager(TestAttributeManager.class.getName());
chainOptions.put(GeneralConstants.CONFIGURATION, idpType);
chainConfig.set(chainOptions);
-
-
+
//Initialize the handler
handler.initChainConfig(chainConfig);
handler.initHandlerConfig(handlerConfig);
-
+
//Create a Protocol Context
MockHttpSession session = new MockHttpSession();
MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest servletRequest = new MockHttpServletRequest(session,
"POST");
MockHttpServletResponse servletResponse = new MockHttpServletResponse();
HTTPContext httpContext = new HTTPContext(servletRequest, servletResponse,
servletContext);
-
- SAML2Object saml2Object = new SAML2Object(){};
-
+
+ SAML2Object saml2Object = new SAML2Object()
+ {
+ };
+
SAMLDocumentHolder docHolder = new SAMLDocumentHolder(saml2Object, null);
IssuerInfoHolder issuerInfo = new
IssuerInfoHolder("http://localhost:8080/idp/");
- SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext,
- issuerInfo.getIssuer(), docHolder, SAML2Handler.HANDLER_TYPE.IDP);
+ SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext,
issuerInfo.getIssuer(), docHolder,
+ SAML2Handler.HANDLER_TYPE.IDP);
SAML2HandlerResponse response = new DefaultSAML2HandlerResponse();
-
+
session.setAttribute(GeneralConstants.PRINCIPAL_ID, new Principal()
{
public String getName()
{
return name;
- }});
- handler.handleRequestType(request, response);
-
+ }
+ });
+ handler.handleRequestType(request, response);
+
Map<String, Object> attribs = (Map<String, Object>)
session.getAttribute(GeneralConstants.ATTRIBUTES);
assertNotNull("Attributes are not null", attribs);
- assertEquals(email,attribs.get(AttributeConstants.EMAIL_ADDRESS));
+ assertEquals(email,
attribs.get(X500SAMLProfileConstants.EMAIL.getFriendlyName()));
}
-
+
public static class TestAttributeManager implements AttributeManager
- {
+ {
public Map<String, Object> getAttributes(Principal userPrincipal,
List<String> attributeKeys)
{
- Map<String,Object> attribs = new HashMap<String, Object>();
-
- if(name.equals(userPrincipal.getName()))
+ Map<String, Object> attribs = new HashMap<String, Object>();
+
+ if (name.equals(userPrincipal.getName()))
{
- attribs.put(AttributeConstants.EMAIL_ADDRESS, email);
+ attribs.put(X500SAMLProfileConstants.EMAIL.getFriendlyName(), email);
}
return attribs;
- }
+ }
}
}
\ No newline at end of file