Picketlink SVN: r525 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-04 12:48:13 -0400 (Thu, 04 Nov 2010)
New Revision: 525
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
Log:
write subject
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2010-11-04 16:47:13 UTC (rev 524)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2010-11-04 16:48:13 UTC (rev 525)
@@ -32,12 +32,20 @@
import org.picketlink.identity.federation.core.exceptions.ProcessingException;
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.util.StaxUtil;
+import org.picketlink.identity.federation.core.util.StringUtil;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+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.AuthnContextType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
+import org.picketlink.identity.federation.saml.v2.assertion.BaseIDAbstractType;
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;
/**
* Write the SAML Assertion to stream
@@ -68,6 +76,14 @@
NameIDType issuer = assertion.getIssuer();
write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out );
+ SubjectType subject = assertion.getSubject();
+ if( subject != null )
+ {
+ write(subject, out);
+ }
+
+ //TODO: conditions and advice
+
List<StatementAbstractType> statements = assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement();
if( statements != null )
{
@@ -77,10 +93,16 @@
{
write( ( AuthnStatementType )statement, out );
}
- else write( statement, out );
+ else if( statement instanceof AttributeStatementType )
+ {
+ write( ( AttributeStatementType )statement, out );
+ }
+ else
+ throw new RuntimeException( "unknown statement type=" + statement.getClass().getName() );
}
}
- StaxUtil.writeEndElement( writer);
+
+ StaxUtil.writeEndElement( writer);
StaxUtil.flush( writer );
}
@@ -96,6 +118,29 @@
//TODO: handle this section
}
+ public void write( AttributeStatementType statement, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get() , ASSERTION_NSURI.get() );
+
+ List<Object> attributes = statement.getAttributeOrEncryptedAttribute();
+ if( attributes != null )
+ {
+ for( Object attr : attributes )
+ {
+ if( attr instanceof AttributeType )
+ {
+ AttributeType attributeType = (AttributeType) attr;
+ write( attributeType, out );
+ }
+ }
+ }
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+
/**
* Write an {@code AuthnStatementType} to stream
* @param authnStatement
@@ -150,5 +195,158 @@
throw new RuntimeException( "Unsupported :" + elName );
}
}
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
}
+
+ /**
+ * Write an {@code AttributeType} to stream
+ * @param attributeType
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( AttributeType attributeType, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE.get() , ASSERTION_NSURI.get() );
+
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME.get(), attributeType.getName() );
+
+ String friendlyName = attributeType.getFriendlyName();
+ if( StringUtil.isNotNull( friendlyName ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.FRIENDLY_NAME.get(), friendlyName );
+ }
+
+ String nameFormat = attributeType.getNameFormat();
+ if( StringUtil.isNotNull( nameFormat ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME_FORMAT.get(), friendlyName );
+ }
+
+ List<Object> attributeValues = attributeType.getAttributeValue();
+ if( attributeValues != null )
+ {
+ for( Object attributeValue : attributeValues )
+ {
+ if( attributeValue instanceof String )
+ {
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_VALUE.get() , ASSERTION_NSURI.get() );
+
+ StaxUtil.writeNameSpace( writer, "xsi", JBossSAMLURIConstants.XSI_NSURI.get() );
+ StaxUtil.writeNameSpace( writer, "xs", JBossSAMLURIConstants.XMLSCHEMA_NSURI.get() );
+ StaxUtil.writeAttribute( writer, JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xs:string");
+ StaxUtil.writeCharacters(writer, (String) attributeValue );
+
+ StaxUtil.writeEndElement( writer);
+ }
+ else
+ throw new RuntimeException( "Unsupported attribute value:" + attributeValue.getClass().getName() );
+ }
+ }
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * write an {@code SubjectType} to stream
+ * @param subject
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( SubjectType subject, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT.get() , ASSERTION_NSURI.get() );
+ List<JAXBElement<?>> contentList = subject.getContent();
+ if( contentList != null )
+ {
+ for( JAXBElement<?> jaxbEl: contentList )
+ {
+ Class<?> declaredType = jaxbEl.getDeclaredType();
+ if( declaredType.equals( SubjectConfirmationType.class) )
+ {
+ SubjectConfirmationType subjectConfirmationType = (SubjectConfirmationType) jaxbEl.getValue();
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION.get(), ASSERTION_NSURI.get() );
+
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.METHOD.get(), subjectConfirmationType.getMethod() );
+
+ BaseIDAbstractType baseID = subjectConfirmationType.getBaseID();
+ if( baseID != null )
+ {
+ write( baseID, out );
+ }
+ NameIDType nameIDType = subjectConfirmationType.getNameID();
+ if( nameIDType != null )
+ {
+ write( nameIDType, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX), out );
+ }
+ SubjectConfirmationDataType subjectConfirmationData = subjectConfirmationType.getSubjectConfirmationData();
+ if( subjectConfirmationData != null )
+ {
+ write( subjectConfirmationData, out );
+ }
+
+
+ StaxUtil.writeEndElement( writer);
+ }
+ else if( declaredType.equals( NameIDType.class ))
+ {
+ NameIDType nameIDType = (NameIDType) jaxbEl.getValue();
+ write( nameIDType, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX), out );
+ }
+ else
+ throw new RuntimeException( "SAMLAssertionWriter: NYI: declared Type:" + declaredType.getName() );
+ }
+ }
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ private void write( BaseIDAbstractType baseId, OutputStream out ) throws ProcessingException
+ {
+ throw new RuntimeException( "NYI");
+ }
+
+ private void write( SubjectConfirmationDataType subjectConfirmationData, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter(out);
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get(), ASSERTION_NSURI.get() );
+
+ //Let us look at attributes
+ String inResponseTo = subjectConfirmationData.getInResponseTo();
+ if( StringUtil.isNotNull( inResponseTo ))
+ {
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.IN_RESPONSE_TO.get(), inResponseTo );
+ }
+
+ XMLGregorianCalendar notBefore = subjectConfirmationData.getNotBefore();
+ if( notBefore != null )
+ {
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_BEFORE.get(),notBefore.toString() );
+ }
+
+ XMLGregorianCalendar notOnOrAfter = subjectConfirmationData.getNotOnOrAfter();
+ if( notOnOrAfter != null )
+ {
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_ON_OR_AFTER.get(),notOnOrAfter.toString() );
+ }
+
+ String recipient = subjectConfirmationData.getRecipient();
+ if( StringUtil.isNotNull( recipient ))
+ {
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.RECIPIENT.get(), recipient );
+ }
+
+ String address = subjectConfirmationData.getAddress();
+ if( StringUtil.isNotNull( address ))
+ {
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.ADDRESS.get(), address );
+ }
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
}
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r524 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-04 12:47:13 -0400 (Thu, 04 Nov 2010)
New Revision: 524
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/JBossSAMLURIConstants.java
Log:
new constants
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 2010-11-04 16:46:44 UTC (rev 523)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-11-04 16:47:13 UTC (rev 524)
@@ -28,9 +28,13 @@
*/
public enum JBossSAMLConstants
{
+ ADDRESS( "Address" ),
ALLOW_CREATE( "AllowCreate" ),
ASSERTION( "Assertion" ),
ASSERTION_CONSUMER_SERVICE_URL( "AssertionConsumerServiceURL" ),
+ ATTRIBUTE( "Attribute" ),
+ ATTRIBUTE_STATEMENT( "AttributeStatement" ),
+ ATTRIBUTE_VALUE( "AttributeValue" ),
AUDIENCE( "Audience" ),
AUDIENCE_RESTRICTION( "AudienceRestriction" ),
AUTHN_CONTEXT( "AuthnContext" ),
@@ -42,6 +46,7 @@
CONSENT( "Consent" ),
DESTINATION( "Destination" ),
FORMAT( "Format" ),
+ FRIENDLY_NAME( "FriendlyName" ),
ID( "ID" ),
IN_RESPONSE_TO( "InResponseTo" ),
ISSUE_INSTANT( "IssueInstant" ),
@@ -51,11 +56,14 @@
LOGOUT_RESPONSE( "LogoutResponse" ),
METADATA_MIME("application/samlmetadata+xml"),
METHOD( "Method" ),
+ NAME( "Name" ),
+ NAME_FORMAT( "NameFormat" ),
NAMEID( "NameID" ),
NAMEID_POLICY( "NameIDPolicy" ),
NAME_QUALIFIER( "NameQualifier" ),
NOT_BEFORE( "NotBefore" ),
NOT_ON_OR_AFTER( "NotOnOrAfter" ),
+ RECIPIENT( "Recipient" ),
RESPONSE( "Response" ),
SESSION_INDEX( "SessionIndex" ),
SP_PROVIDED_ID( "SPProvidedID" ),
@@ -70,6 +78,7 @@
STATUS_RESPONSE_TYPE( "StatusResponseType" ),
SUBJECT( "Subject" ),
SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
+ SUBJECT_CONFIRMATION_DATA( "SubjectConfirmationData" ),
VALUE( "Value" ),
VERSION( "Version" ),
VERSION_2_0("2.0"),
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLURIConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLURIConstants.java 2010-11-04 16:46:44 UTC (rev 523)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLURIConstants.java 2010-11-04 16:47:13 UTC (rev 524)
@@ -104,7 +104,8 @@
X500_NSURI("urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500"),
XMLSCHEMA_NSURI("http://www.w3.org/2001/XMLSchema"),
XMLDSIG_NSURI("http://www.w3.org/2000/09/xmldsig#"),
- XMLENC_NSURI("http://www.w3.org/2001/04/xmlenc#");
+ XMLENC_NSURI("http://www.w3.org/2001/04/xmlenc#"),
+ XSI_NSURI( "http://www.w3.org/2001/XMLSchema-instance" );
private String uri = null;
14 years, 2 months
Picketlink SVN: r523 - federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-04 12:46:44 -0400 (Thu, 04 Nov 2010)
New Revision: 523
Modified:
federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java
Log:
consider the case when attribs is null
Modified: federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java
===================================================================
--- federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java 2010-11-04 05:48:13 UTC (rev 522)
+++ federation/trunk/picketlink-web/src/main/java/org/picketlink/identity/federation/web/handlers/saml2/SAML2AuthenticationHandler.java 2010-11-04 16:46:44 UTC (rev 523)
@@ -225,7 +225,7 @@
saml2Response.createTimedConditions(assertion, assertionValidity);
//Add in the attributes information
- if(attribs != null)
+ if(attribs != null && attribs.size() > 0 )
{
AttributeStatementType attStatement = StatementUtil.createAttributeStatement(attribs);
assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement().add(attStatement);
@@ -255,6 +255,7 @@
}
catch (Exception e)
{
+ e.printStackTrace();
if(trace)
log.trace(e);
}
14 years, 2 months
Picketlink SVN: r522 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-04 01:48:13 -0400 (Thu, 04 Nov 2010)
New Revision: 522
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java
Log:
add new methods
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2010-11-03 21:35:31 UTC (rev 521)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2010-11-04 05:48:13 UTC (rev 522)
@@ -91,6 +91,25 @@
throw new ProcessingException( e );
}
}
+
+ /**
+ * Set a prefix
+ * @param writer
+ * @param prefix
+ * @param nsURI
+ * @throws ProcessingException
+ */
+ public static void setPrefix( XMLStreamWriter writer, String prefix, String nsURI ) throws ProcessingException
+ {
+ try
+ {
+ writer.setPrefix(prefix, nsURI );
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ProcessingException( e );
+ }
+ }
/**
* Write an xml attribute
@@ -112,6 +131,26 @@
}
/**
+ * Write an xml attribute
+ * @param writer
+ * @param localName localpart
+ * @param type typically xsi:type
+ * @param value value of the attribute
+ * @throws ProcessingException
+ */
+ public static void writeAttribute( XMLStreamWriter writer, String localName, String type, String value ) throws ProcessingException
+ {
+ try
+ {
+ writer.writeAttribute( localName, type, value );
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ProcessingException( e );
+ }
+ }
+
+ /**
* Write a string as text node
* @param writer
* @param value
14 years, 2 months
Picketlink SVN: r521 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v2/writers and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-03 17:35:31 -0400 (Wed, 03 Nov 2010)
New Revision: 521
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/writers/SAMLRequestWriter.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java
Log:
PLFED-109: PLFED-110: write SLO req/response
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 2010-11-03 17:41:54 UTC (rev 520)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-11-03 21:35:31 UTC (rev 521)
@@ -67,6 +67,7 @@
STATUS_CODE( "StatusCode" ),
STATUS_DETAIL( "StatusDetail" ),
STATUS_MESSAGE( "StatusMessage" ),
+ STATUS_RESPONSE_TYPE( "StatusResponseType" ),
SUBJECT( "Subject" ),
SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
VALUE( "Value" ),
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java 2010-11-03 17:41:54 UTC (rev 520)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java 2010-11-03 21:35:31 UTC (rev 521)
@@ -34,6 +34,7 @@
import org.picketlink.identity.federation.core.util.StringUtil;
import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
+import org.picketlink.identity.federation.saml.v2.protocol.LogoutRequestType;
import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
/**
@@ -87,6 +88,33 @@
}
/**
+ * Write a {@code LogoutRequestType} to stream
+ * @param logOutRequest
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( LogoutRequestType logOutRequest, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.LOGOUT_REQUEST.get() , PROTOCOL_NSURI.get() );
+
+ StaxUtil.writeNameSpace( writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get() );
+ StaxUtil.WriteDefaultNameSpace( writer, ASSERTION_NSURI.get() );
+
+ //Attributes
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ID.get(), logOutRequest.getID() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.VERSION.get(), logOutRequest.getVersion() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ISSUE_INSTANT.get(), logOutRequest.getIssueInstant().toString() );
+
+ NameIDType issuer = logOutRequest.getIssuer();
+ write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out );
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
* Write a {@code NameIDPolicyType} to stream
* @param nameIDPolicy
* @param out
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java 2010-11-03 17:41:54 UTC (rev 520)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java 2010-11-03 21:35:31 UTC (rev 521)
@@ -49,6 +49,7 @@
public class SAMLResponseWriter extends BaseWriter
{
private SAMLAssertionWriter assertionWriter = new SAMLAssertionWriter();
+
/**
* Write a {@code ResponseType} to stream
* @param response
@@ -88,6 +89,41 @@
}
/**
+ * Write a {@code StatusResponseType}
+ * @param response
+ * @param qname QName of the starting element
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( StatusResponseType response, QName qname, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+
+ if( qname == null )
+ {
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_RESPONSE_TYPE.get() , PROTOCOL_NSURI.get() );
+ }
+ else
+ {
+ StaxUtil.writeStartElement( writer, qname.getPrefix(), qname.getLocalPart() , qname.getNamespaceURI() );
+ }
+
+ StaxUtil.writeNameSpace( writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get() );
+ StaxUtil.WriteDefaultNameSpace( writer, ASSERTION_NSURI.get() );
+
+ writeBaseAttributes( response );
+
+ NameIDType issuer = response.getIssuer();
+ write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out );
+
+ StatusType status = response.getStatus();
+ write( status, out );
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
* Write a {@code StatusType} to stream
* @param status
* @param out
@@ -133,6 +169,9 @@
{
StaxUtil.writeAttribute( writer, JBossSAMLConstants.VALUE.get(), value );
}
+ StatusCodeType subStatusCode = statusCodeType.getStatusCode();
+ if( subStatusCode != null )
+ write( subStatusCode, out );
StaxUtil.writeEndElement( writer);
StaxUtil.flush( writer );
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java 2010-11-03 17:41:54 UTC (rev 520)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java 2010-11-03 21:35:31 UTC (rev 521)
@@ -29,6 +29,7 @@
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLRequestWriter;
import org.picketlink.identity.federation.saml.v2.protocol.LogoutRequestType;
/**
@@ -53,5 +54,9 @@
assertEquals( "2.0", lotRequest.getVersion() );
//Issuer
assertEquals( "http://localhost:8080/sales/", lotRequest.getIssuer().getValue() );
+
+ //Try out writing
+ SAMLRequestWriter writer = new SAMLRequestWriter();
+ writer.write( lotRequest, System.out );
}
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java 2010-11-03 17:41:54 UTC (rev 520)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java 2010-11-03 21:35:31 UTC (rev 521)
@@ -23,13 +23,18 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.PROTOCOL_NSURI;
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants.LOGOUT_RESPONSE;
import java.io.InputStream;
+import javax.xml.namespace.QName;
+
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
-import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLResponseWriter;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
/**
@@ -46,7 +51,7 @@
InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-logout-response.xml" );
SAMLParser parser = new SAMLParser();
- ResponseType response = ( ResponseType ) parser.parse(configStream);
+ StatusResponseType response = ( StatusResponseType ) parser.parse(configStream);
assertNotNull( "ResponseType is not null", response );
assertEquals( XMLTimeUtil.parse( "2010-07-29T13:46:03.862-05:00" ), response.getIssueInstant() );
@@ -60,5 +65,9 @@
StatusType status = response.getStatus();
assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Responder", status.getStatusCode().getValue() );
assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Success", status.getStatusCode().getStatusCode().getValue() );
+
+ //Let us do some writing - currently only visual inspection. We will do proper validation later.
+ SAMLResponseWriter writer = new SAMLResponseWriter();
+ writer.write(response, new QName( PROTOCOL_NSURI.get(), LOGOUT_RESPONSE.get(), "samlp"), System.out );
}
}
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r520 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v2/constants and 2 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-03 13:41:54 -0400 (Wed, 03 Nov 2010)
New Revision: 520
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.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/SAMLAssertionParserTestCase.java
Log:
PLFED-109: PLFED-110: parse SLO request response
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-03 14:15:54 UTC (rev 519)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -31,7 +31,6 @@
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
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.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
@@ -59,23 +58,13 @@
startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
if( startElement == null )
break;
+ super.parseCommonElements(startElement, xmlEventReader, authnRequest);
+
String elementName = StaxParserUtil.getStartElementName( startElement );
- if( JBossSAMLConstants.ISSUER.get().equals( elementName ))
+ if( JBossSAMLConstants.NAMEID_POLICY.get().equals( elementName ))
{
startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
- NameIDType issuer = new NameIDType();
- issuer.setValue( StaxParserUtil.getElementText( xmlEventReader ));
- authnRequest.setIssuer( issuer );
- }
- else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
- {
- startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
- StaxParserUtil.bypassElementBlock(xmlEventReader, JBossSAMLConstants.SIGNATURE.get() );
- }
- else if( JBossSAMLConstants.NAMEID_POLICY.get().equals( elementName ))
- {
- startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
authnRequest.setNameIDPolicy( getNameIDPolicy( startElement ));
}
}
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-11-03 14:15:54 UTC (rev 519)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -68,6 +68,18 @@
return authNRequestParser.parse( xmlEventReader );
}
else if( JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( nsURI ) &&
+ JBossSAMLConstants.LOGOUT_REQUEST.get().equals( startElementName.getLocalPart() ))
+ {
+ SAMLSloRequestParser sloParser = new SAMLSloRequestParser();
+ return sloParser.parse( xmlEventReader );
+ }
+ else if( JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( nsURI ) &&
+ JBossSAMLConstants.LOGOUT_RESPONSE.get().equals( startElementName.getLocalPart() ))
+ {
+ SAMLSloResponseParser sloParser = new SAMLSloResponseParser();
+ return sloParser.parse( xmlEventReader );
+ }
+ else if( JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( nsURI ) &&
JBossSAMLConstants.RESPONSE.get().equals( startElementName.getLocalPart() ))
{
SAMLResponseParser responseParser = new SAMLResponseParser();
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java 2010-11-03 14:15:54 UTC (rev 519)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -22,12 +22,15 @@
package org.picketlink.identity.federation.core.parsers.saml;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.protocol.RequestAbstractType;
/**
@@ -68,4 +71,23 @@
if( consent != null )
request.setConsent( StaxParserUtil.getAttributeValue( consent ));
}
+
+ protected void parseCommonElements( StartElement startElement, XMLEventReader xmlEventReader,
+ RequestAbstractType request ) throws ParsingException
+ {
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+
+ if( JBossSAMLConstants.ISSUER.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ NameIDType issuer = new NameIDType();
+ issuer.setValue( StaxParserUtil.getElementText( xmlEventReader ));
+ request.setIssuer( issuer );
+ }
+ else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StaxParserUtil.bypassElementBlock(xmlEventReader, JBossSAMLConstants.SIGNATURE.get() );
+ }
+ }
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java 2010-11-03 14:15:54 UTC (rev 519)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -23,10 +23,7 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.events.Attribute;
-import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
-import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
@@ -36,8 +33,6 @@
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
-import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
-import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
/**
* Parse the SAML Response
@@ -115,52 +110,5 @@
return response;
}
- /**
- * Parse the status element
- * @param xmlEventReader
- * @return
- * @throws ParsingException
- */
- private StatusType parseStatus( XMLEventReader xmlEventReader ) throws ParsingException
- {
- //Get the Start Element
- StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- String STATUS = JBossSAMLConstants.STATUS.get();
- StaxParserUtil.validate(startElement, STATUS );
-
- StatusType status = new StatusType();
-
- while( xmlEventReader.hasNext() )
- {
- startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
- QName startElementName = startElement.getName();
- String elementTag = startElementName.getLocalPart();
-
- StatusCodeType statusCode = new StatusCodeType();
-
- if( JBossSAMLConstants.STATUS_CODE.get().equals( elementTag ))
- {
- startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- Attribute valueAttr = startElement.getAttributeByName( new QName( "Value" ));
- if( valueAttr != null )
- {
- statusCode.setValue( StaxParserUtil.getAttributeValue( valueAttr ));
- }
- //Get the next end element
- StaxParserUtil.getNextEndElement(xmlEventReader);
- }
-
- status.setStatusCode( statusCode );
-
- //Get the next end element
- XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
- if( xmlEvent instanceof EndElement )
- {
- EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- if( StaxParserUtil.matches(endElement, STATUS ))
- break;
- }
- }
- return status;
- }
+
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -0,0 +1,106 @@
+/*
+ * 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.picketlink.identity.federation.core.parsers.saml;
+
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants.LOGOUT_REQUEST;
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.PROTOCOL_NSURI;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.LogoutRequestType;
+
+/**
+ * Parse the Single Log Out requests
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloRequestParser extends SAMLRequestAbstractParser implements ParserNamespaceSupport
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ //Get the startelement
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(startElement, LOGOUT_REQUEST.get() );
+
+ LogoutRequestType logoutRequest = parseBaseAttributes( startElement );
+
+ while( xmlEventReader.hasNext() )
+ {
+ //Let us peek at the next start element
+ startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( startElement == null )
+ break;
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+
+ parseCommonElements(startElement, xmlEventReader, logoutRequest );
+
+ if( JBossSAMLConstants.SESSION_INDEX.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ logoutRequest.getSessionIndex().add( StaxParserUtil.getElementText( xmlEventReader ) );
+ }
+ }
+ return logoutRequest;
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ return PROTOCOL_NSURI.get().equals( qname.getNamespaceURI() )
+ && LOGOUT_REQUEST.equals( qname.getLocalPart() );
+ }
+
+ /**
+ * Parse the attributes at the log out request element
+ * @param startElement
+ * @return
+ * @throws ParsingException
+ */
+ private LogoutRequestType parseBaseAttributes( StartElement startElement ) throws ParsingException
+ {
+ LogoutRequestType logoutRequest = new LogoutRequestType();
+ //Let us get the attributes
+ super.parseBaseAttributes(startElement, logoutRequest );
+
+ Attribute reason = startElement.getAttributeByName( new QName( "Reason" ));
+ if( reason != null )
+ logoutRequest.setReason( StaxParserUtil.getAttributeValue( reason ));
+
+ Attribute notOnOrAfter = startElement.getAttributeByName( new QName( "NotOnOrAfter" ));
+ if( notOnOrAfter != null )
+ logoutRequest.setNotOnOrAfter( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( notOnOrAfter )));
+ return logoutRequest;
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -0,0 +1,111 @@
+/*
+ * 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.picketlink.identity.federation.core.parsers.saml;
+
+
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants.LOGOUT_RESPONSE;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+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.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+
+/**
+ * Parse the SLO Response
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloResponseParser extends SAMLStatusResponseTypeParser implements ParserNamespaceSupport
+{
+
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ //Get the startelement
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(startElement, LOGOUT_RESPONSE.get() );
+
+ ResponseType response = parseBaseAttributes(startElement);
+
+ while( xmlEventReader.hasNext() )
+ {
+ //Let us peek at the next start element
+ startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( startElement == null )
+ break;
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+
+ if( JBossSAMLConstants.ISSUER.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ NameIDType issuer = new NameIDType();
+ issuer.setValue( StaxParserUtil.getElementText( xmlEventReader ));
+ response.setIssuer( issuer );
+ }
+ else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StaxParserUtil.bypassElementBlock(xmlEventReader, JBossSAMLConstants.SIGNATURE.get() );
+ }
+ else if( JBossSAMLConstants.ASSERTION.get().equals( elementName ))
+ {
+ SAMLAssertionParser assertionParser = new SAMLAssertionParser();
+ response.getAssertionOrEncryptedAssertion().add( assertionParser.parse(xmlEventReader));
+ }
+ else if( JBossSAMLConstants.STATUS.get().equals( elementName ))
+ {
+ response.setStatus( parseStatus(xmlEventReader) );
+ }
+ }
+ return response;
+ }
+
+ /**
+ * Parse the attributes at the response element
+ * @param startElement
+ * @return
+ * @throws ConfigurationException
+ */
+ private ResponseType parseBaseAttributes( StartElement startElement ) throws ParsingException
+ {
+ ResponseType response = new ResponseType();
+ super.parseBaseAttributes( startElement, response );
+
+ return response;
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ return JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( qname.getNamespaceURI() )
+ && LOGOUT_RESPONSE.equals( qname.getLocalPart() );
+ }
+}
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java 2010-11-03 14:15:54 UTC (rev 519)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -22,13 +22,19 @@
package org.picketlink.identity.federation.core.parsers.saml;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
/**
* Base Class for all Response Type parsing for SAML2
@@ -71,6 +77,73 @@
Attribute inResponseTo = startElement.getAttributeByName( new QName( "InResponseTo" ));
if( inResponseTo != null )
response.setInResponseTo( StaxParserUtil.getAttributeValue( inResponseTo ));
- }
+ }
+
+ /**
+ * Parse the status element
+ * @param xmlEventReader
+ * @return
+ * @throws ParsingException
+ */
+ protected StatusType parseStatus( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ //Get the Start Element
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ String STATUS = JBossSAMLConstants.STATUS.get();
+ StaxParserUtil.validate(startElement, STATUS );
+
+ StatusType status = new StatusType();
+
+ while( xmlEventReader.hasNext() )
+ {
+ startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+ if( startElement == null )
+ break;
+
+ QName startElementName = startElement.getName();
+ String elementTag = startElementName.getLocalPart();
+
+ StatusCodeType statusCode = new StatusCodeType();
+
+ if( JBossSAMLConstants.STATUS_CODE.get().equals( elementTag ))
+ {
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ if( startElement == null )
+ break;
+ Attribute valueAttr = startElement.getAttributeByName( new QName( "Value" ));
+ if( valueAttr != null )
+ {
+ statusCode.setValue( StaxParserUtil.getAttributeValue( valueAttr ));
+ }
+ status.setStatusCode( statusCode );
+
+ //Peek at the next start element to see if it is status code
+ startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( JBossSAMLConstants.STATUS_CODE.get().equals( startElement.getName().getLocalPart() ))
+ {
+ StatusCodeType subStatusCodeType = new StatusCodeType();
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ Attribute subValueAttr = startElement.getAttributeByName( new QName( "Value" ));
+ if( subValueAttr != null )
+ {
+ subStatusCodeType.setValue( StaxParserUtil.getAttributeValue( subValueAttr ));
+ }
+ statusCode.setStatusCode( subStatusCodeType );
+ }
+ else
+ break;
+ }
+
+ //Get the next end element
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if( xmlEvent instanceof EndElement )
+ {
+ EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
+ if( StaxParserUtil.matches(endElement, STATUS ))
+ break;
+ }
+ }
+ return status;
+ }
}
\ 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 2010-11-03 14:15:54 UTC (rev 519)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -47,6 +47,8 @@
ISSUE_INSTANT( "IssueInstant" ),
ISSUER( "Issuer" ),
LANG_EN("en"),
+ LOGOUT_REQUEST( "LogoutRequest" ),
+ LOGOUT_RESPONSE( "LogoutResponse" ),
METADATA_MIME("application/samlmetadata+xml"),
METHOD( "Method" ),
NAMEID( "NameID" ),
@@ -55,6 +57,7 @@
NOT_BEFORE( "NotBefore" ),
NOT_ON_OR_AFTER( "NotOnOrAfter" ),
RESPONSE( "Response" ),
+ SESSION_INDEX( "SessionIndex" ),
SP_PROVIDED_ID( "SPProvidedID" ),
SP_NAME_QUALIFIER( "SPNameQualifier" ),
SIGNATURE( "Signature" ),
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-03 14:15:54 UTC (rev 519)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -28,10 +28,10 @@
import java.util.List;
import javax.xml.bind.JAXBElement;
-import javax.xml.datatype.DatatypeFactory;
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
import org.picketlink.identity.federation.saml.v2.assertion.AudienceRestrictionType;
import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
@@ -47,9 +47,7 @@
{
@Test
public void testSAMLAssertionParsing() throws Exception
- {
- DatatypeFactory dtf = DatatypeFactory.newInstance();
-
+ {
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-assertion.xml" );
@@ -58,16 +56,14 @@
assertNotNull( assertion );
assertEquals( "ID_ab0392ef-b557-4453-95a8-a7e168da8ac5", assertion.getID() );
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.869Z" ), assertion.getIssueInstant() );
+ 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();
+ List<JAXBElement<?>> content = subject.getContent();
-
-
int size = content.size();
for( int i = 0 ; i < size; i++ )
@@ -86,8 +82,8 @@
//Conditions
ConditionsType conditions = (ConditionsType) node.getValue();
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.869Z" ) , conditions.getNotBefore() );
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T21:13:37.869Z" ) , conditions.getNotOnOrAfter() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.869Z" ) , conditions.getNotBefore() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T21:13:37.869Z" ) , conditions.getNotOnOrAfter() );
}
}
@@ -100,9 +96,7 @@
*/
@Test
public void testSAMLAssertionParsingWithAudienceRestriction() throws Exception
- {
- DatatypeFactory dtf = DatatypeFactory.newInstance();
-
+ {
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-assertion-audiencerestriction.xml" );
@@ -111,7 +105,7 @@
assertNotNull( assertion );
assertEquals( "ID_cf9efbf0-9d7f-4b4a-b77f-d83ecaafd374", assertion.getID() );
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.911Z" ), assertion.getIssueInstant() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.911Z" ), assertion.getIssueInstant() );
assertEquals( "2.0", assertion.getVersion() );
//Issuer
@@ -140,8 +134,8 @@
{
//Conditions
ConditionsType conditions = (ConditionsType) node.getValue();
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.911Z" ) , conditions.getNotBefore() );
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T21:13:37.911Z" ) , conditions.getNotOnOrAfter() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.911Z" ) , conditions.getNotBefore() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T21:13:37.911Z" ) , conditions.getNotOnOrAfter() );
//Audience Restriction
AudienceRestrictionType audienceRestrictionType =
Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -0,0 +1,57 @@
+/*
+ * 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.picketlink.test.identity.federation.core.parser.saml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+
+import org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.LogoutRequestType;
+
+/**
+ * Validate the parsing of SLO (log out) Request
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloRequestParserTestCase
+{
+ @Test
+ public void testSAMLLogOutRequestParsing() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-logout-request.xml" );
+
+ SAMLParser parser = new SAMLParser();
+ LogoutRequestType lotRequest = ( LogoutRequestType ) parser.parse(configStream);
+ assertNotNull( lotRequest );
+
+ assertEquals( "ID_c3b5ae86-7fea-4d8b-a438-a3f47d8e92c3", lotRequest.getID() );
+ assertEquals( XMLTimeUtil.parse( "2010-07-29T13:46:20.647-05:00" ), lotRequest.getIssueInstant() );
+ assertEquals( "2.0", lotRequest.getVersion() );
+ //Issuer
+ assertEquals( "http://localhost:8080/sales/", lotRequest.getIssuer().getValue() );
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java 2010-11-03 17:41:54 UTC (rev 520)
@@ -0,0 +1,64 @@
+/*
+ * 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.picketlink.test.identity.federation.core.parser.saml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+
+import org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
+
+/**
+ * Validate the parsing of SLO Response
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloResponseParserTestCase
+{
+ @Test
+ public void testSAMLResponseParse() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-logout-response.xml" );
+
+ SAMLParser parser = new SAMLParser();
+ ResponseType response = ( ResponseType ) parser.parse(configStream);
+ assertNotNull( "ResponseType is not null", response );
+
+ assertEquals( XMLTimeUtil.parse( "2010-07-29T13:46:03.862-05:00" ), response.getIssueInstant() );
+ assertEquals( "2.0", response.getVersion() );
+ assertEquals( "ID_97d332a8-3224-4653-a1ff-65c966e56852", response.getID() );
+
+ //Issuer
+ assertEquals( "http://localhost:8080/employee-post/", response.getIssuer().getValue() );
+
+ //Status
+ StatusType status = response.getStatus();
+ assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Responder", status.getStatusCode().getValue() );
+ assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Success", status.getStatusCode().getStatusCode().getValue() );
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml 2010-11-03 17:41:54 UTC (rev 520)
@@ -0,0 +1,9 @@
+<ns3:LogoutRequest xmlns:ns3="urn:oasis:names:tc:SAML:2.0:protocol"
+ xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
+ xmlns:ns2="http://www.w3.org/2000/09/xmldsig#"
+ xmlns:ns4="http://www.w3.org/2001/04/xmlenc#"
+ ID="ID_c3b5ae86-7fea-4d8b-a438-a3f47d8e92c3"
+ IssueInstant="2010-07-29T13:46:20.647-05:00"
+ Version="2.0" >
+ <Issuer>http://localhost:8080/sales/</Issuer>
+</ns3:LogoutRequest>
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml 2010-11-03 17:41:54 UTC (rev 520)
@@ -0,0 +1,15 @@
+<ns3:LogoutResponse xmlns:ns3="urn:oasis:names:tc:SAML:2.0:protocol"
+ xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
+ xmlns:ns2="http://www.w3.org/2000/09/xmldsig#"
+ xmlns:ns4="http://www.w3.org/2001/04/xmlenc#"
+ ID="ID_97d332a8-3224-4653-a1ff-65c966e56852"
+ InResponseTo="ID_230a1668-c2ab-47af-83f7-79613f9994d9"
+ IssueInstant="2010-07-29T13:46:03.862-05:00"
+ Version="2.0">
+ <Issuer>http://localhost:8080/employee-post/</Issuer>
+ <ns3:Status>
+ <ns3:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Responder">
+ <ns3:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
+ </ns3:StatusCode>
+ </ns3:Status>
+</ns3:LogoutResponse>
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r519 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v2/writers and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-03 10:15:54 -0400 (Wed, 03 Nov 2010)
New Revision: 519
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java
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/writers/SAMLRequestWriter.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java
Log:
PLFED-109: PLFED-110: add write of saml response
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 2010-11-03 03:29:36 UTC (rev 518)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-11-03 14:15:54 UTC (rev 519)
@@ -35,6 +35,7 @@
AUDIENCE_RESTRICTION( "AudienceRestriction" ),
AUTHN_CONTEXT( "AuthnContext" ),
AUTHN_CONTEXT_DECLARATION_REF( "AuthnContextDeclRef" ),
+ AUTHN_INSTANT( "AuthnInstant" ),
AUTHN_REQUEST( "AuthnRequest" ),
AUTHN_STATEMENT( "AuthnStatement" ),
CONDITIONS( "Conditions" ),
@@ -42,6 +43,7 @@
DESTINATION( "Destination" ),
FORMAT( "Format" ),
ID( "ID" ),
+ IN_RESPONSE_TO( "InResponseTo" ),
ISSUE_INSTANT( "IssueInstant" ),
ISSUER( "Issuer" ),
LANG_EN("en"),
@@ -60,8 +62,11 @@
SIGNATURE_SHA1_WITH_RSA("http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
STATUS( "Status" ),
STATUS_CODE( "StatusCode" ),
+ STATUS_DETAIL( "StatusDetail" ),
+ STATUS_MESSAGE( "StatusMessage" ),
SUBJECT( "Subject" ),
SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
+ VALUE( "Value" ),
VERSION( "Version" ),
VERSION_2_0("2.0"),
HTTP_POST_BINDING("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java 2010-11-03 14:15:54 UTC (rev 519)
@@ -0,0 +1,101 @@
+/*
+ * 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.picketlink.identity.federation.core.saml.v2.writers;
+
+import java.io.OutputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.core.util.StringUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+
+/**
+ * Base Class for the Stax writers for SAML
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 2, 2010
+ */
+public class BaseWriter
+{
+ protected static String PROTOCOL_PREFIX = "samlp";
+ protected static String ASSERTION_PREFIX = "saml";
+
+ protected XMLStreamWriter writer = null;
+
+ /**
+ * Write {@code NameIDType} to stream
+ * @param nameIDType
+ * @param tag
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( NameIDType nameIDType, QName tag, OutputStream out ) throws ProcessingException
+ {
+ if( writer == null )
+ writer = StaxUtil.getXMLStreamWriter( out );
+
+ StaxUtil.writeStartElement( writer, tag.getPrefix(), tag.getLocalPart() , tag.getNamespaceURI() );
+
+ String format = nameIDType.getFormat();
+ if( StringUtil.isNotNull( format ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORMAT.get(), format );
+ }
+
+ String spProvidedID = nameIDType.getSPProvidedID();
+ if( StringUtil.isNotNull( spProvidedID ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_PROVIDED_ID.get(), spProvidedID );
+ }
+
+ String spNameQualifier = nameIDType.getSPNameQualifier();
+ if( StringUtil.isNotNull( spNameQualifier ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(), spNameQualifier );
+ }
+
+ String nameQualifier = nameIDType.getNameQualifier();
+ if( StringUtil.isNotNull( nameQualifier ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME_QUALIFIER.get(), nameQualifier );
+ }
+
+ String value = nameIDType.getValue();
+ if( StringUtil.isNotNull( value ))
+ {
+ StaxUtil.writeCharacters( writer, value );
+ }
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ protected void verifyWriter( OutputStream out ) throws ProcessingException
+ {
+ if( writer == null )
+ writer = StaxUtil.getXMLStreamWriter( out );
+ }
+
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2010-11-03 14:15:54 UTC (rev 519)
@@ -0,0 +1,154 @@
+/*
+ * 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.picketlink.identity.federation.core.saml.v2.writers;
+
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.ASSERTION_NSURI;
+
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType;
+import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.StatementAbstractType;
+
+/**
+ * Write the SAML Assertion to stream
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 2, 2010
+ */
+public class SAMLAssertionWriter extends BaseWriter
+{
+ /**
+ * Write an {@code AssertionType} to stream
+ * @param assertion
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( AssertionType assertion, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.ASSERTION.get() , ASSERTION_NSURI.get() );
+ StaxUtil.writeNameSpace( writer, ASSERTION_PREFIX, ASSERTION_NSURI.get() );
+ StaxUtil.WriteDefaultNameSpace( writer, ASSERTION_NSURI.get() );
+
+ //Attributes
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ID.get(), assertion.getID() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.VERSION.get(), assertion.getVersion() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ISSUE_INSTANT.get(), assertion.getIssueInstant().toString() );
+
+ NameIDType issuer = assertion.getIssuer();
+ write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out );
+
+ List<StatementAbstractType> statements = assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement();
+ if( statements != null )
+ {
+ for( StatementAbstractType statement: statements )
+ {
+ if( statement instanceof AuthnStatementType )
+ {
+ write( ( AuthnStatementType )statement, out );
+ }
+ else write( statement, out );
+ }
+ }
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write an {@code StatementAbstractType} to stream
+ * @param statement
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( StatementAbstractType statement, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+ //TODO: handle this section
+ }
+
+ /**
+ * Write an {@code AuthnStatementType} to stream
+ * @param authnStatement
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( AuthnStatementType authnStatement, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_STATEMENT.get() , ASSERTION_NSURI.get() );
+
+ XMLGregorianCalendar authnInstant = authnStatement.getAuthnInstant();
+ if( authnInstant != null )
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.AUTHN_INSTANT.get(), authnInstant.toString() );
+ }
+
+ AuthnContextType authnContext = authnStatement.getAuthnContext();
+ if( authnContext != null )
+ write( authnContext, out );
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write an {@code AuthnContextType} to stream
+ * @param authContext
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( AuthnContextType authContext, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT.get() , ASSERTION_NSURI.get() );
+
+ List< JAXBElement<?> > subList = authContext.getContent();
+ if( subList != null )
+ {
+ for( JAXBElement<?> el: subList )
+ {
+ QName elName = el.getName();
+ if( elName.getLocalPart().equals( JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get() ))
+ {
+ String decl = (String) el.getValue();
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get() ,
+ ASSERTION_NSURI.get() );
+ StaxUtil.writeCharacters( writer, decl );
+ StaxUtil.writeEndElement( writer);
+ }
+ else
+ throw new RuntimeException( "Unsupported :" + elName );
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java 2010-11-03 03:29:36 UTC (rev 518)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java 2010-11-03 14:15:54 UTC (rev 519)
@@ -27,7 +27,6 @@
import java.io.OutputStream;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamWriter;
import org.picketlink.identity.federation.core.exceptions.ProcessingException;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
@@ -42,12 +41,8 @@
* @author Anil.Saldhana(a)redhat.com
* @since Nov 2, 2010
*/
-public class SAMLRequestWriter
-{
- private static String PROTOCOL_PREFIX = "samlp";
-
- private XMLStreamWriter writer = null;
-
+public class SAMLRequestWriter extends BaseWriter
+{
/**
* Write a {@code AuthnRequestType } to stream
* @param request
@@ -56,9 +51,7 @@
*/
public void write( AuthnRequestType request, OutputStream out ) throws ProcessingException
{
- //Get the XML writer
- if( writer == null )
- writer = StaxUtil.getXMLStreamWriter( out );
+ verifyWriter( out );
StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.AUTHN_REQUEST.get() , PROTOCOL_NSURI.get() );
@@ -94,54 +87,6 @@
}
/**
- * Write {@code NameIDType} to stream
- * @param nameIDType
- * @param tag
- * @param out
- * @throws ProcessingException
- */
- public void write( NameIDType nameIDType, QName tag, OutputStream out ) throws ProcessingException
- {
- if( writer == null )
- writer = StaxUtil.getXMLStreamWriter( out );
-
- StaxUtil.writeStartElement( writer, tag.getPrefix(), tag.getLocalPart() , tag.getNamespaceURI() );
-
- String format = nameIDType.getFormat();
- if( StringUtil.isNotNull( format ))
- {
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORMAT.get(), format );
- }
-
- String spProvidedID = nameIDType.getSPProvidedID();
- if( StringUtil.isNotNull( spProvidedID ))
- {
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_PROVIDED_ID.get(), spProvidedID );
- }
-
- String spNameQualifier = nameIDType.getSPNameQualifier();
- if( StringUtil.isNotNull( spNameQualifier ))
- {
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(), spNameQualifier );
- }
-
- String nameQualifier = nameIDType.getNameQualifier();
- if( StringUtil.isNotNull( nameQualifier ))
- {
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME_QUALIFIER.get(), nameQualifier );
- }
-
- String value = nameIDType.getValue();
- if( StringUtil.isNotNull( value ))
- {
- StaxUtil.writeCharacters( writer, value );
- }
-
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
- }
-
- /**
* Write a {@code NameIDPolicyType} to stream
* @param nameIDPolicy
* @param out
@@ -149,8 +94,7 @@
*/
public void write( NameIDPolicyType nameIDPolicy, OutputStream out ) throws ProcessingException
{
- if( writer == null )
- writer = StaxUtil.getXMLStreamWriter( out );
+ verifyWriter( out );
StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.NAMEID_POLICY.get(), PROTOCOL_NSURI.get() );
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java 2010-11-03 14:15:54 UTC (rev 519)
@@ -0,0 +1,181 @@
+/*
+ * 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.picketlink.identity.federation.core.saml.v2.writers;
+
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.ASSERTION_NSURI;
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.PROTOCOL_NSURI;
+
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.core.util.StringUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusDetailType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
+
+/**
+ * Write a SAML Response to stream
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 2, 2010
+ */
+public class SAMLResponseWriter extends BaseWriter
+{
+ private SAMLAssertionWriter assertionWriter = new SAMLAssertionWriter();
+ /**
+ * Write a {@code ResponseType} to stream
+ * @param response
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( ResponseType response, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.RESPONSE.get() , PROTOCOL_NSURI.get() );
+
+ StaxUtil.writeNameSpace( writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get() );
+ StaxUtil.WriteDefaultNameSpace( writer, ASSERTION_NSURI.get() );
+
+ writeBaseAttributes( response );
+
+ NameIDType issuer = response.getIssuer();
+ write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out );
+
+ StatusType status = response.getStatus();
+ write( status, out );
+
+ List<Object> assertions = response.getAssertionOrEncryptedAssertion();
+ if( assertions != null )
+ {
+ for( Object assertion: assertions )
+ {
+ if( assertion instanceof AssertionType )
+ {
+ assertionWriter.write( (AssertionType) assertion, out );
+ }
+ }
+ }
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write a {@code StatusType} to stream
+ * @param status
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( StatusType status, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS.get() , PROTOCOL_NSURI.get() );
+
+ StatusCodeType statusCodeType = status.getStatusCode();
+ write( statusCodeType , out );
+
+ String statusMessage = status.getStatusMessage();
+ if( StringUtil.isNotNull( statusMessage ))
+ {
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_MESSAGE.get() , PROTOCOL_NSURI.get() );
+ StaxUtil.writeEndElement( writer);
+ }
+
+ StatusDetailType statusDetail = status.getStatusDetail();
+ if( statusDetail != null )
+ write( statusDetail, out );
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write a {@code StatusCodeType} to stream
+ * @param statusCodeType
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( StatusCodeType statusCodeType, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_CODE.get() , PROTOCOL_NSURI.get() );
+
+ String value = statusCodeType.getValue();
+ if( StringUtil.isNotNull( value ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.VALUE.get(), value );
+ }
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write a {@code StatusDetailType} to stream
+ * @param statusDetailType
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( StatusDetailType statusDetailType, OutputStream out ) throws ProcessingException
+ {
+ verifyWriter( out );
+
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_CODE.get() , PROTOCOL_NSURI.get() );
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write the common attributes for all response types
+ * @param statusResponse
+ * @throws ProcessingException
+ */
+ private void writeBaseAttributes( StatusResponseType statusResponse ) throws ProcessingException
+ {
+ //Attributes
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ID.get(), statusResponse.getID() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.VERSION.get(), statusResponse.getVersion() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ISSUE_INSTANT.get(), statusResponse.getIssueInstant().toString() );
+
+ String destination = statusResponse.getDestination();
+ if( StringUtil.isNotNull( destination ))
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.DESTINATION.get(), destination );
+
+ String consent = statusResponse.getConsent();
+ if( StringUtil.isNotNull( consent ))
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.CONSENT.get(), consent );
+
+ String inResponseTo = statusResponse.getInResponseTo();
+ if( StringUtil.isNotNull( inResponseTo ))
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.IN_RESPONSE_TO.get(), inResponseTo );
+ }
+}
\ No newline at end of file
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 2010-11-03 03:29:36 UTC (rev 518)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java 2010-11-03 14:15:54 UTC (rev 519)
@@ -32,6 +32,7 @@
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLResponseWriter;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
@@ -89,5 +90,9 @@
assertEquals( XMLTimeUtil.parse( "2009-05-26T14:06:26.359-05:00" ), authnStatement.getAuthnInstant() );
authnContextDeclRefJaxb = (JAXBElement<?>) authnStatement.getAuthnContext().getContent().get(0);
assertEquals( "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", authnContextDeclRefJaxb.getValue() );
+
+ //Let us do some writing - currently only visual inspection. We will do proper validation later.
+ SAMLResponseWriter writer = new SAMLResponseWriter();
+ writer.write(response, System.out );
}
}
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r518 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v2/constants and 3 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-02 23:29:36 -0400 (Tue, 02 Nov 2010)
New Revision: 518
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
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/util/StaxUtil.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAuthnRequestParserTestCase.java
Log:
PLFED-109: PLFED-110: add write of saml request
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 2010-11-02 23:41:04 UTC (rev 517)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-11-03 03:29:36 UTC (rev 518)
@@ -28,7 +28,9 @@
*/
public enum JBossSAMLConstants
{
+ ALLOW_CREATE( "AllowCreate" ),
ASSERTION( "Assertion" ),
+ ASSERTION_CONSUMER_SERVICE_URL( "AssertionConsumerServiceURL" ),
AUDIENCE( "Audience" ),
AUDIENCE_RESTRICTION( "AudienceRestriction" ),
AUTHN_CONTEXT( "AuthnContext" ),
@@ -36,6 +38,9 @@
AUTHN_REQUEST( "AuthnRequest" ),
AUTHN_STATEMENT( "AuthnStatement" ),
CONDITIONS( "Conditions" ),
+ CONSENT( "Consent" ),
+ DESTINATION( "Destination" ),
+ FORMAT( "Format" ),
ID( "ID" ),
ISSUE_INSTANT( "IssueInstant" ),
ISSUER( "Issuer" ),
@@ -48,6 +53,8 @@
NOT_BEFORE( "NotBefore" ),
NOT_ON_OR_AFTER( "NotOnOrAfter" ),
RESPONSE( "Response" ),
+ SP_PROVIDED_ID( "SPProvidedID" ),
+ SP_NAME_QUALIFIER( "SPNameQualifier" ),
SIGNATURE( "Signature" ),
SIGNATURE_SHA1_WITH_DSA("http://www.w3.org/2000/09/xmldsig#dsa-sha1"),
SIGNATURE_SHA1_WITH_RSA("http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java 2010-11-03 03:29:36 UTC (rev 518)
@@ -0,0 +1,178 @@
+/*
+ * 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.picketlink.identity.federation.core.saml.v2.writers;
+
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.ASSERTION_NSURI;
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.PROTOCOL_NSURI;
+
+import java.io.OutputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.core.util.StringUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
+import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
+
+/**
+ * Writes a SAML2 Request Type to Stream
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 2, 2010
+ */
+public class SAMLRequestWriter
+{
+ private static String PROTOCOL_PREFIX = "samlp";
+
+ private XMLStreamWriter writer = null;
+
+ /**
+ * Write a {@code AuthnRequestType } to stream
+ * @param request
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( AuthnRequestType request, OutputStream out ) throws ProcessingException
+ {
+ //Get the XML writer
+ if( writer == null )
+ writer = StaxUtil.getXMLStreamWriter( out );
+
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.AUTHN_REQUEST.get() , PROTOCOL_NSURI.get() );
+
+ StaxUtil.writeNameSpace( writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get() );
+ StaxUtil.WriteDefaultNameSpace( writer, ASSERTION_NSURI.get() );
+
+ //Attributes
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ID.get(), request.getID() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.VERSION.get(), request.getVersion() );
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString() );
+
+ String destination = request.getDestination();
+ if( StringUtil.isNotNull( destination ))
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.DESTINATION.get(), destination );
+
+ String consent = request.getConsent();
+ if( StringUtil.isNotNull( consent ))
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.CONSENT.get(), consent );
+
+ String assertionURL = request.getAssertionConsumerServiceURL();
+ if( StringUtil.isNotNull( assertionURL ) )
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_URL.get(), assertionURL );
+
+ NameIDType issuer = request.getIssuer();
+ write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out );
+
+ NameIDPolicyType nameIDPolicy = request.getNameIDPolicy();
+ if( nameIDPolicy != null )
+ write( nameIDPolicy, out );
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write {@code NameIDType} to stream
+ * @param nameIDType
+ * @param tag
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( NameIDType nameIDType, QName tag, OutputStream out ) throws ProcessingException
+ {
+ if( writer == null )
+ writer = StaxUtil.getXMLStreamWriter( out );
+
+ StaxUtil.writeStartElement( writer, tag.getPrefix(), tag.getLocalPart() , tag.getNamespaceURI() );
+
+ String format = nameIDType.getFormat();
+ if( StringUtil.isNotNull( format ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORMAT.get(), format );
+ }
+
+ String spProvidedID = nameIDType.getSPProvidedID();
+ if( StringUtil.isNotNull( spProvidedID ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_PROVIDED_ID.get(), spProvidedID );
+ }
+
+ String spNameQualifier = nameIDType.getSPNameQualifier();
+ if( StringUtil.isNotNull( spNameQualifier ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(), spNameQualifier );
+ }
+
+ String nameQualifier = nameIDType.getNameQualifier();
+ if( StringUtil.isNotNull( nameQualifier ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME_QUALIFIER.get(), nameQualifier );
+ }
+
+ String value = nameIDType.getValue();
+ if( StringUtil.isNotNull( value ))
+ {
+ StaxUtil.writeCharacters( writer, value );
+ }
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+
+ /**
+ * Write a {@code NameIDPolicyType} to stream
+ * @param nameIDPolicy
+ * @param out
+ * @throws ProcessingException
+ */
+ public void write( NameIDPolicyType nameIDPolicy, OutputStream out ) throws ProcessingException
+ {
+ if( writer == null )
+ writer = StaxUtil.getXMLStreamWriter( out );
+
+ StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.NAMEID_POLICY.get(), PROTOCOL_NSURI.get() );
+
+ String format = nameIDPolicy.getFormat();
+ if( StringUtil.isNotNull( format ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORMAT.get(), format );
+ }
+
+ String spNameQualifier = nameIDPolicy.getSPNameQualifier();
+ if( StringUtil.isNotNull( spNameQualifier ))
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(), spNameQualifier );
+ }
+
+ Boolean allowCreate = nameIDPolicy.isAllowCreate();
+ if( allowCreate != null )
+ {
+ StaxUtil.writeAttribute( writer, JBossSAMLConstants.ALLOW_CREATE.get(), allowCreate.toString() );
+ }
+
+ StaxUtil.writeEndElement( writer);
+ StaxUtil.flush( writer );
+ }
+}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2010-11-02 23:41:04 UTC (rev 517)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2010-11-03 03:29:36 UTC (rev 518)
@@ -130,6 +130,24 @@
}
/**
+ * Write the default namespace
+ * @param writer
+ * @param ns
+ * @throws ProcessingException
+ */
+ public static void WriteDefaultNameSpace( XMLStreamWriter writer, String ns ) throws ProcessingException
+ {
+ try
+ {
+ writer.writeDefaultNamespace( ns );
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ProcessingException( e );
+ }
+ }
+
+ /**
* Write a namespace
* @param writer
* @param prefix prefix
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAuthnRequestParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAuthnRequestParserTestCase.java 2010-11-02 23:41:04 UTC (rev 517)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAuthnRequestParserTestCase.java 2010-11-03 03:29:36 UTC (rev 518)
@@ -29,6 +29,7 @@
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLRequestWriter;
import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
@@ -64,5 +65,9 @@
NameIDPolicyType nameIDPolicy = authnRequest.getNameIDPolicy();
assertEquals( "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified", nameIDPolicy.getFormat() );
assertEquals( Boolean.TRUE , nameIDPolicy.isAllowCreate() );
+
+ //Try out writing
+ SAMLRequestWriter writer = new SAMLRequestWriter();
+ writer.write(authnRequest, System.out );
}
}
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r517 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-02 19:41:04 -0400 (Tue, 02 Nov 2010)
New Revision: 517
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
Log:
PLFED-109: PLFED-110: add some base class
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-02 22:39:23 UTC (rev 516)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-02 23:41:04 UTC (rev 517)
@@ -31,7 +31,6 @@
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
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.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
@@ -41,7 +40,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Nov 2, 2010
*/
-public class SAMLAuthNRequestParser implements ParserNamespaceSupport
+public class SAMLAuthNRequestParser extends SAMLRequestAbstractParser implements ParserNamespaceSupport
{
/**
* @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
@@ -101,10 +100,7 @@
{
AuthnRequestType authnRequest = new AuthnRequestType();
//Let us get the attributes
- Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
- if( idAttr == null )
- throw new RuntimeException( "ID attribute is missing" );
- authnRequest.setID( StaxParserUtil.getAttributeValue( idAttr ));
+ super.parseBaseAttributes(startElement, authnRequest );
Attribute assertionConsumerServiceURL = startElement.getAttributeByName( new QName( "AssertionConsumerServiceURL" ));
if( assertionConsumerServiceURL != null )
@@ -114,15 +110,6 @@
if( assertionConsumerServiceIndex != null )
authnRequest.setAssertionConsumerServiceIndex( Integer.parseInt( StaxParserUtil.getAttributeValue( assertionConsumerServiceIndex )));
- Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
- if( destination != null )
- authnRequest.setDestination( StaxParserUtil.getAttributeValue( destination ));
-
- Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
- if( issueInstant == null )
- throw new RuntimeException( "IssueInstant attribute required in AuthnRequest" );
- authnRequest.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant )));
-
Attribute protocolBinding = startElement.getAttributeByName( new QName( "ProtocolBinding" ));
if( protocolBinding != null )
authnRequest.setProtocolBinding( StaxParserUtil.getAttributeValue( protocolBinding ));
@@ -131,15 +118,6 @@
if( providerName != null )
authnRequest.setProviderName( StaxParserUtil.getAttributeValue( providerName ));
- Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
- if( consent != null )
- authnRequest.setConsent( StaxParserUtil.getAttributeValue( consent ));
-
- Attribute version = startElement.getAttributeByName( new QName( "Version" ));
- if( version == null )
- throw new RuntimeException( "Version attribute required in AuthnRequest" );
- authnRequest.setVersion( StaxParserUtil.getAttributeValue( version ));
-
Attribute forceAuthn = startElement.getAttributeByName( new QName( "ForceAuthn" ));
if( forceAuthn != null )
{
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java 2010-11-02 23:41:04 UTC (rev 517)
@@ -0,0 +1,71 @@
+/*
+ * 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.picketlink.identity.federation.core.parsers.saml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.RequestAbstractType;
+
+/**
+ * Base Class for SAML Request Parsing
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 2, 2010
+ */
+public abstract class SAMLRequestAbstractParser
+{
+ /**
+ * Parse the attributes that are common to all SAML Request Types
+ * @param startElement
+ * @param request
+ * @throws ParsingException
+ */
+ protected void parseBaseAttributes( StartElement startElement , RequestAbstractType request ) throws ParsingException
+ {
+ Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
+ if( idAttr == null )
+ throw new RuntimeException( "ID attribute is missing" );
+ request.setID( StaxParserUtil.getAttributeValue( idAttr ));
+
+ Attribute version = startElement.getAttributeByName( new QName( "Version" ));
+ if( version == null )
+ throw new RuntimeException( "Version attribute required in Request" );
+ request.setVersion( StaxParserUtil.getAttributeValue( version ));
+
+ Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
+ if( issueInstant == null )
+ throw new RuntimeException( "IssueInstant attribute required in Request" );
+ request.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant )));
+
+ Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
+ if( destination != null )
+ request.setDestination( StaxParserUtil.getAttributeValue( destination ));
+
+ Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
+ if( consent != null )
+ request.setConsent( StaxParserUtil.getAttributeValue( consent ));
+ }
+}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java 2010-11-02 22:39:23 UTC (rev 516)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java 2010-11-02 23:41:04 UTC (rev 517)
@@ -34,7 +34,6 @@
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
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.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
@@ -45,7 +44,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Nov 2, 2010
*/
-public class SAMLResponseParser implements ParserNamespaceSupport
+public class SAMLResponseParser extends SAMLStatusResponseTypeParser implements ParserNamespaceSupport
{
private String RESPONSE = JBossSAMLConstants.RESPONSE.get();
/**
@@ -111,29 +110,8 @@
private ResponseType parseBaseAttributes( StartElement startElement ) throws ParsingException
{
ResponseType response = new ResponseType();
- //Let us get the attributes
- Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
- if( idAttr == null )
- throw new RuntimeException( "ID attribute is missing" );
- response.setID( StaxParserUtil.getAttributeValue( idAttr ));
+ super.parseBaseAttributes( startElement, response );
- Attribute inResponseTo = startElement.getAttributeByName( new QName( "InResponseTo" ));
- if( inResponseTo != null )
- response.setInResponseTo( StaxParserUtil.getAttributeValue( inResponseTo ));
-
- Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
- if( destination != null )
- response.setDestination( StaxParserUtil.getAttributeValue( destination ));
-
- Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
- if( issueInstant != null )
- {
- response.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant )));
- }
-
- Attribute version = startElement.getAttributeByName( new QName( "Version" ));
- if( version != null )
- response.setVersion( StaxParserUtil.getAttributeValue( version ));
return response;
}
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java 2010-11-02 23:41:04 UTC (rev 517)
@@ -0,0 +1,76 @@
+/*
+ * 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.picketlink.identity.federation.core.parsers.saml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
+
+/**
+ * Base Class for all Response Type parsing for SAML2
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 2, 2010
+ */
+public abstract class SAMLStatusResponseTypeParser
+{
+ /**
+ * Parse the attributes that are common to all SAML Response Types
+ * @param startElement
+ * @param response
+ * @throws ParsingException
+ */
+ protected void parseBaseAttributes( StartElement startElement , StatusResponseType response ) throws ParsingException
+ {
+ Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
+ if( idAttr == null )
+ throw new RuntimeException( "ID attribute is missing" );
+ response.setID( StaxParserUtil.getAttributeValue( idAttr ));
+
+ Attribute version = startElement.getAttributeByName( new QName( "Version" ));
+ if( version == null )
+ throw new RuntimeException( "Version attribute required in Response" );
+ response.setVersion( StaxParserUtil.getAttributeValue( version ));
+
+ Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
+ if( issueInstant == null )
+ throw new RuntimeException( "IssueInstant attribute required in Response" );
+ response.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant )));
+
+ Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
+ if( destination != null )
+ response.setDestination( StaxParserUtil.getAttributeValue( destination ));
+
+ Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
+ if( consent != null )
+ response.setConsent( StaxParserUtil.getAttributeValue( consent ));
+
+ Attribute inResponseTo = startElement.getAttributeByName( new QName( "InResponseTo" ));
+ if( inResponseTo != null )
+ response.setInResponseTo( StaxParserUtil.getAttributeValue( inResponseTo ));
+ }
+
+}
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r516 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-11-02 18:39:23 -0400 (Tue, 02 Nov 2010)
New Revision: 516
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
Log:
PLFED-109: PLFED-110: add some addtl attribs
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-11-02 22:23:16 UTC (rev 515)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-11-02 22:39:23 UTC (rev 516)
@@ -24,7 +24,6 @@
import javax.xml.bind.JAXBElement;
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.EndElement;
import javax.xml.stream.events.StartElement;
@@ -191,8 +190,14 @@
StaxParserUtil.matches( startElement, AUTHNSTATEMENT );
Attribute authnInstant = startElement.getAttributeByName( new QName( "AuthnInstant" ));
+ if( authnInstant == null )
+ throw new RuntimeException( "Required attribute AuthnInstant in " + AUTHNSTATEMENT );
authnStatementType.setAuthnInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( authnInstant )));
+ 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();
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-02 22:23:16 UTC (rev 515)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-02 22:39:23 UTC (rev 516)
@@ -108,17 +108,20 @@
Attribute assertionConsumerServiceURL = startElement.getAttributeByName( new QName( "AssertionConsumerServiceURL" ));
if( assertionConsumerServiceURL != null )
- authnRequest.setAssertionConsumerServiceURL( StaxParserUtil.getAttributeValue( assertionConsumerServiceURL ));
+ authnRequest.setAssertionConsumerServiceURL( StaxParserUtil.getAttributeValue( assertionConsumerServiceURL ));
+
+ Attribute assertionConsumerServiceIndex = startElement.getAttributeByName( new QName( "AssertionConsumerServiceIndex" ));
+ if( assertionConsumerServiceIndex != null )
+ authnRequest.setAssertionConsumerServiceIndex( Integer.parseInt( StaxParserUtil.getAttributeValue( assertionConsumerServiceIndex )));
Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
if( destination != null )
authnRequest.setDestination( StaxParserUtil.getAttributeValue( destination ));
Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
- if( issueInstant != null )
- {
- authnRequest.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant )));
- }
+ if( issueInstant == null )
+ throw new RuntimeException( "IssueInstant attribute required in AuthnRequest" );
+ authnRequest.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant )));
Attribute protocolBinding = startElement.getAttributeByName( new QName( "ProtocolBinding" ));
if( protocolBinding != null )
@@ -128,9 +131,31 @@
if( providerName != null )
authnRequest.setProviderName( StaxParserUtil.getAttributeValue( providerName ));
+ Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
+ if( consent != null )
+ authnRequest.setConsent( StaxParserUtil.getAttributeValue( consent ));
+
Attribute version = startElement.getAttributeByName( new QName( "Version" ));
- if( version != null )
- authnRequest.setVersion( StaxParserUtil.getAttributeValue( version ));
+ if( version == null )
+ throw new RuntimeException( "Version attribute required in AuthnRequest" );
+ authnRequest.setVersion( StaxParserUtil.getAttributeValue( version ));
+
+ Attribute forceAuthn = startElement.getAttributeByName( new QName( "ForceAuthn" ));
+ if( forceAuthn != null )
+ {
+ authnRequest.setForceAuthn( Boolean.parseBoolean( StaxParserUtil.getAttributeValue( forceAuthn ) ));
+ }
+
+ Attribute isPassive = startElement.getAttributeByName( new QName( "IsPassive" ));
+ if( isPassive != null )
+ {
+ authnRequest.setIsPassive( Boolean.parseBoolean( StaxParserUtil.getAttributeValue( isPassive ) ));
+ }
+
+ Attribute attributeConsumingServiceIndex = startElement.getAttributeByName( new QName( "AttributeConsumingServiceIndex" ));
+ if( attributeConsumingServiceIndex != null )
+ authnRequest.setAttributeConsumingServiceIndex( Integer.parseInt( StaxParserUtil.getAttributeValue( attributeConsumingServiceIndex )));
+
return authnRequest;
}
14 years, 2 months