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