Author: anil.saldhana(a)jboss.com
Date: 2010-11-04 17:47:35 -0400 (Thu, 04 Nov 2010)
New Revision: 534
Modified:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java
Log:
take care of x500 attributes
Modified:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-11-04
21:33:08 UTC (rev 533)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-11-04
21:47:35 UTC (rev 534)
@@ -39,8 +39,10 @@
import org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
import org.picketlink.identity.federation.saml.v2.assertion.AudienceRestrictionType;
+import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.StatementAbstractType;
import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationDataType;
import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationType;
import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
@@ -57,46 +59,44 @@
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-assertion.xml" );
-
+
SAMLParser parser = new SAMLParser();
AssertionType assertion = (AssertionType) parser.parse(configStream);
assertNotNull( assertion );
-
+
assertEquals( "ID_ab0392ef-b557-4453-95a8-a7e168da8ac5",
assertion.getID() );
assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.869Z" ),
assertion.getIssueInstant() );
//Issuer
assertEquals( "Test STS", assertion.getIssuer().getValue() );
-
+
//Subject
SubjectType subject = assertion.getSubject();
List<JAXBElement<?>> content = subject.getContent();
-
+
int size = content.size();
-
+
for( int i = 0 ; i < size; i++ )
{
JAXBElement<?> node = content.get(i);
if( node.getDeclaredType().equals( NameIDType.class ))
{
NameIDType subjectNameID = (NameIDType) node.getValue();
-
+
assertEquals( "jduke", subjectNameID.getValue() );
assertEquals( "urn:picketlink:identity-federation",
subjectNameID.getNameQualifier() );
}
-
+
if( node.getDeclaredType().equals( ConditionsType.class ))
- {
-
+ {
//Conditions
ConditionsType conditions = (ConditionsType) node.getValue();
assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.869Z" ) ,
conditions.getNotBefore() );
- assertEquals( XMLTimeUtil.parse( "2010-09-30T21:13:37.869Z" ) ,
conditions.getNotOnOrAfter() );
-
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T21:13:37.869Z" ) ,
conditions.getNotOnOrAfter() );
}
}
}
-
-
+
+
/**
* This test validates the parsing of audience restrictions inside the conditions
* @throws Exception
@@ -106,35 +106,35 @@
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-assertion-audiencerestriction.xml" );
-
+
SAMLParser parser = new SAMLParser();
AssertionType assertion = (AssertionType) parser.parse(configStream);
assertNotNull( assertion );
-
+
assertEquals( "ID_cf9efbf0-9d7f-4b4a-b77f-d83ecaafd374",
assertion.getID() );
assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.911Z" ),
assertion.getIssueInstant() );
assertEquals( "2.0", assertion.getVersion() );
-
+
//Issuer
assertEquals( "Test STS", assertion.getIssuer().getValue() );
-
+
//Subject
SubjectType subject = assertion.getSubject();
List<JAXBElement<?>> content = subject.getContent();
-
+
int size = content.size();
-
+
for( int i = 0 ; i < size; i++ )
{
JAXBElement<?> node = content.get(i);
if( node.getDeclaredType().equals( NameIDType.class ))
{
NameIDType subjectNameID = (NameIDType) node.getValue();
-
+
assertEquals( "jduke", subjectNameID.getValue() );
assertEquals( "urn:picketlink:identity-federation",
subjectNameID.getNameQualifier() );
}
-
+
if( node.getDeclaredType().equals( ConditionsType.class ))
{
//Conditions
@@ -150,31 +150,61 @@
}
}
}
-
-
+
+
@Test
public void testAssertionWithX500Attribute() throws Exception
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-assertion-x500attrib.xml" );
-
+
SAMLParser parser = new SAMLParser();
AssertionType assertion = (AssertionType) parser.parse(configStream);
assertNotNull( assertion );
-
+
assertEquals( "ID_b07b804c-7c29-ea16-7300-4f3d6f7928ac",
assertion.getID() );
assertEquals( XMLTimeUtil.parse( "2004-12-05T09:22:05Z" ),
assertion.getIssueInstant() );
assertEquals( "2.0", assertion.getVersion() );
-
+
//Issuer
assertEquals( "https://idp.example.org/SAML2",
assertion.getIssuer().getValue() );
-
+
+ List<StatementAbstractType> statements =
assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement();
+ assertEquals( 2, statements.size() );
+
+ AuthnStatementType authnStatement = (AuthnStatementType) statements.get(0);
+ assertEquals( XMLTimeUtil.parse( "2004-12-05T09:22:00Z" ),
authnStatement.getAuthnInstant() );
+ assertEquals( "b07b804c-7c29-ea16-7300-4f3d6f7928ac",
authnStatement.getSessionIndex() );
+
+
+ AttributeStatementType attributeStatement = (AttributeStatementType)
statements.get( 1 );
+ List<Object> attributes =
attributeStatement.getAttributeOrEncryptedAttribute();
+ assertEquals( 1, attributes.size() );
+ AttributeType attribute = (AttributeType) attributes.get(0);
+ assertEquals( "eduPersonAffiliation", attribute.getFriendlyName() );
+ assertEquals( "urn:oid:1.3.6.1.4.1.5923.1.1.1.1", attribute.getName() );
+ assertEquals( "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
attribute.getNameFormat() );
+
+ //Ensure that we have x500:encoding
+ QName x500EncodingName = new QName( JBossSAMLURIConstants.X500_NSURI.get(),
+ JBossSAMLConstants.ENCODING.get() );
+ String encodingValue = attribute.getOtherAttributes().get( x500EncodingName );
+ assertEquals( "LDAP", encodingValue );
+
+ List<Object> attributeValues = attribute.getAttributeValue();
+ assertEquals( 2, attributeValues.size() );
+
+ String str = (String ) attributeValues.get( 0 );
+ if( ! ( str.equals( "member") || str.equals( "staff" )))
+ throw new RuntimeException( "attrib value not found" );
+
//Subject
SubjectType subject = assertion.getSubject();
List<JAXBElement<?>> content = subject.getContent();
-
+
int size = content.size();
-
+ assertEquals( 2, size );
+
for( int i = 0 ; i < size; i++ )
{
JAXBElement<?> node = content.get(i);
@@ -182,11 +212,11 @@
if( clazz.equals( NameIDType.class ))
{
NameIDType subjectNameID = (NameIDType) node.getValue();
-
+
assertEquals( "3f7b3dcf-1674-4ecd-92c8-1544f346baf8",
subjectNameID.getValue() );
assertEquals(
"urn:oasis:names:tc:SAML:2.0:nameid-format:transient", subjectNameID.getFormat()
);
}
-
+
if( clazz.equals( ConditionsType.class ))
{
//Conditions
@@ -200,45 +230,17 @@
assertEquals( 1, audienceRestrictionType.getAudience().size() );
assertEquals( "https://sp.example.com/SAML2",
audienceRestrictionType.getAudience().get( 0 ));
}
-
+
else if( clazz.equals( SubjectConfirmationType.class ))
{
SubjectConfirmationType subjectConfirmation = (SubjectConfirmationType)
node.getValue();
assertEquals( "urn:oasis:names:tc:SAML:2.0:cm:bearer",
subjectConfirmation.getMethod() );
-
+
SubjectConfirmationDataType subjectConfirmationData =
subjectConfirmation.getSubjectConfirmationData();
assertEquals( "ID_aaf23196-1773-2113-474a-fe114412ab72",
subjectConfirmationData.getInResponseTo() );
assertEquals( XMLTimeUtil.parse( "2004-12-05T09:27:05Z" ),
subjectConfirmationData.getNotOnOrAfter() );
assertEquals( "https://sp.example.com/SAML2/SSO/POST",
subjectConfirmationData.getRecipient());
}
-
- else if( clazz.equals( AttributeStatementType.class ))
- {
- AttributeStatementType attributeStatement = (AttributeStatementType)
node.getValue();
- List<Object> attributes =
attributeStatement.getAttributeOrEncryptedAttribute();
- assertEquals( 2, attributes.size() );
-
- for( Object attr: attributes )
- {
- AttributeType attribute = (AttributeType) attr;
- assertEquals( "eduPersonAffiliation",
attribute.getFriendlyName() );
- assertEquals( "urn:oid:1.3.6.1.4.1.5923.1.1.1.1",
attribute.getName() );
- assertEquals( "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
attribute.getNameFormat() );
-
- //Ensure that we have x500:encoding
- QName x500EncodingName = new QName(
JBossSAMLURIConstants.X500_NSURI.get(),
- JBossSAMLConstants.ENCODING.get() );
- String encodingValue = attribute.getOtherAttributes().get(
x500EncodingName );
- assertEquals( "LDAP", encodingValue );
-
- List<Object> attributeValues = attribute.getAttributeValue();
- assertEquals( 1, attributeValues.size() );
-
- String str = (String ) attributeValues.get( 0 );
- if( ! ( str.equals( "member") || str.equals( "staff"
)))
- throw new RuntimeException( "attrib value not found" );
- }
- }
}
}
}
\ No newline at end of file