Author: anil.saldhana(a)jboss.com
Date: 2011-03-01 14:35:51 -0500 (Tue, 01 Mar 2011)
New Revision: 787
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-response.xml
Log:
PLFED-152: consider SubjectLocality
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java 2011-03-01
19:10:15 UTC (rev 786)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java 2011-03-01
19:35:51 UTC (rev 787)
@@ -37,7 +37,7 @@
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
-import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
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;
@@ -47,6 +47,7 @@
import org.picketlink.identity.federation.newmodel.saml.v2.assertion.AuthnContextType;
import org.picketlink.identity.federation.newmodel.saml.v2.assertion.AuthnStatementType;
import org.picketlink.identity.federation.newmodel.saml.v2.assertion.NameIDType;
+import
org.picketlink.identity.federation.newmodel.saml.v2.assertion.SubjectLocalityType;
/**
* Utility methods for SAML Parser
@@ -61,55 +62,55 @@
* @return
* @throws ParsingException
*/
- public static AttributeStatementType parseAttributeStatement( XMLEventReader
xmlEventReader ) throws ParsingException
+ public static AttributeStatementType parseAttributeStatement(XMLEventReader
xmlEventReader) throws ParsingException
{
AttributeStatementType attributeStatementType = new AttributeStatementType();
-
+
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
String ATTRIBSTATEMT = JBossSAMLConstants.ATTRIBUTE_STATEMENT.get();
- StaxParserUtil.validate( startElement, ATTRIBSTATEMT );
-
- while( xmlEventReader.hasNext() )
+ StaxParserUtil.validate(startElement, ATTRIBSTATEMT);
+
+ while (xmlEventReader.hasNext())
{
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
- if( xmlEvent instanceof EndElement )
+ if (xmlEvent instanceof EndElement)
{
EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement,
JBossSAMLConstants.ATTRIBUTE_STATEMENT.get() );
+ StaxParserUtil.validate(endElement,
JBossSAMLConstants.ATTRIBUTE_STATEMENT.get());
break;
}
//Get the next start element
- startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
String tag = startElement.getName().getLocalPart();
- if( JBossSAMLConstants.ATTRIBUTE.get().equals( tag ) )
+ if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag))
{
AttributeType attribute = parseAttribute(xmlEventReader);
- attributeStatementType.addAttribute( new ASTChoiceType( attribute ));
+ attributeStatementType.addAttribute(new ASTChoiceType(attribute));
}
- else throw new RuntimeException( "Unknown tag:" + tag +
"::Location=" + startElement.getLocation() );
- }
+ else
+ throw new RuntimeException("Unknown tag:" + tag +
"::Location=" + startElement.getLocation());
+ }
return attributeStatementType;
}
-
+
/**
* Parse an {@code AttributeType}
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static AttributeType parseAttribute( XMLEventReader xmlEventReader ) throws
ParsingException
- {
- StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- StaxParserUtil.validate( startElement, JBossSAMLConstants.ATTRIBUTE.get() );
+ public static AttributeType parseAttribute(XMLEventReader xmlEventReader) throws
ParsingException
+ {
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE.get());
AttributeType attributeType = null;
-
- Attribute name = startElement.getAttributeByName( new QName(
JBossSAMLConstants.NAME.get() ));
- if( name == null )
- throw new RuntimeException( "Required attribute Name in Attribute" );
- attributeType = new AttributeType( StaxParserUtil.getAttributeValue( name ));
-
+
+ Attribute name = startElement.getAttributeByName(new
QName(JBossSAMLConstants.NAME.get()));
+ if (name == null)
+ throw new RuntimeException("Required attribute Name in Attribute");
+ attributeType = new AttributeType(StaxParserUtil.getAttributeValue(name));
+
parseAttributeType(xmlEventReader, startElement,
JBossSAMLConstants.ATTRIBUTE.get(), attributeType);
-
/*//Look for X500 Encoding
QName x500EncodingName = new QName( JBossSAMLURIConstants.X500_NSURI.get(),
@@ -154,229 +155,277 @@
}
else throw new RuntimeException( "Unknown tag:" + tag );
}*/
-
- return attributeType;
+
+ return attributeType;
}
-
+
/**
* Parse an {@code AttributeType}
* @param xmlEventReader
* @throws ParsingException
*/
- public static void parseAttributeType( XMLEventReader xmlEventReader,
- StartElement startElement, String rootTag, AttributeType attributeType ) throws
ParsingException
- {
+ public static void parseAttributeType(XMLEventReader xmlEventReader, StartElement
startElement, String rootTag,
+ AttributeType attributeType) throws ParsingException
+ {
//Look for X500 Encoding
- QName x500EncodingName = new QName( JBossSAMLURIConstants.X500_NSURI.get(),
- JBossSAMLConstants.ENCODING.get(), JBossSAMLURIConstants.X500_PREFIX.get()
);
- Attribute x500EncodingAttr = startElement.getAttributeByName( x500EncodingName );
-
- if( x500EncodingAttr != null )
- {
- attributeType.getOtherAttributes().put( x500EncodingAttr.getName(),
StaxParserUtil.getAttributeValue( x500EncodingAttr ));
- }
-
- Attribute friendlyName = startElement.getAttributeByName( new QName(
JBossSAMLConstants.FRIENDLY_NAME.get() ));
- if( friendlyName != null )
- attributeType.setFriendlyName( StaxParserUtil.getAttributeValue( friendlyName
));
-
- Attribute nameFormat = startElement.getAttributeByName( new QName(
JBossSAMLConstants.NAME_FORMAT.get() ));
- if( nameFormat != null )
- attributeType.setNameFormat( StaxParserUtil.getAttributeValue( nameFormat ));
-
- while( xmlEventReader.hasNext() )
+ QName x500EncodingName = new QName(JBossSAMLURIConstants.X500_NSURI.get(),
JBossSAMLConstants.ENCODING.get(),
+ JBossSAMLURIConstants.X500_PREFIX.get());
+ Attribute x500EncodingAttr = startElement.getAttributeByName(x500EncodingName);
+
+ if (x500EncodingAttr != null)
{
+ attributeType.getOtherAttributes().put(x500EncodingAttr.getName(),
+ StaxParserUtil.getAttributeValue(x500EncodingAttr));
+ }
+
+ Attribute friendlyName = startElement.getAttributeByName(new
QName(JBossSAMLConstants.FRIENDLY_NAME.get()));
+ if (friendlyName != null)
+ attributeType.setFriendlyName(StaxParserUtil.getAttributeValue(friendlyName));
+
+ Attribute nameFormat = startElement.getAttributeByName(new
QName(JBossSAMLConstants.NAME_FORMAT.get()));
+ if (nameFormat != null)
+ attributeType.setNameFormat(StaxParserUtil.getAttributeValue(nameFormat));
+
+ while (xmlEventReader.hasNext())
+ {
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
- if( xmlEvent instanceof EndElement )
+ if (xmlEvent instanceof EndElement)
{
EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader);
- if( StaxParserUtil.matches( end, rootTag ))
+ if (StaxParserUtil.matches(end, rootTag))
break;
}
startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
- if( startElement == null )
+ if (startElement == null)
break;
String tag = StaxParserUtil.getStartElementName(startElement);
-
- if( JBossSAMLConstants.ATTRIBUTE.get().equals( tag ))
+
+ if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag))
break;
-
- if( JBossSAMLConstants.ATTRIBUTE_VALUE.get().equals( tag ) )
+
+ if (JBossSAMLConstants.ATTRIBUTE_VALUE.get().equals(tag))
{
Object attributeValue = parseAttributeValue(xmlEventReader);
- attributeType.addAttributeValue( attributeValue );
+ attributeType.addAttributeValue(attributeValue);
}
- else throw new RuntimeException( "Unknown tag:" + tag +
"::Location=" + startElement.getLocation() );
+ else
+ throw new RuntimeException("Unknown tag:" + tag +
"::Location=" + startElement.getLocation());
}
}
-
+
/**
* Parse Attribute value
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static Object parseAttributeValue( XMLEventReader xmlEventReader ) throws
ParsingException
+ public static Object parseAttributeValue(XMLEventReader xmlEventReader) throws
ParsingException
{
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- StaxParserUtil.validate( startElement, JBossSAMLConstants.ATTRIBUTE_VALUE.get() );
-
- Attribute type = startElement.getAttributeByName( new QName(
JBossSAMLURIConstants.XSI_NSURI.get(),
- "type", "xsi"));
- if( type == null )
+ StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE_VALUE.get());
+
+ Attribute type = startElement.getAttributeByName(new
QName(JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xsi"));
+ if (type == null)
{
return StaxParserUtil.getElementText(xmlEventReader);
- }
-
- String typeValue = StaxParserUtil.getAttributeValue(type);
- if( typeValue.contains( ":string" ))
+ }
+
+ String typeValue = StaxParserUtil.getAttributeValue(type);
+ if (typeValue.contains(":string"))
{
return StaxParserUtil.getElementText(xmlEventReader);
}
-
- throw new RuntimeException( "Unsupported xsi:type=" + typeValue );
+
+ throw new RuntimeException("Unsupported xsi:type=" + typeValue);
}
-
+
/**
* Parse the AuthnStatement inside the assertion
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static AuthnStatementType parseAuthnStatement( XMLEventReader xmlEventReader )
throws ParsingException
+ public static AuthnStatementType parseAuthnStatement(XMLEventReader xmlEventReader)
throws ParsingException
{
-
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
String AUTHNSTATEMENT = JBossSAMLConstants.AUTHN_STATEMENT.get();
- StaxParserUtil.validate( startElement, AUTHNSTATEMENT );
-
- Attribute authnInstant = startElement.getAttributeByName( new QName(
"AuthnInstant" ));
- if( authnInstant == null )
- throw new RuntimeException( "Required attribute AuthnInstant in " +
AUTHNSTATEMENT );
+ StaxParserUtil.validate(startElement, AUTHNSTATEMENT);
- XMLGregorianCalendar issueInstant = XMLTimeUtil.parse(
StaxParserUtil.getAttributeValue( authnInstant ));
- AuthnStatementType authnStatementType = new AuthnStatementType( issueInstant );
-
- Attribute sessionIndex = startElement.getAttributeByName( new QName(
"SessionIndex" ));
- if( sessionIndex != null )
- authnStatementType.setSessionIndex( StaxParserUtil.getAttributeValue(
sessionIndex ));
-
- //Get the next start element
- startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
- String tag = startElement.getName().getLocalPart();
- if( JBossSAMLConstants.AUTHN_CONTEXT.get().equals( tag ) )
+ Attribute authnInstant = startElement.getAttributeByName(new
QName("AuthnInstant"));
+ if (authnInstant == null)
+ throw new RuntimeException("Required attribute AuthnInstant in " +
AUTHNSTATEMENT);
+
+ XMLGregorianCalendar issueInstant =
XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(authnInstant));
+ AuthnStatementType authnStatementType = new AuthnStatementType(issueInstant);
+
+ Attribute sessionIndex = startElement.getAttributeByName(new
QName("SessionIndex"));
+ if (sessionIndex != null)
+
authnStatementType.setSessionIndex(StaxParserUtil.getAttributeValue(sessionIndex));
+
+ while (xmlEventReader.hasNext())
{
- authnStatementType.setAuthnContext( parseAuthnContextType( xmlEventReader ) );
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if (xmlEvent == null)
+ break;
+
+ if (xmlEvent instanceof EndElement)
+ {
+ xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
+ EndElement endElement = (EndElement) xmlEvent;
+ String endElementTag = StaxParserUtil.getEndElementName(endElement);
+ if (endElementTag.equals(AUTHNSTATEMENT))
+ break;
+ else
+ throw new RuntimeException("Unknown End Element:" +
endElementTag);
+ }
+ startElement = null;
+
+ if (xmlEvent instanceof StartElement)
+ {
+ startElement = (StartElement) xmlEvent;
+ }
+ else
+ {
+ startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+ }
+ if (startElement == null)
+ break;
+
+ String tag = StaxParserUtil.getStartElementName(startElement);
+
+ if (JBossSAMLConstants.SUBJECT_LOCALITY.get().equals(tag))
+ {
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ SubjectLocalityType subjectLocalityType = new SubjectLocalityType();
+ Attribute address = startElement.getAttributeByName(new
QName(JBossSAMLConstants.ADDRESS.get()));
+ if (address != null)
+ {
+
subjectLocalityType.setAddress(StaxParserUtil.getAttributeValue(address));
+ }
+ Attribute dns = startElement.getAttributeByName(new
QName(JBossSAMLConstants.DNS_NAME.get()));
+ if (dns != null)
+ {
+ subjectLocalityType.setDNSName(StaxParserUtil.getAttributeValue(dns));
+ }
+ authnStatementType.setSubjectLocality(subjectLocalityType);
+ StaxParserUtil.validate(StaxParserUtil.getNextEndElement(xmlEventReader),
+ JBossSAMLConstants.SUBJECT_LOCALITY.get());
+ }
+ else if (JBossSAMLConstants.AUTHN_CONTEXT.get().equals(tag))
+ {
+ authnStatementType.setAuthnContext(parseAuthnContextType(xmlEventReader));
+ }
+ else
+ throw new RuntimeException("Unknown tag:" + tag +
"::Location=" + startElement.getLocation());
+
}
- else throw new RuntimeException( "Unknown tag:" + tag +
"::Location=" + startElement.getLocation() );
-
- EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement, AUTHNSTATEMENT );
-
+
return authnStatementType;
}
-
+
/**
* Parse the AuthnContext Type inside the AuthnStatement
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static AuthnContextType parseAuthnContextType( XMLEventReader xmlEventReader )
throws ParsingException
+ public static AuthnContextType parseAuthnContextType(XMLEventReader xmlEventReader)
throws ParsingException
{
AuthnContextType authnContextType = new AuthnContextType();
-
+
StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- StaxParserUtil.validate( startElement, JBossSAMLConstants.AUTHN_CONTEXT.get() );
-
+ StaxParserUtil.validate(startElement, JBossSAMLConstants.AUTHN_CONTEXT.get());
+
//Get the next start element
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
String tag = startElement.getName().getLocalPart();
-
- if( JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get().equals( tag ))
+
+ if (JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get().equals(tag))
{
- String text = StaxParserUtil.getElementText( xmlEventReader );
-
- AuthnContextDeclRefType aAuthnContextDeclType = new AuthnContextDeclRefType(
URI.create(text));
- authnContextType.addURIType(aAuthnContextDeclType);
+ String text = StaxParserUtil.getElementText(xmlEventReader);
+
+ AuthnContextDeclRefType aAuthnContextDeclType = new
AuthnContextDeclRefType(URI.create(text));
+ authnContextType.addURIType(aAuthnContextDeclType);
EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement, JBossSAMLConstants.AUTHN_CONTEXT.get() );
+ StaxParserUtil.validate(endElement, JBossSAMLConstants.AUTHN_CONTEXT.get());
}
- else if( JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get().equals( tag ))
+ else if (JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get().equals(tag))
{
- String text = StaxParserUtil.getElementText( xmlEventReader );
-
- AuthnContextClassRefType aAuthnContextClassRefType = new
AuthnContextClassRefType( URI.create(text));
- authnContextType.addURIType( aAuthnContextClassRefType );
+ String text = StaxParserUtil.getElementText(xmlEventReader);
+
+ AuthnContextClassRefType aAuthnContextClassRefType = new
AuthnContextClassRefType(URI.create(text));
+ authnContextType.addURIType(aAuthnContextClassRefType);
EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement, JBossSAMLConstants.AUTHN_CONTEXT.get() );
+ StaxParserUtil.validate(endElement, JBossSAMLConstants.AUTHN_CONTEXT.get());
}
else
- throw new RuntimeException( "Unknown Tag:" + tag +
"::Location=" + startElement.getLocation() );
-
+ throw new RuntimeException("Unknown Tag:" + tag +
"::Location=" + startElement.getLocation());
+
return authnContextType;
- }
-
+ }
+
/**
* Parse a {@code NameIDType}
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static NameIDType parseNameIDType( XMLEventReader xmlEventReader ) throws
ParsingException
+ public static NameIDType parseNameIDType(XMLEventReader xmlEventReader) throws
ParsingException
{
- StartElement nameIDElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StartElement nameIDElement = StaxParserUtil.getNextStartElement(xmlEventReader);
NameIDType nameID = new NameIDType();
-
- Attribute nameQualifier = nameIDElement.getAttributeByName( new QName(
JBossSAMLConstants.NAME_QUALIFIER.get() ));
- if( nameQualifier != null )
+
+ Attribute nameQualifier = nameIDElement.getAttributeByName(new
QName(JBossSAMLConstants.NAME_QUALIFIER.get()));
+ if (nameQualifier != null)
{
- nameID.setNameQualifier( StaxParserUtil.getAttributeValue(nameQualifier) );
- }
-
- Attribute format = nameIDElement.getAttributeByName( new QName(
JBossSAMLConstants.FORMAT.get() ));
- if( format != null )
+ nameID.setNameQualifier(StaxParserUtil.getAttributeValue(nameQualifier));
+ }
+
+ Attribute format = nameIDElement.getAttributeByName(new
QName(JBossSAMLConstants.FORMAT.get()));
+ if (format != null)
{
- nameID.setFormat( URI.create( StaxParserUtil.getAttributeValue( format )) );
+ nameID.setFormat(URI.create(StaxParserUtil.getAttributeValue(format)));
}
-
- Attribute spProvidedID = nameIDElement.getAttributeByName( new QName(
JBossSAMLConstants.SP_PROVIDED_ID.get() ));
- if( spProvidedID != null )
+
+ Attribute spProvidedID = nameIDElement.getAttributeByName(new
QName(JBossSAMLConstants.SP_PROVIDED_ID.get()));
+ if (spProvidedID != null)
{
- nameID.setSPProvidedID( StaxParserUtil.getAttributeValue( spProvidedID ));
+ nameID.setSPProvidedID(StaxParserUtil.getAttributeValue(spProvidedID));
}
-
- Attribute spNameQualifier = nameIDElement.getAttributeByName( new QName(
JBossSAMLConstants.SP_NAME_QUALIFIER.get() ));
- if( spNameQualifier != null )
+
+ Attribute spNameQualifier = nameIDElement
+ .getAttributeByName(new QName(JBossSAMLConstants.SP_NAME_QUALIFIER.get()));
+ if (spNameQualifier != null)
{
- nameID.setSPNameQualifier( StaxParserUtil.getAttributeValue( spNameQualifier
));
+ nameID.setSPNameQualifier(StaxParserUtil.getAttributeValue(spNameQualifier));
}
- String nameIDValue = StaxParserUtil.getElementText( xmlEventReader );
- nameID.setValue( nameIDValue );
-
+ String nameIDValue = StaxParserUtil.getElementText(xmlEventReader);
+ nameID.setValue(nameIDValue);
+
return nameID;
}
-
+
/**
* Parse a space delimited list of strings
* @param startElement
* @return
*/
- public static List<String> parseProtocolEnumeration( StartElement startElement
)
+ public static List<String> parseProtocolEnumeration(StartElement startElement)
{
List<String> protocolEnum = new ArrayList<String>();
- Attribute proto = startElement.getAttributeByName( new QName(
JBossSAMLConstants.PROTOCOL_SUPPORT_ENUMERATION.get() ) );
+ Attribute proto = startElement
+ .getAttributeByName(new
QName(JBossSAMLConstants.PROTOCOL_SUPPORT_ENUMERATION.get()));
String val = StaxParserUtil.getAttributeValue(proto);
- if( StringUtil.isNotNull( val ))
+ if (StringUtil.isNotNull(val))
{
- StringTokenizer st = new StringTokenizer( val );
- while( st.hasMoreTokens() )
+ StringTokenizer st = new StringTokenizer(val);
+ while (st.hasMoreTokens())
{
- protocolEnum.add( st.nextToken() );
+ protocolEnum.add(st.nextToken());
}
-
+
}
- return protocolEnum;
+ return protocolEnum;
}
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2011-03-01
19:10:15 UTC (rev 786)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2011-03-01
19:35:51 UTC (rev 787)
@@ -62,6 +62,7 @@
CONTACT_PERSON( "ContactPerson" ),
CONTACT_TYPE( "contactType" ),
DESTINATION( "Destination" ),
+ DNS_NAME( "DNSName"),
EMAIL_ADDRESS( "EmailAddress" ),
ENCODING( "Encoding" ),
ENCRYPTED_ASSERTION( "EncryptedAssertion" ),
@@ -137,6 +138,7 @@
SUBJECT( "Subject" ),
SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
SUBJECT_CONFIRMATION_DATA( "SubjectConfirmationData" ),
+ SUBJECT_LOCALITY( "SubjectLocality" ),
SURNAME( "SurName" ),
TELEPHONE_NUMBER( "TelephoneNumber" ),
TYPE( "type" ),
Modified:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java 2011-03-01
19:10:15 UTC (rev 786)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java 2011-03-01
19:35:51 UTC (rev 787)
@@ -46,6 +46,7 @@
import
org.picketlink.identity.federation.newmodel.saml.v2.assertion.StatementAbstractType;
import
org.picketlink.identity.federation.newmodel.saml.v2.assertion.SubjectConfirmationDataType;
import
org.picketlink.identity.federation.newmodel.saml.v2.assertion.SubjectConfirmationType;
+import
org.picketlink.identity.federation.newmodel.saml.v2.assertion.SubjectLocalityType;
import org.picketlink.identity.federation.newmodel.saml.v2.assertion.SubjectType;
import
org.picketlink.identity.federation.newmodel.saml.v2.profiles.xacml.assertion.XACMLAuthzDecisionStatementType;
import org.picketlink.identity.federation.newmodel.saml.v2.protocol.ResponseType;
@@ -63,157 +64,161 @@
public void testSAMLResponseParse() throws Exception
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-response.xml" );
-
+ InputStream configStream =
tcl.getResourceAsStream("parser/saml2/saml2-response.xml");
+
SAMLParser parser = new SAMLParser();
- ResponseType response = ( ResponseType ) parser.parse(configStream);
- assertNotNull( "ResponseType is not null", response );
-
- assertEquals( XMLTimeUtil.parse( "2009-05-26T14:06:26.362-05:00" ),
response.getIssueInstant() );
- assertEquals( "2.0", response.getVersion() );
- assertEquals( "ID_1164e0fc-576d-4797-b11c-3d049520f566", response.getID()
);
-
+ ResponseType response = (ResponseType) parser.parse(configStream);
+ assertNotNull("ResponseType is not null", response);
+
+ assertEquals(XMLTimeUtil.parse("2009-05-26T14:06:26.362-05:00"),
response.getIssueInstant());
+ assertEquals("2.0", response.getVersion());
+ assertEquals("ID_1164e0fc-576d-4797-b11c-3d049520f566",
response.getID());
+
//Issuer
- assertEquals( "testIssuer", response.getIssuer().getValue() );
-
+ assertEquals("testIssuer", response.getIssuer().getValue());
+
//Status
StatusType status = response.getStatus();
- assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Success",
status.getStatusCode().getValue().toString() );
-
+ assertEquals("urn:oasis:names:tc:SAML:2.0:status:Success",
status.getStatusCode().getValue().toString());
+
List<RTChoiceType> assertionList = response.getAssertions();
- assertEquals( 2, assertionList.size() );
-
- AssertionType assertion1 = assertionList.get( 0 ).getAssertion();
- assertEquals( "ID_0be488d8-7089-4892-8aeb-83594c800706",
assertion1.getID() );
- assertEquals( XMLTimeUtil.parse( "2009-05-26T14:06:26.362-05:00" ),
assertion1.getIssueInstant() );
- assertEquals( "2.0", assertion1.getVersion() );
- assertEquals( "testIssuer", assertion1.getIssuer().getValue() ) ;
-
+ assertEquals(2, assertionList.size());
+
+ AssertionType assertion1 = assertionList.get(0).getAssertion();
+ assertEquals("ID_0be488d8-7089-4892-8aeb-83594c800706",
assertion1.getID());
+ assertEquals(XMLTimeUtil.parse("2009-05-26T14:06:26.362-05:00"),
assertion1.getIssueInstant());
+ assertEquals("2.0", assertion1.getVersion());
+ assertEquals("testIssuer", assertion1.getIssuer().getValue());
+
Iterator<StatementAbstractType> iterator =
assertion1.getStatements().iterator();
-
+
AuthnStatementType authnStatement = (AuthnStatementType) iterator.next();
- assertEquals( XMLTimeUtil.parse( "2009-05-26T14:06:26.359-05:00" ),
authnStatement.getAuthnInstant() );
-
+ assertEquals(XMLTimeUtil.parse("2009-05-26T14:06:26.359-05:00"),
authnStatement.getAuthnInstant());
AuthnContextType authnContext = authnStatement.getAuthnContext();
-
+
AuthnContextDeclRefType refType = (AuthnContextDeclRefType)
authnContext.getURIType().iterator().next();
- assertEquals(
"urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport",
refType.getValue().toASCIIString() );
+
assertEquals("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport",
refType.getValue()
+ .toASCIIString());
/*
JAXBElement<?> authnContextDeclRefJaxb = (JAXBElement<?>)
authnStatement.getAuthnContext().getContent().get(0);
assertEquals(
"urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport",
authnContextDeclRefJaxb.getValue() );*/
-
-
- AssertionType assertion2 = (AssertionType) assertionList.get( 1 ).getAssertion();
- assertEquals( "ID_976d8310-658a-450d-be39-f33c73c8afa6",
assertion2.getID() );
- assertEquals( XMLTimeUtil.parse( "2009-05-26T14:06:26.363-05:00" ),
assertion2.getIssueInstant() );
- assertEquals( "2.0", assertion2.getVersion() );
- assertEquals( "testIssuer", assertion2.getIssuer().getValue() );
-
+
+ AssertionType assertion2 = assertionList.get(1).getAssertion();
+ assertEquals("ID_976d8310-658a-450d-be39-f33c73c8afa6",
assertion2.getID());
+ assertEquals(XMLTimeUtil.parse("2009-05-26T14:06:26.363-05:00"),
assertion2.getIssueInstant());
+ assertEquals("2.0", assertion2.getVersion());
+ assertEquals("testIssuer", assertion2.getIssuer().getValue());
+
authnStatement = (AuthnStatementType)
assertion2.getStatements().iterator().next();
- assertEquals( XMLTimeUtil.parse( "2009-05-26T14:06:26.359-05:00" ),
authnStatement.getAuthnInstant() );
+ assertEquals(XMLTimeUtil.parse("2009-05-26T14:06:26.359-05:00"),
authnStatement.getAuthnInstant());
+ SubjectLocalityType subjectLocality = authnStatement.getSubjectLocality();
+ assertNotNull(subjectLocality);
+ assertEquals("127.0.0.1", subjectLocality.getAddress());
authnContext = authnStatement.getAuthnContext();
-
+
refType = (AuthnContextDeclRefType) authnContext.getURIType().iterator().next();
- assertEquals(
"urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport",
refType.getValue().toASCIIString() );
-
+
assertEquals("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport",
refType.getValue()
+ .toASCIIString());
+
//Let us do some writing - currently only visual inspection. We will do proper
validation later.
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- SAMLResponseWriter writer = new
SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
- writer.write(response );
-
- System.out.println( new String( baos.toByteArray() ));
-
- ByteArrayInputStream bis = new ByteArrayInputStream( baos.toByteArray() );
- DocumentUtil.getDocument( bis ); //throws exceptions
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SAMLResponseWriter writer = new
SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(response);
+
+ System.out.println(new String(baos.toByteArray()));
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ DocumentUtil.getDocument(bis); //throws exceptions
}
-
+
@Test
public void testAssertionWithSubjectAndAttributes() throws Exception
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-response-assertion-subject.xml" );
-
+ InputStream configStream =
tcl.getResourceAsStream("parser/saml2/saml2-response-assertion-subject.xml");
+
SAMLParser parser = new SAMLParser();
- ResponseType response = ( ResponseType ) parser.parse(configStream);
- assertNotNull( response );
-
- assertEquals( "ID_45df1ea5-81e4-4147-a39a-43a4ef613f4e", response.getID()
);
- assertEquals( XMLTimeUtil.parse( "2010-11-04T00:19:16.847-05:00" ),
response.getIssueInstant() );
- assertEquals( "2.0", response.getVersion() );
- assertEquals( "http://localhost:8080/employee/",
response.getDestination() );
- assertEquals( "ID_04ded476-d73c-48af-b3a9-232a52905ffb",
response.getInResponseTo() );
-
+ ResponseType response = (ResponseType) parser.parse(configStream);
+ assertNotNull(response);
+
+ assertEquals("ID_45df1ea5-81e4-4147-a39a-43a4ef613f4e",
response.getID());
+ assertEquals(XMLTimeUtil.parse("2010-11-04T00:19:16.847-05:00"),
response.getIssueInstant());
+ assertEquals("2.0", response.getVersion());
+ assertEquals("http://localhost:8080/employee/",
response.getDestination());
+ assertEquals("ID_04ded476-d73c-48af-b3a9-232a52905ffb",
response.getInResponseTo());
+
//Issuer
- assertEquals( "http://localhost:8080/idp/",
response.getIssuer().getValue() );
-
+ assertEquals("http://localhost:8080/idp/",
response.getIssuer().getValue());
+
//Status
StatusType status = response.getStatus();
- assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Success",
status.getStatusCode().getValue().toString() );
-
+ assertEquals("urn:oasis:names:tc:SAML:2.0:status:Success",
status.getStatusCode().getValue().toString());
+
//Get the assertion
- AssertionType assertion = (AssertionType)
response.getAssertions().get(0).getAssertion();
- assertEquals( "ID_8be1534d-9155-4837-9f26-70ea2c15e327",
assertion.getID() );
- assertEquals( XMLTimeUtil.parse( "2010-11-04T00:19:16.842-05:00" ),
assertion.getIssueInstant() );
- assertEquals( "2.0", assertion.getVersion() );
-
- assertEquals( "http://localhost:8080/idp/",
assertion.getIssuer().getValue() );
-
+ AssertionType assertion = response.getAssertions().get(0).getAssertion();
+ assertEquals("ID_8be1534d-9155-4837-9f26-70ea2c15e327",
assertion.getID());
+ assertEquals(XMLTimeUtil.parse("2010-11-04T00:19:16.842-05:00"),
assertion.getIssueInstant());
+ assertEquals("2.0", assertion.getVersion());
+
+ assertEquals("http://localhost:8080/idp/",
assertion.getIssuer().getValue());
+
//Subject
SubjectType subject = assertion.getSubject();
-
+
NameIDType subjectNameID = (NameIDType) subject.getSubType().getBaseID();
- assertEquals( "anil", subjectNameID.getValue() );
- assertEquals( "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
subjectNameID.getFormat().toString() );
-
+ assertEquals("anil", subjectNameID.getValue());
+ assertEquals("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
subjectNameID.getFormat().toString());
+
SubjectConfirmationType subjectConfirmation = subject.getConfirmation().get(0);
- assertEquals( "urn:oasis:names:tc:SAML:2.0:cm:bearer",
subjectConfirmation.getMethod() );
-
+ assertEquals("urn:oasis:names:tc:SAML:2.0:cm:bearer",
subjectConfirmation.getMethod());
+
SubjectConfirmationDataType subjectConfirmationData =
subjectConfirmation.getSubjectConfirmationData();
- assertEquals( "ID_04ded476-d73c-48af-b3a9-232a52905ffb",
subjectConfirmationData.getInResponseTo() );
- assertEquals( XMLTimeUtil.parse( "2010-11-04T00:19:16.842-05:00" ),
subjectConfirmationData.getNotBefore() );
- assertEquals( XMLTimeUtil.parse( "2010-11-04T00:19:16.842-05:00" ),
subjectConfirmationData.getNotOnOrAfter() );
- assertEquals( "http://localhost:8080/employee/",
subjectConfirmationData.getRecipient());
-
- AttributeStatementType attributeStatement = (AttributeStatementType)
assertion.getStatements().iterator().next();
-
+ assertEquals("ID_04ded476-d73c-48af-b3a9-232a52905ffb",
subjectConfirmationData.getInResponseTo());
+ assertEquals(XMLTimeUtil.parse("2010-11-04T00:19:16.842-05:00"),
subjectConfirmationData.getNotBefore());
+ assertEquals(XMLTimeUtil.parse("2010-11-04T00:19:16.842-05:00"),
subjectConfirmationData.getNotOnOrAfter());
+ assertEquals("http://localhost:8080/employee/",
subjectConfirmationData.getRecipient());
+
+ AttributeStatementType attributeStatement = (AttributeStatementType)
assertion.getStatements().iterator().next();
+
List<AttributeStatementType.ASTChoiceType> attributes =
attributeStatement.getAttributes();
- assertEquals( 2, attributes.size() );
-
- for( AttributeStatementType.ASTChoiceType attr: attributes )
+ assertEquals(2, attributes.size());
+
+ for (AttributeStatementType.ASTChoiceType attr : attributes)
{
AttributeType attribute = attr.getAttribute();
- assertEquals( "role", attribute.getFriendlyName() );
- assertEquals( "role", attribute.getName() );
- assertEquals( "role", attribute.getNameFormat() );
+ assertEquals("role", attribute.getFriendlyName());
+ assertEquals("role", attribute.getName());
+ assertEquals("role", attribute.getNameFormat());
List<Object> attributeValues = attribute.getAttributeValue();
- assertEquals( 1, attributeValues.size() );
-
- String str = (String ) attributeValues.get( 0 );
- if( ! ( str.equals( "employee") || str.equals( "manager"
)))
- throw new RuntimeException( "attrib value not found" );
- }
+ assertEquals(1, attributeValues.size());
+
+ String str = (String) attributeValues.get(0);
+ if (!(str.equals("employee") || str.equals("manager")))
+ throw new RuntimeException("attrib value not found");
+ }
}
-
+
@Test
public void testXACMLDecisionStatements() throws Exception
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- InputStream configStream = tcl.getResourceAsStream(
"saml-xacml/saml-xacml-response-1.xml" );
-
+ InputStream configStream =
tcl.getResourceAsStream("saml-xacml/saml-xacml-response-1.xml");
+
SAMLParser parser = new SAMLParser();
- ResponseType response = ( ResponseType ) parser.parse(configStream);
- assertNotNull( "ResponseType is not null", response );
-
+ ResponseType response = (ResponseType) parser.parse(configStream);
+ assertNotNull("ResponseType is not null", response);
+
//Get the assertion
- AssertionType assertion = (AssertionType)
response.getAssertions().get(0).getAssertion();
- assertEquals( "ID_response-id:1", assertion.getID() );
- assertEquals( XMLTimeUtil.parse( "2008-03-19T22:17:13Z" ),
assertion.getIssueInstant() );
- assertEquals( "2.0", assertion.getVersion() );
-
- XACMLAuthzDecisionStatementType xacmlStat = (XACMLAuthzDecisionStatementType)
assertion.getStatements().iterator().next();
- assertNotNull( xacmlStat.getRequest() );
- assertNotNull( xacmlStat.getResponse() );
+ AssertionType assertion = response.getAssertions().get(0).getAssertion();
+ assertEquals("ID_response-id:1", assertion.getID());
+ assertEquals(XMLTimeUtil.parse("2008-03-19T22:17:13Z"),
assertion.getIssueInstant());
+ assertEquals("2.0", assertion.getVersion());
+
+ XACMLAuthzDecisionStatementType xacmlStat = (XACMLAuthzDecisionStatementType)
assertion.getStatements()
+ .iterator().next();
+ assertNotNull(xacmlStat.getRequest());
+ assertNotNull(xacmlStat.getResponse());
}
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-response.xml
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-response.xml 2011-03-01
19:10:15 UTC (rev 786)
+++
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-response.xml 2011-03-01
19:35:51 UTC (rev 787)
@@ -22,6 +22,7 @@
ID="ID_976d8310-658a-450d-be39-f33c73c8afa6" Version="2.0">
<Issuer>testIssuer</Issuer>
<AuthnStatement AuthnInstant="2009-05-26T14:06:26.359-05:00">
+ <SubjectLocality Address="127.0.0.1"/>
<AuthnContext>
<AuthnContextDeclRef>
urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport