Author: anil.saldhana(a)jboss.com
Date: 2011-06-29 14:36:59 -0400 (Wed, 29 Jun 2011)
New Revision: 1041
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/BaseSAML11Writer.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11RequestWriter.java
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/SAML11Constants.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java
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/SAMLMetadataWriter.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/SAML11AssertionParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11RequestParserTestCase.java
Log:
PLFED-192: writing
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/SAML11Constants.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/SAML11Constants.java 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/SAML11Constants.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -72,6 +72,8 @@
String DNS_ADDRESS = "DNSAddress";
+ String EVIDENCE = "Evidence";
+
String FORMAT = "Format";
String FORMAT_EMAIL_ADDRESS =
"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/BaseSAML11Writer.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/BaseSAML11Writer.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/BaseSAML11Writer.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -0,0 +1,48 @@
+/*
+ * 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.v1.writers;
+
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jun 27, 2011
+ */
+public abstract class BaseSAML11Writer
+{
+ protected static String PROTOCOL_PREFIX = "samlp";
+
+ protected static String ASSERTION_PREFIX = "saml";
+
+ protected static String XACML_SAML_PREFIX = "xacml-saml";
+
+ protected static String XACML_SAML_PROTO_PREFIX = "xacml-samlp";
+
+ protected static String XSI_PREFIX = "xsi";
+
+ protected XMLStreamWriter writer;
+
+ public BaseSAML11Writer(XMLStreamWriter writer)
+ {
+ this.writer = writer;
+ }
+}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -30,6 +30,7 @@
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.v1.assertion.SAML11ActionType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AdviceType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AssertionType;
import
org.picketlink.identity.federation.saml.v1.assertion.SAML11AttributeStatementType;
@@ -40,6 +41,7 @@
import
org.picketlink.identity.federation.saml.v1.assertion.SAML11AuthorizationDecisionStatementType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11ConditionAbstractType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11ConditionsType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11EvidenceType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11NameIdentifierType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11StatementAbstractType;
import
org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectConfirmationType;
@@ -57,24 +59,13 @@
* @author Anil.Saldhana(a)redhat.com
* @since June 24, 2011
*/
-public class SAML11AssertionWriter
+public class SAML11AssertionWriter extends BaseSAML11Writer
{
+ String ns = SAML11Constants.ASSERTION_11_NSURI;
- protected static String PROTOCOL_PREFIX = "samlp";
-
- protected static String ASSERTION_PREFIX = "saml";
-
- protected static String XACML_SAML_PREFIX = "xacml-saml";
-
- protected static String XACML_SAML_PROTO_PREFIX = "xacml-samlp";
-
- protected static String XSI_PREFIX = "xsi";
-
- protected XMLStreamWriter writer;
-
- public SAML11AssertionWriter(XMLStreamWriter writer) throws ProcessingException
+ public SAML11AssertionWriter(XMLStreamWriter writer)
{
- this.writer = writer;
+ super(writer);
}
/**
@@ -86,7 +77,6 @@
*/
public void write(SAML11AssertionType assertion) throws ProcessingException
{
- String ns = SAML11Constants.ASSERTION_11_NSURI;
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.ASSERTION.get(), ns);
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ns);
StaxUtil.writeDefaultNameSpace(writer, ns);
@@ -227,7 +217,7 @@
*/
public void write(SAML11AuthenticationStatementType authnStatement) throws
ProcessingException
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_STATEMENT.get(),
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
SAML11Constants.AUTHENTICATION_STATEMENT,
SAML11Constants.ASSERTION_11_NSURI);
XMLGregorianCalendar authnInstant = authnStatement.getAuthenticationInstant();
@@ -296,7 +286,6 @@
public void write(SAML11AuthorizationDecisionStatementType xacmlStat) throws
ProcessingException
{
- String ns = SAML11Constants.ASSERTION_11_NSURI;
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
SAML11Constants.AUTHORIZATION_DECISION_STATEMENT, ns);
String resource = xacmlStat.getResource().toString();
@@ -323,6 +312,7 @@
{
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.SUBJECT.get(),
SAML11Constants.ASSERTION_11_NSURI);
+ StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ns);
SAML11SubjectTypeChoice choice = subject.getChoice();
if (choice != null)
@@ -369,7 +359,10 @@
}
Object subjectConfirmationData = confirmation.getSubjectConfirmationData();
- writeSubjectConfirmationData(subjectConfirmationData);
+ if (subjectConfirmationData != null)
+ {
+ writeSubjectConfirmationData(subjectConfirmationData);
+ }
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
@@ -411,7 +404,6 @@
*/
public void write(SAML11AttributeType attributeType) throws ProcessingException
{
- String ns = SAML11Constants.ASSERTION_11_NSURI;
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.ATTRIBUTE.get(), ns);
writeAttributeTypeWithoutRootTag(attributeType);
@@ -449,7 +441,6 @@
public void writeStringAttributeValue(String attributeValue) throws
ProcessingException
{
- String ns = SAML11Constants.ASSERTION_11_NSURI;
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.ATTRIBUTE_VALUE.get(), ns);
StaxUtil.writeNameSpace(writer, JBossSAMLURIConstants.XSI_PREFIX.get(),
JBossSAMLURIConstants.XSI_NSURI.get());
@@ -469,4 +460,40 @@
StaxUtil.writeCharacters(writer, localizedNameType.getValue());
StaxUtil.writeEndElement(writer);
}
+
+ public void write(SAML11ActionType action) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.ACTION, ns);
+ String ns = action.getNamespace();
+ if (StringUtil.isNotNull(ns))
+ {
+ StaxUtil.writeAttribute(writer, SAML11Constants.NAMESPACE, ns);
+ }
+ String val = action.getValue();
+ if (StringUtil.isNotNull(val))
+ {
+ StaxUtil.writeCharacters(writer, val);
+ }
+ StaxUtil.writeEndElement(writer);
+ }
+
+ public void write(SAML11EvidenceType evidence) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.EVIDENCE,
ns);
+
+ List<String> assertionIDRefs = evidence.getAssertionIDReference();
+ for (String assertionIDRef : assertionIDRefs)
+ {
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
SAML11Constants.ASSERTION_ID_REF, ns);
+ StaxUtil.writeCharacters(writer, assertionIDRef);
+ StaxUtil.writeEndElement(writer);
+ }
+
+ List<SAML11AssertionType> assertions = evidence.getAssertions();
+ for (SAML11AssertionType assertion : assertions)
+ {
+ write(assertion);
+ }
+ StaxUtil.writeEndElement(writer);
+ }
}
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11RequestWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11RequestWriter.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11RequestWriter.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -0,0 +1,198 @@
+/*
+ * 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.v1.writers;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v1.SAML11Constants;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11ActionType;
+import
org.picketlink.identity.federation.saml.v1.assertion.SAML11AttributeDesignatorType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11AttributeType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11EvidenceType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectType;
+import org.picketlink.identity.federation.saml.v1.protocol.SAML11AttributeQueryType;
+import
org.picketlink.identity.federation.saml.v1.protocol.SAML11AuthenticationQueryType;
+import
org.picketlink.identity.federation.saml.v1.protocol.SAML11AuthorizationDecisionQueryType;
+import org.picketlink.identity.federation.saml.v1.protocol.SAML11QueryAbstractType;
+import org.picketlink.identity.federation.saml.v1.protocol.SAML11RequestType;
+
+/**
+ * Write the {@link SAML11RequestType} to stream
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jun 27, 2011
+ */
+public class SAML11RequestWriter extends BaseSAML11Writer
+{
+ protected String namespace = SAML11Constants.PROTOCOL_11_NSURI;
+
+ protected SAML11AssertionWriter assertionWriter;
+
+ public SAML11RequestWriter(XMLStreamWriter writer)
+ {
+ super(writer);
+ assertionWriter = new SAML11AssertionWriter(writer);
+ }
+
+ public void write(SAML11RequestType request) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.REQUEST,
namespace);
+ StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
+ StaxUtil.writeDefaultNameSpace(writer, namespace);
+
+ // Attributes
+ StaxUtil.writeAttribute(writer, SAML11Constants.REQUEST_ID, request.getID());
+ StaxUtil.writeAttribute(writer, SAML11Constants.MAJOR_VERSION,
request.getMajorVersion() + "");
+ StaxUtil.writeAttribute(writer, SAML11Constants.MINOR_VERSION,
request.getMinorVersion() + "");
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(),
request.getIssueInstant().toString());
+
+ List<String> assertionIDRefs = request.getAssertionIDRef();
+ for (String assertionIDRef : assertionIDRefs)
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
SAML11Constants.ASSERTION_ID_REF, namespace);
+ StaxUtil.writeCharacters(writer, assertionIDRef);
+ StaxUtil.writeEndElement(writer);
+ }
+
+ List<String> assertionArtifacts = request.getAssertionArtifact();
+ for (String assertionArtifact : assertionArtifacts)
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
SAML11Constants.ASSERTION_ARTIFACT, namespace);
+ StaxUtil.writeCharacters(writer, assertionArtifact);
+ StaxUtil.writeEndElement(writer);
+ }
+
+ SAML11QueryAbstractType query = request.getQuery();
+ if (query instanceof SAML11AuthenticationQueryType)
+ {
+ SAML11AuthenticationQueryType authQuery = (SAML11AuthenticationQueryType)
query;
+ write(authQuery);
+ }
+ else if (query instanceof SAML11AttributeQueryType)
+ {
+ SAML11AttributeQueryType attQuery = (SAML11AttributeQueryType) query;
+ write(attQuery);
+ }
+ else if (query instanceof SAML11AuthenticationQueryType)
+ {
+ SAML11AuthenticationQueryType attQuery = (SAML11AuthenticationQueryType) query;
+ write(attQuery);
+ }
+ else if (query instanceof SAML11AuthorizationDecisionQueryType)
+ {
+ SAML11AuthorizationDecisionQueryType attQuery =
(SAML11AuthorizationDecisionQueryType) query;
+ write(attQuery);
+ }
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
+ }
+
+ public void write(SAML11AuthenticationQueryType auth) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
SAML11Constants.AUTHENTICATION_QUERY, namespace);
+
+ URI authMethod = auth.getAuthenticationMethod();
+ if (authMethod != null)
+ {
+ StaxUtil.writeAttribute(writer, SAML11Constants.AUTHENTICATION_METHOD,
authMethod.toString());
+ }
+
+ SAML11SubjectType subject = auth.getSubject();
+ if (subject != null)
+ {
+ assertionWriter.write(subject);
+ }
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
+ }
+
+ public void write(SAML11AttributeQueryType attr) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
SAML11Constants.ATTRIBUTE_QUERY, namespace);
+
+ URI resource = attr.getResource();
+ if (resource != null)
+ {
+ StaxUtil.writeAttribute(writer, SAML11Constants.RESOURCE, resource.toString());
+ }
+
+ SAML11SubjectType subject = attr.getSubject();
+ if (subject != null)
+ {
+ assertionWriter.write(subject);
+ }
+
+ List<SAML11AttributeDesignatorType> attributes = attr.get();
+ for (SAML11AttributeDesignatorType attribute : attributes)
+ {
+ if (attribute instanceof SAML11AttributeType)
+ {
+ SAML11AttributeType sat = (SAML11AttributeType) attribute;
+ assertionWriter.write(sat);
+ }
+ else
+ throw new ProcessingException("Unknown type:" +
attribute.getClass());
+ }
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
+ }
+
+ public void write(SAML11AuthorizationDecisionQueryType attr) throws
ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
SAML11Constants.ATTRIBUTE_QUERY, namespace);
+
+ URI resource = attr.getResource();
+ if (resource != null)
+ {
+ StaxUtil.writeAttribute(writer, SAML11Constants.RESOURCE, resource.toString());
+ }
+
+ SAML11SubjectType subject = attr.getSubject();
+ if (subject != null)
+ {
+ assertionWriter.write(subject);
+ }
+
+ List<SAML11ActionType> actions = attr.get();
+ for (SAML11ActionType action : actions)
+ {
+ assertionWriter.write(action);
+ }
+
+ SAML11EvidenceType evidence = attr.getEvidence();
+ if (evidence != null)
+ {
+ assertionWriter.write(evidence);
+ }
+
+ 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/saml/v2/writers/BaseWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -60,7 +60,7 @@
protected XMLStreamWriter writer = null;
- public BaseWriter(XMLStreamWriter writer) throws ProcessingException
+ public BaseWriter(XMLStreamWriter writer)
{
this.writer = writer;
}
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 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -75,7 +75,7 @@
*/
public class SAMLAssertionWriter extends BaseWriter
{
- public SAMLAssertionWriter(XMLStreamWriter writer) throws ProcessingException
+ public SAMLAssertionWriter(XMLStreamWriter writer)
{
super(writer);
}
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLMetadataWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLMetadataWriter.java 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLMetadataWriter.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -43,6 +43,8 @@
import org.picketlink.identity.federation.saml.v2.metadata.EndpointType;
import org.picketlink.identity.federation.saml.v2.metadata.EntitiesDescriptorType;
import org.picketlink.identity.federation.saml.v2.metadata.EntityDescriptorType;
+import
org.picketlink.identity.federation.saml.v2.metadata.EntityDescriptorType.EDTChoiceType;
+import
org.picketlink.identity.federation.saml.v2.metadata.EntityDescriptorType.EDTDescriptorChoiceType;
import org.picketlink.identity.federation.saml.v2.metadata.IDPSSODescriptorType;
import org.picketlink.identity.federation.saml.v2.metadata.IndexedEndpointType;
import org.picketlink.identity.federation.saml.v2.metadata.KeyDescriptorType;
@@ -54,8 +56,6 @@
import org.picketlink.identity.federation.saml.v2.metadata.RoleDescriptorType;
import org.picketlink.identity.federation.saml.v2.metadata.SPSSODescriptorType;
import org.picketlink.identity.federation.saml.v2.metadata.SSODescriptorType;
-import
org.picketlink.identity.federation.saml.v2.metadata.EntityDescriptorType.EDTChoiceType;
-import
org.picketlink.identity.federation.saml.v2.metadata.EntityDescriptorType.EDTDescriptorChoiceType;
import org.w3c.dom.Element;
/**
@@ -67,7 +67,7 @@
{
private final String METADATA_PREFIX = "md";
- public SAMLMetadataWriter(XMLStreamWriter writer) throws ProcessingException
+ public SAMLMetadataWriter(XMLStreamWriter writer)
{
super(writer);
}
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 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -42,7 +42,7 @@
import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
import org.picketlink.identity.federation.core.util.JAXBUtil;
import org.picketlink.identity.federation.core.util.StaxUtil;
-import org.picketlink.identity.federation.core.util.StringUtil;
+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;
@@ -56,214 +56,219 @@
* @since Nov 2, 2010
*/
public class SAMLRequestWriter extends BaseWriter
-{
- public SAMLRequestWriter(XMLStreamWriter writer) throws ProcessingException
+{
+ public SAMLRequestWriter(XMLStreamWriter writer)
{
super(writer);
}
-
+
/**
* Write a {@code AuthnRequestType } to stream
* @param request
* @param out
* @throws ProcessingException
*/
- public void write( AuthnRequestType request ) throws ProcessingException
- {
- 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() );
-
+ public void write(AuthnRequestType request) throws ProcessingException
+ {
+ 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() );
-
+ 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());
+
URI destination = request.getDestination();
- if( destination != null )
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.DESTINATION.get(),
destination.toASCIIString() );
+ if (destination != null)
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(),
destination.toASCIIString());
String consent = request.getConsent();
- if( StringUtil.isNotNull( consent ))
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.CONSENT.get(), consent );
-
+ if (StringUtil.isNotNull(consent))
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
+
URI assertionURL = request.getAssertionConsumerServiceURL();
- if( assertionURL != null )
- StaxUtil.writeAttribute( writer,
JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_URL.get(), assertionURL.toASCIIString() );
-
+ if (assertionURL != null)
+ StaxUtil.writeAttribute(writer,
JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_URL.get(),
+ assertionURL.toASCIIString());
+
Boolean forceAuthn = request.isForceAuthn();
- if( forceAuthn != null )
+ if (forceAuthn != null)
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORCE_AUTHN.get(),
forceAuthn.toString() );
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.FORCE_AUTHN.get(),
forceAuthn.toString());
}
-
+
Boolean isPassive = request.isIsPassive();
- if( isPassive != null )
+ if (isPassive != null)
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.IS_PASSIVE.get(),
isPassive.toString() );
- }
-
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.IS_PASSIVE.get(),
isPassive.toString());
+ }
+
URI protocolBinding = request.getProtocolBinding();
- if( protocolBinding != null )
+ if (protocolBinding != null)
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.PROTOCOL_BINDING.get(),
protocolBinding.toString() );
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROTOCOL_BINDING.get(),
protocolBinding.toString());
}
-
+
Integer assertionIndex = request.getAssertionConsumerServiceIndex();
- if( assertionIndex != null )
+ if (assertionIndex != null)
{
- StaxUtil.writeAttribute( writer,
JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_INDEX.get(), assertionIndex.toString() );
+ StaxUtil.writeAttribute(writer,
JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_INDEX.get(),
+ assertionIndex.toString());
}
-
+
Integer attrIndex = request.getAttributeConsumingServiceIndex();
- if( attrIndex != null )
+ if (attrIndex != null)
{
- StaxUtil.writeAttribute( writer,
JBossSAMLConstants.ATTRIBUTE_CONSUMING_SERVICE_INDEX.get(), attrIndex.toString() );
+ StaxUtil.writeAttribute(writer,
JBossSAMLConstants.ATTRIBUTE_CONSUMING_SERVICE_INDEX.get(),
+ attrIndex.toString());
}
String providerName = request.getProviderName();
- if( StringUtil.isNotNull( providerName ))
+ if (StringUtil.isNotNull(providerName))
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.PROVIDER_NAME.get(),
providerName );
- }
-
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROVIDER_NAME.get(),
providerName);
+ }
+
NameIDType issuer = request.getIssuer();
- if( issuer != null )
+ if (issuer != null)
{
- write( issuer, new QName( ASSERTION_NSURI.get(),
JBossSAMLConstants.ISSUER.get()));
- }
+ write(issuer, new QName(ASSERTION_NSURI.get(),
JBossSAMLConstants.ISSUER.get()));
+ }
NameIDPolicyType nameIDPolicy = request.getNameIDPolicy();
- if( nameIDPolicy != null )
- write( nameIDPolicy );
-
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ if (nameIDPolicy != null)
+ write(nameIDPolicy);
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
+
/**
* Write a {@code LogoutRequestType} to stream
* @param logOutRequest
* @param out
* @throws ProcessingException
*/
- public void write( LogoutRequestType logOutRequest ) throws ProcessingException
+ public void write(LogoutRequestType logOutRequest) throws ProcessingException
{
- 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() );
-
+ 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() );
-
+ 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());
+
URI destination = logOutRequest.getDestination();
- if( destination != null )
+ if (destination != null)
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.DESTINATION.get(),
destination.toASCIIString() );
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(),
destination.toASCIIString());
}
-
+
String consent = logOutRequest.getConsent();
- if( StringUtil.isNotNull( consent ))
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.CONSENT.get(), consent );
-
+ if (StringUtil.isNotNull(consent))
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
+
NameIDType issuer = logOutRequest.getIssuer();
- write( issuer, new QName( ASSERTION_NSURI.get(),
JBossSAMLConstants.ISSUER.get()));
-
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
+
/**
* Write a {@code NameIDPolicyType} to stream
* @param nameIDPolicy
* @param out
* @throws ProcessingException
*/
- public void write( NameIDPolicyType nameIDPolicy ) throws ProcessingException
+ public void write(NameIDPolicyType nameIDPolicy) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.NAMEID_POLICY.get(), PROTOCOL_NSURI.get() );
-
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
JBossSAMLConstants.NAMEID_POLICY.get(), PROTOCOL_NSURI.get());
+
URI format = nameIDPolicy.getFormat();
- if( format != null )
+ if (format != null)
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORMAT.get(),
format.toASCIIString() );
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.FORMAT.get(),
format.toASCIIString());
}
-
+
String spNameQualifier = nameIDPolicy.getSPNameQualifier();
- if( StringUtil.isNotNull( spNameQualifier ))
+ if (StringUtil.isNotNull(spNameQualifier))
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(),
spNameQualifier );
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(),
spNameQualifier);
}
-
+
Boolean allowCreate = nameIDPolicy.isAllowCreate();
- if( allowCreate != null )
+ if (allowCreate != null)
{
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.ALLOW_CREATE.get(),
allowCreate.toString() );
- }
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.ALLOW_CREATE.get(),
allowCreate.toString());
+ }
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
- public void write( XACMLAuthzDecisionQueryType xacmlQuery ) throws
ProcessingException
+
+ public void write(XACMLAuthzDecisionQueryType xacmlQuery) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.REQUEST_ABSTRACT.get(), PROTOCOL_NSURI.get() );
- StaxUtil.writeNameSpace( writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get() );
- StaxUtil.writeNameSpace(writer, XACML_SAML_PROTO_PREFIX,
JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get() );
- StaxUtil.writeDefaultNameSpace( writer, JBossSAMLURIConstants.XACML_NSURI.get() );
-
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
JBossSAMLConstants.REQUEST_ABSTRACT.get(),
+ PROTOCOL_NSURI.get());
+ StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
+ StaxUtil.writeNameSpace(writer, XACML_SAML_PROTO_PREFIX,
JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get());
+ StaxUtil.writeDefaultNameSpace(writer, JBossSAMLURIConstants.XACML_NSURI.get());
+
//Attributes
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.ID.get(), xacmlQuery.getID()
);
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.VERSION.get(),
xacmlQuery.getVersion() );
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.ISSUE_INSTANT.get(),
xacmlQuery.getIssueInstant().toString() );
-
- StaxUtil.writeAttribute( writer, new QName(
JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get(),
- JBossSAMLConstants.INPUT_CONTEXT_ONLY.get() , XACML_SAML_PROTO_PREFIX ),
"true" );
-
- StaxUtil.writeAttribute( writer, new QName(
JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get(),
- JBossSAMLConstants.RETURN_CONTEXT.get(), XACML_SAML_PROTO_PREFIX ),
"true" );
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), xacmlQuery.getID());
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(),
xacmlQuery.getVersion());
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(),
xacmlQuery.getIssueInstant().toString());
+ StaxUtil.writeAttribute(writer, new
QName(JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get(),
+ JBossSAMLConstants.INPUT_CONTEXT_ONLY.get(), XACML_SAML_PROTO_PREFIX),
"true");
+
+ StaxUtil.writeAttribute(writer, new
QName(JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get(),
+ JBossSAMLConstants.RETURN_CONTEXT.get(), XACML_SAML_PROTO_PREFIX),
"true");
+
StaxUtil.writeNameSpace(writer, JBossSAMLURIConstants.XSI_PREFIX.get(),
JBossSAMLURIConstants.XSI_NSURI.get());
StaxUtil.writeNameSpace(writer, "xs",
JBossSAMLURIConstants.XMLSCHEMA_NSURI.get());
-
+
StaxUtil.writeAttribute(writer, JBossSAMLURIConstants.XSI_NSURI.get(),
"type",
- "xacml-samlp:XACMLAuthzDecisionQueryType" );
-
+ "xacml-samlp:XACMLAuthzDecisionQueryType");
+
URI destination = xacmlQuery.getDestination();
- if( destination != null )
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.DESTINATION.get(),
destination.toASCIIString() );
+ if (destination != null)
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(),
destination.toASCIIString());
String consent = xacmlQuery.getConsent();
- if( StringUtil.isNotNull( consent ))
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.CONSENT.get(), consent );
-
-
+ if (StringUtil.isNotNull(consent))
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
+
NameIDType issuer = xacmlQuery.getIssuer();
- if( issuer != null )
+ if (issuer != null)
{
- write( issuer, new QName( ASSERTION_NSURI.get(),
JBossSAMLConstants.ISSUER.get()));
- }
-
+ write(issuer, new QName(ASSERTION_NSURI.get(),
JBossSAMLConstants.ISSUER.get()));
+ }
+
RequestType xacmlRequest = xacmlQuery.getRequest();
-
+
ObjectFactory of = new ObjectFactory();
-
+
StringWriter sw = new StringWriter();
try
{
- Marshaller m = JAXBUtil.getMarshaller( RequestType.class.getPackage().getName()
);
- m.marshal( of.createRequest(xacmlRequest), sw );
+ Marshaller m =
JAXBUtil.getMarshaller(RequestType.class.getPackage().getName());
+ m.marshal(of.createRequest(xacmlRequest), sw);
}
catch (JAXBException e)
- {
+ {
throw new ProcessingException(e);
}
-
+
try
{
- Document xacmlDoc = DocumentUtil.getDocument( sw.toString() );
- StaxUtil.writeDOMNode(writer, xacmlDoc.getDocumentElement() );
+ Document xacmlDoc = DocumentUtil.getDocument(sw.toString());
+ StaxUtil.writeDOMNode(writer, xacmlDoc.getDocumentElement());
}
catch (ConfigurationException e)
{
@@ -274,7 +279,7 @@
throw new ProcessingException(e);
}
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ 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/saml/v2/writers/SAMLResponseWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -38,11 +38,11 @@
import org.picketlink.identity.federation.saml.v2.assertion.EncryptedAssertionType;
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.ResponseType.RTChoiceType;
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;
-import org.picketlink.identity.federation.saml.v2.protocol.ResponseType.RTChoiceType;
import org.w3c.dom.Element;
/**
@@ -51,60 +51,60 @@
* @since Nov 2, 2010
*/
public class SAMLResponseWriter extends BaseWriter
-{
- private SAMLAssertionWriter assertionWriter;
-
- public SAMLResponseWriter(XMLStreamWriter writer) throws ProcessingException
+{
+ private final SAMLAssertionWriter assertionWriter;
+
+ public SAMLResponseWriter(XMLStreamWriter writer)
{
super(writer);
this.assertionWriter = new SAMLAssertionWriter(writer);
}
-
+
/**
* Write a {@code ResponseType} to stream
* @param response
* @param out
* @throws ProcessingException
*/
- public void write( ResponseType response ) throws ProcessingException
+ public void write(ResponseType response) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.RESPONSE.get() , PROTOCOL_NSURI.get() );
-
- StaxUtil.writeNameSpace( writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get() );
- StaxUtil.writeNameSpace( writer, ASSERTION_PREFIX, ASSERTION_NSURI.get() );
- StaxUtil.writeDefaultNameSpace( writer, ASSERTION_NSURI.get() );
-
- writeBaseAttributes( response );
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
JBossSAMLConstants.RESPONSE.get(), PROTOCOL_NSURI.get());
+ StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
+ StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
+ StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
+
+ writeBaseAttributes(response);
+
NameIDType issuer = response.getIssuer();
- write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() )
);
-
+ write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+
StatusType status = response.getStatus();
- write( status );
-
+ write(status);
+
List<RTChoiceType> choiceTypes = response.getAssertions();
- if( choiceTypes != null )
+ if (choiceTypes != null)
{
- for( RTChoiceType choiceType: choiceTypes )
+ for (RTChoiceType choiceType : choiceTypes)
{
AssertionType assertion = choiceType.getAssertion();
- if( assertion != null )
+ if (assertion != null)
{
- assertionWriter.write( (AssertionType) assertion );
+ assertionWriter.write(assertion);
}
-
+
EncryptedAssertionType encryptedAssertion =
choiceType.getEncryptedAssertion();
- if( encryptedAssertion != null )
+ if (encryptedAssertion != null)
{
Element encElement = encryptedAssertion.getEncryptedElement();
StaxUtil.writeDOMElement(writer, encElement);
- }
+ }
}
}
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
+
/**
* Write a {@code StatusResponseType}
* @param response
@@ -112,118 +112,121 @@
* @param out
* @throws ProcessingException
*/
- public void write( StatusResponseType response, QName qname ) throws
ProcessingException
+ public void write(StatusResponseType response, QName qname) throws
ProcessingException
{
- if( qname == null )
+ if (qname == null)
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS_RESPONSE_TYPE.get() , PROTOCOL_NSURI.get() );
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS_RESPONSE_TYPE.get(),
+ PROTOCOL_NSURI.get());
}
else
{
- StaxUtil.writeStartElement( writer, qname.getPrefix(), qname.getLocalPart() ,
qname.getNamespaceURI() );
+ 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 );
+ 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() )
);
-
+ write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+
StatusType status = response.getStatus();
- write( status );
-
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ write(status);
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
+
/**
* Write a {@code StatusType} to stream
* @param status
* @param out
* @throws ProcessingException
*/
- public void write( StatusType status ) throws ProcessingException
+ public void write(StatusType status) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS.get() , PROTOCOL_NSURI.get() );
-
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS.get(), PROTOCOL_NSURI.get());
+
StatusCodeType statusCodeType = status.getStatusCode();
- write( statusCodeType );
-
+ write(statusCodeType);
+
String statusMessage = status.getStatusMessage();
- if( StringUtil.isNotNull( statusMessage ))
+ if (StringUtil.isNotNull(statusMessage))
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS_MESSAGE.get() , PROTOCOL_NSURI.get() );
- StaxUtil.writeEndElement( writer);
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS_MESSAGE.get(),
+ PROTOCOL_NSURI.get());
+ StaxUtil.writeEndElement(writer);
}
-
+
StatusDetailType statusDetail = status.getStatusDetail();
- if( statusDetail != null )
- write( statusDetail );
-
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ if (statusDetail != null)
+ write(statusDetail);
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
+
/**
* Write a {@code StatusCodeType} to stream
* @param statusCodeType
* @param out
* @throws ProcessingException
*/
- public void write( StatusCodeType statusCodeType ) throws ProcessingException
+ public void write(StatusCodeType statusCodeType) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS_CODE.get() , PROTOCOL_NSURI.get() );
-
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS_CODE.get(), PROTOCOL_NSURI.get());
+
URI value = statusCodeType.getValue();
- if( value != null )
- {
- StaxUtil.writeAttribute( writer, JBossSAMLConstants.VALUE.get(),
value.toASCIIString() );
+ if (value != null)
+ {
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.VALUE.get(),
value.toASCIIString());
}
StatusCodeType subStatusCode = statusCodeType.getStatusCode();
- if( subStatusCode != null )
- write( subStatusCode );
-
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ if (subStatusCode != null)
+ write(subStatusCode);
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
+
/**
* Write a {@code StatusDetailType} to stream
* @param statusDetailType
* @param out
* @throws ProcessingException
*/
- public void write( StatusDetailType statusDetailType ) throws ProcessingException
+ public void write(StatusDetailType statusDetailType) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX,
JBossSAMLConstants.STATUS_CODE.get() , PROTOCOL_NSURI.get() );
- StaxUtil.writeEndElement( writer);
- StaxUtil.flush( writer );
+ 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
+ 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() );
-
+ 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 );
+ 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 );
-
+ 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 );
- }
+ 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/SAML11AssertionParserTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11AssertionParserTestCase.java 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11AssertionParserTestCase.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -25,13 +25,16 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v1.writers.SAML11AssertionWriter;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.util.StaxUtil;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AssertionType;
import
org.picketlink.identity.federation.saml.v1.assertion.SAML11AttributeStatementType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AttributeType;
@@ -86,6 +89,12 @@
SAML11SubjectConfirmationType subjectConfirm = subject.getSubjectConfirmation();
URI confirmationMethod = subjectConfirm.getConfirmationMethod().get(0);
assertEquals("urn:oasis:names:tc:SAML:1.0:cm:bearer",
confirmationMethod.toString());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11AssertionWriter writer = new
SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(assertion);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -143,6 +152,12 @@
List<Object> attribValues = attrib.get();
assertTrue(attribValues.contains("member"));
assertTrue(attribValues.contains("student"));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11AssertionWriter writer = new
SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(assertion);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -165,6 +180,12 @@
SAML11ConditionsType conditions = assertion.getConditions();
assertEquals(XMLTimeUtil.parse("2002-06-19T17:05:37.795Z"),
conditions.getNotBefore());
assertEquals(XMLTimeUtil.parse("2002-06-19T17:15:37.795Z"),
conditions.getNotOnOrAfter());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11AssertionWriter writer = new
SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(assertion);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -236,6 +257,12 @@
subjConf = subject.getSubjectConfirmation();
confirmationMethod = subjConf.getConfirmationMethod().get(0);
assertEquals("urn:oasis:names:tc:SAML:1.0:cm:artifact",
confirmationMethod.toString());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11AssertionWriter writer = new
SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(assertion);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -271,5 +298,11 @@
Element sig = assertion.getSignature();
assertNotNull(sig);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11AssertionWriter writer = new
SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(assertion);
+ System.out.println(new String(baos.toByteArray()));
}
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11RequestParserTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11RequestParserTestCase.java 2011-06-28
15:59:54 UTC (rev 1040)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11RequestParserTestCase.java 2011-06-29
18:36:59 UTC (rev 1041)
@@ -25,13 +25,16 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
import org.picketlink.identity.federation.core.saml.v1.SAML11Constants;
+import org.picketlink.identity.federation.core.saml.v1.writers.SAML11RequestWriter;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.util.StaxUtil;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11ActionType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectType;
import org.picketlink.identity.federation.saml.v1.protocol.SAML11AttributeQueryType;
@@ -69,6 +72,12 @@
SAML11SubjectType subject = attQuery.getSubject();
SAML11SubjectType.SAML11SubjectTypeChoice choice = subject.getChoice();
assertEquals("myusername", choice.getNameID().getValue());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11RequestWriter writer = new
SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(request);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -93,6 +102,12 @@
SAML11SubjectType subject = attQuery.getSubject();
SAML11SubjectType.SAML11SubjectTypeChoice choice = subject.getChoice();
assertEquals("testID", choice.getNameID().getValue());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11RequestWriter writer = new
SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(request);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -126,6 +141,12 @@
SAML11ActionType action = actions.get(0);
assertEquals("create", action.getValue());
assertEquals("http://www.jboss.org", action.getNamespace());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11RequestWriter writer = new
SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(request);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -144,6 +165,12 @@
assertEquals(XMLTimeUtil.parse("2002-06-19T17:03:44.022Z"),
request.getIssueInstant());
assertEquals("abcd", request.getAssertionArtifact().get(0));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11RequestWriter writer = new
SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(request);
+ System.out.println(new String(baos.toByteArray()));
}
@Test
@@ -162,5 +189,11 @@
assertEquals(XMLTimeUtil.parse("2002-06-19T17:03:44.022Z"),
request.getIssueInstant());
assertEquals("abcd", request.getAssertionIDRef().get(0));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11RequestWriter writer = new
SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(request);
+ System.out.println(new String(baos.toByteArray()));
}
}
\ No newline at end of file