Picketlink SVN: r1047 - in federation/trunk: picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util and 9 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-30 19:50:05 -0400 (Thu, 30 Jun 2011)
New Revision: 1047
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/JAXPValidationUtil.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SchemaManagerUtil.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/AbstractParserTest.java
federation/trunk/picketlink-fed-model/src/main/resources/schema/saml/v1/oasis-sstc-saml-schema-assertion-1.1.xsd
federation/trunk/picketlink-xmlsec-model/src/main/resources/schema/w3c/xmlschema/xml.xsd
Modified:
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/util/StaxParserUtil.java
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/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/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/main/java/org/picketlink/identity/federation/core/util/IDFedLSInputResolver.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SecurityActions.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
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java
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/SAMLAuthnRequestParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/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-assertion-x500attrib.xml
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml
federation/trunk/picketlink-fed-core/src/test/resources/saml-xacml/saml-xacml-response-1.xml
federation/trunk/picketlink-fed-model/src/main/java/org/picketlink/identity/federation/saml/v2/profiles/xacml/assertion/XACMLAuthzDecisionStatementType.java
Log:
PLFED-188: jaxp schema validation
Modified: 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 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -31,9 +31,11 @@
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.util.SAMLParserUtil;
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.LogoutRequestType;
/**
@@ -64,11 +66,23 @@
parseCommonElements(startElement, xmlEventReader, logoutRequest);
+ startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+ if (startElement == null)
+ break;
+ elementName = StaxParserUtil.getStartElementName(startElement);
+
if (JBossSAMLConstants.SESSION_INDEX.get().equals(elementName))
{
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
logoutRequest.getSessionIndex().add(StaxParserUtil.getElementText(xmlEventReader));
}
+ else if (JBossSAMLConstants.NAMEID.get().equals(elementName))
+ {
+ NameIDType nameID = SAMLParserUtil.parseNameIDType(xmlEventReader);
+ logoutRequest.setNameID(nameID);
+ }
+ else
+ throw new RuntimeException("unknown " + elementName);
}
return logoutRequest;
}
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -21,8 +21,8 @@
*/
package org.picketlink.identity.federation.core.parsers.util;
+import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
@@ -33,13 +33,9 @@
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
-import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stax.StAXSource;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.apache.log4j.Logger;
@@ -48,13 +44,12 @@
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.DocumentUtil;
+import org.picketlink.identity.federation.core.util.JAXPValidationUtil;
import org.picketlink.identity.federation.core.util.StringUtil;
import org.picketlink.identity.federation.core.util.TransformerUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
/**
* Utility for the stax based parser
@@ -470,82 +465,8 @@
throw new RuntimeException("Expecting </" + tag + ">. Found </" + elementTag + ">");
}
- public static Validator getSchemaValidator()
+ public static Validator getSchemaValidator() throws SAXException, IOException
{
- if (validator == null)
- {
- try
- {
- final Class<?> clazz = StaxParserUtil.class;
-
- URL saml1Assertion = SecurityActions.loadResource(clazz, "schema/saml/v1/saml-schema-assertion-1.0.xsd");
- URL saml1Protocol = SecurityActions.loadResource(clazz, "schema/saml/v1/saml-schema-protocol-1.1.xsd");
- URL dsig = SecurityActions.loadResource(clazz, "schema/w3c/xmldsig/xmldsig-core-schema.xsd");
- URL xmlenc = SecurityActions.loadResource(clazz, "schema/w3c/xmlenc/xenc-schema.xsd");
-
- if (saml1Assertion == null)
- throw new RuntimeException("SAML11 Assertion Schema not found");
-
- if (saml1Protocol == null)
- throw new RuntimeException("SAML11 Protocol Schema not found");
-
- if (dsig == null)
- throw new RuntimeException("XML DSIG Schema not found");
-
- if (xmlenc == null)
- throw new RuntimeException("XML Enc Schema not found");
-
- Source[] sources = new Source[]
- {new StreamSource(dsig.openStream()), new StreamSource(xmlenc.openStream()),
- new StreamSource(saml1Assertion.openStream()), new StreamSource(saml1Protocol.openStream())};
-
- /* URL schemaURL = tcl.getResource(schemaFile);
- if (schemaURL == null)
- throw new RuntimeException("Cannot find schema :" + schemaFile);*/
- SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
- Schema schemaGrammar = schemaFactory.newSchema(sources);
-
- validator = schemaGrammar.newValidator();
- validator.setErrorHandler(new ErrorHandler()
- {
-
- public void error(SAXParseException ex) throws SAXException
- {
- logException(ex);
- throw ex;
- }
-
- public void fatalError(SAXParseException ex) throws SAXException
- {
- logException(ex);
- throw ex;
- }
-
- public void warning(SAXParseException ex) throws SAXException
- {
- logException(ex);
- }
-
- private void logException(SAXParseException sax)
- {
- StringBuilder builder = new StringBuilder();
-
- if (trace)
- {
- builder.append("[").append(sax.getLineNumber()).append(",").append(sax.getColumnNumber())
- .append("]");
- builder.append(":").append(sax.getLocalizedMessage());
- log.trace(builder.toString());
- }
- }
- });
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- return validator;
+ return JAXPValidationUtil.validator();
}
}
\ No newline at end of file
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 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLURIConstants.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -111,7 +111,7 @@
X500_PREFIX("x500"),
X500_NSURI("urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500"),
XACML_NSURI( "urn:oasis:names:tc:xacml:2.0:context:schema:os" ),
- XACML_SAML_NSURI( "urn:oasis:names:tc:xacml:2.0:saml:assertion:schema:os" ),
+ XACML_SAML_NSURI( "urn:oasis:xacml:2.0:saml:assertion:schema:os" ),
XACML_SAML_PROTO_NSURI( "urn:oasis:xacml:2.0:saml:protocol:schema:os" ),
XML( "http://www.w3.org/XML/1998/namespace" ),
XMLSCHEMA_NSURI("http://www.w3.org/2001/XMLSchema"),
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-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -76,6 +76,8 @@
{
StaxUtil.writeStartElement(writer, tag.getPrefix(), tag.getLocalPart(), tag.getNamespaceURI());
+ StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
+
URI format = nameIDType.getFormat();
if (format != null)
{
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-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -102,6 +102,10 @@
if (issuer != null)
write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+ Element sig = assertion.getSignature();
+ if (sig != null)
+ StaxUtil.writeDOMElement(writer, sig);
+
SubjectType subject = assertion.getSubject();
if (subject != null)
{
@@ -174,10 +178,6 @@
}
}
- Element sig = assertion.getSignature();
- if (sig != null)
- StaxUtil.writeDOMElement(writer, sig);
-
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
@@ -369,6 +369,32 @@
}
}
+ Set<URIType> uriTypes = authContext.getURIType();
+ for (URIType uriType : uriTypes)
+ {
+ if (uriType instanceof AuthnContextClassRefType)
+ {
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get(),
+ ASSERTION_NSURI.get());
+ StaxUtil.writeCharacters(writer, uriType.getValue().toString());
+ StaxUtil.writeEndElement(writer);
+ }
+ else if (uriType instanceof AuthnContextDeclRefType)
+ {
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
+ JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get(), ASSERTION_NSURI.get());
+ StaxUtil.writeCharacters(writer, uriType.getValue().toString());
+ StaxUtil.writeEndElement(writer);
+ }
+ else if (uriType instanceof AuthnContextDeclType)
+ {
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION.get(),
+ ASSERTION_NSURI.get());
+ StaxUtil.writeCharacters(writer, uriType.getValue().toString());
+ StaxUtil.writeEndElement(writer);
+ }
+ }
+
StaxUtil.writeEndElement(writer);
StaxUtil.flush(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-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -175,6 +175,12 @@
NameIDType issuer = logOutRequest.getIssuer();
write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+ NameIDType nameID = logOutRequest.getNameID();
+ if (nameID != null)
+ {
+ write(nameID, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX));
+ }
+
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
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-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -77,7 +77,10 @@
writeBaseAttributes(response);
NameIDType issuer = response.getIssuer();
- write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+ if (issuer != null)
+ {
+ write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+ }
StatusType status = response.getStatus();
write(status);
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/IDFedLSInputResolver.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/IDFedLSInputResolver.java 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/IDFedLSInputResolver.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -23,9 +23,12 @@
import java.io.InputStream;
import java.io.Reader;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
+import org.apache.log4j.Logger;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
@@ -36,15 +39,58 @@
*/
public class IDFedLSInputResolver implements LSResourceResolver
{
+ protected static Logger log = Logger.getLogger(IDFedLSInputResolver.class);
+
private static Map<String, LSInput> lsmap = new HashMap<String, LSInput>();
- private static Map<String, String> schemaLocationMap = new HashMap<String, String>();
+ private static Map<String, String> schemaLocationMap = new LinkedHashMap<String, String>();
static
{
+ //XML Schema/DTD
+ schemaLocationMap.put("datatypes.dtd", "schema/w3c/xmlschema/datatypes.dtd");
+ schemaLocationMap.put("XMLSchema.dtd", "schema/w3c/xmlschema/XMLSchema.dtd");
+ schemaLocationMap.put("http://www.w3.org/2001/xml.xsd", "schema/w3c/xmlschema/xml.xsd");
+
+ //XML DSIG
+ schemaLocationMap.put("http://www.w3.org/2000/09/xmldsig#", "schema/w3c/xmldsig/xmldsig-core-schema.xsd");
+ schemaLocationMap.put("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd",
+ "schema/w3c/xmldsig/xmldsig-core-schema.xsd");
+
+ //XML Enc
+ schemaLocationMap.put("http://www.w3.org/2001/04/xmlenc#", "schema/w3c/xmlenc/xenc-schema.xsd");
+ schemaLocationMap.put("http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/xenc-schema.xsd",
+ "schema/w3c/xmlenc/xenc-schema.xsd");
+
+ //XACML
+ schemaLocationMap.put("access_control-xacml-2.0-context-schema-os.xsd",
+ "schema/access_control-xacml-2.0-context-schema-os.xsd");
+ schemaLocationMap.put("access_control-xacml-2.0-policy-schema-os.xsd",
+ "schema/access_control-xacml-2.0-policy-schema-os.xsd");
+
//SAML
+
schemaLocationMap.put("saml-schema-assertion-2.0.xsd", "schema/saml/v2/saml-schema-assertion-2.0.xsd");
+ schemaLocationMap.put("saml-schema-protocol-2.0.xsd", "schema/saml/v2/saml-schema-protocol-2.0.xsd");
+ schemaLocationMap.put("saml-schema-metadata-2.0.xsd", "schema/saml/v2/saml-schema-metadata-2.0.xsd");
+ schemaLocationMap.put("saml-schema-x500-2.0.xsd", "schema/saml/v2/saml-schema-x500-2.0.xsd");
+ schemaLocationMap.put("saml-schema-xacml-2.0.xsd", "schema/saml/v2/saml-schema-xacml-2.0.xsd");
+ schemaLocationMap.put("saml-schema-xacml-2.0.xsd", "schema/saml/v2/saml-schema-xacml-2.0.xsd");
+ schemaLocationMap.put("saml-schema-authn-context-2.0.xsd", "schema/saml/v2/saml-schema-authn-context-2.0.xsd");
+ schemaLocationMap.put("saml-schema-authn-context-types-2.0.xsd",
+ "schema/saml/v2/saml-schema-authn-context-types-2.0.xsd");
+ schemaLocationMap.put("saml-schema-assertion-1.0.xsd", "schema/saml/v1/saml-schema-assertion-1.0.xsd");
+ schemaLocationMap.put("oasis-sstc-saml-schema-assertion-1.1.xsd",
+ "schema/saml/v1/oasis-sstc-saml-schema-assertion-1.1.xsd");
+ schemaLocationMap.put("saml-schema-protocol-1.1.xsd", "schema/saml/v1/saml-schema-protocol-1.1.xsd");
+
+ schemaLocationMap.put("access_control-xacml-2.0-saml-assertion-schema-os.xsd",
+ "schema/saml/v2/access_control-xacml-2.0-saml-assertion-schema-os.xsd");
+
+ schemaLocationMap.put("access_control-xacml-2.0-saml-protocol-schema-os.xsd",
+ "schema/saml/v2/access_control-xacml-2.0-saml-protocol-schema-os.xsd");
+
//WS-T
schemaLocationMap.put("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "schema/wstrust/v1_3/ws-trust-1.3.xsd");
schemaLocationMap.put("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext...",
@@ -53,36 +99,30 @@
"schema/wstrust/v1_3/oasis-200401-wss-wssecurity-utility-1.0.xsd");
schemaLocationMap.put("http://schemas.xmlsoap.org/ws/2004/09/policy", "schema/wstrust/v1_3/ws-policy.xsd");
schemaLocationMap.put("http://www.w3.org/2005/08/addressing", "schema/wstrust/v1_3/ws-addr.xsd");
+ }
- //XML DSIG
- schemaLocationMap.put("http://www.w3.org/2000/09/xmldsig#", "schema/w3c/xmldsig/xmldsig-core-schema.xsd");
- schemaLocationMap.put("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd",
- "schema/w3c/xmldsig/xmldsig-core-schema.xsd");
-
- //XML Enc
- schemaLocationMap.put("http://www.w3.org/2001/04/xmlenc#", "schema/w3c/xmlenc/xenc-schema.xsd");
- schemaLocationMap.put("http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/xenc-schema.xsd",
- "schema/w3c/xmlenc/xenc-schema.xsd");
-
- //XML Schema/DTD
- schemaLocationMap.put("datatypes.dtd", "schema/w3c/xmlschema/datatypes.dtd");
- schemaLocationMap.put("http://www.w3.org/2001/XMLSchema.dtd", "schema/w3c/xmlschema/XMLSchema.dtd");
+ public static Collection<String> schemas()
+ {
+ Collection<String> schemaValues = schemaLocationMap.values();
+ schemaValues.remove("schema/w3c/xmlschema/datatypes.dtd");
+ schemaValues.remove("schema/w3c/xmlschema/XMLSchema.dtd");
+ log.info("Considered the schemas:" + schemaValues);
+ return schemaValues;
}
public LSInput resolveResource(String type, String namespaceURI, final String publicId, final String systemId,
final String baseURI)
{
+ if (systemId == null)
+ throw new RuntimeException("systemid null");
LSInput lsi = lsmap.get(systemId);
if (lsi == null)
{
- ClassLoader tcl = SecurityActions.getContextClassLoader();
- String loc = schemaLocationMap.get(systemId);
+ final ClassLoader tcl = SecurityActions.getContextClassLoader();
+ final String loc = schemaLocationMap.get(systemId);
if (loc == null)
return null;
- final InputStream is = tcl.getResourceAsStream(loc);
- if (is == null)
- throw new RuntimeException("inputstream is null for " + loc);
lsi = new LSInput()
{
public String getBaseURI()
@@ -92,6 +132,9 @@
public InputStream getByteStream()
{
+ final InputStream is = tcl.getResourceAsStream(loc);
+ if (is == null)
+ throw new RuntimeException("inputstream is null for " + loc);
return is;
}
@@ -162,5 +205,4 @@
}
return lsi;
}
-
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/JAXPValidationUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/JAXPValidationUtil.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/JAXPValidationUtil.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -0,0 +1,152 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.apache.log4j.Logger;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Utility class associated with JAXP Validation
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jun 30, 2011
+ */
+public class JAXPValidationUtil
+{
+ protected static Logger log = Logger.getLogger(JAXPValidationUtil.class);
+
+ protected static boolean trace = log.isTraceEnabled();
+
+ protected static Validator validator;
+
+ protected static SchemaFactory schemaFactory;
+
+ public static void validate(String str) throws SAXException, IOException
+ {
+ validator().validate(new StreamSource(str));
+ }
+
+ public static void validate(InputStream stream) throws SAXException, IOException
+ {
+ validator().validate(new StreamSource(stream));
+ }
+
+ public static Validator validator() throws SAXException, IOException
+ {
+ String schemaFactoryProperty = "javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI;
+ SecurityActions.setSystemProperty(schemaFactoryProperty, "org.apache.xerces.jaxp.validation.XMLSchemaFactory");
+
+ if (validator == null)
+ {
+ Schema schema = getSchema();
+ if (schema == null)
+ throw new RuntimeException("Could not get all the schemas");
+
+ validator = schema.newValidator();
+ validator.setErrorHandler(new CustomErrorHandler());
+ }
+ return validator;
+ }
+
+ private static Schema getSchema() throws IOException
+ {
+ schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
+
+ schemaFactory.setResourceResolver(new IDFedLSInputResolver());
+ schemaFactory.setErrorHandler(new CustomErrorHandler());
+ Schema schemaGrammar = null;
+ try
+ {
+ schemaGrammar = schemaFactory.newSchema(sources());
+ }
+ catch (SAXException e)
+ {
+ log.error("Cannot get schema", e);
+ }
+ return schemaGrammar;
+ }
+
+ private static Source[] sources() throws IOException
+ {
+ List<String> schemas = SchemaManagerUtil.getSchemas();
+
+ Source[] sourceArr = new Source[schemas.size()];
+
+ int i = 0;
+ for (String schema : schemas)
+ {
+ URL url = SecurityActions.loadResource(JAXPValidationUtil.class, schema);
+ if (url == null)
+ throw new RuntimeException(schema + " is not available");
+ sourceArr[i++] = new StreamSource(url.openStream());
+ }
+ return sourceArr;
+ }
+
+ private static class CustomErrorHandler implements ErrorHandler
+ {
+ public void error(SAXParseException ex) throws SAXException
+ {
+ logException(ex);
+ if (ex.getMessage().contains("null") == false)
+ {
+ throw ex;
+ }
+ }
+
+ public void fatalError(SAXParseException ex) throws SAXException
+ {
+ logException(ex);
+ throw ex;
+ }
+
+ public void warning(SAXParseException ex) throws SAXException
+ {
+ logException(ex);
+ }
+
+ private void logException(SAXParseException sax)
+ {
+ StringBuilder builder = new StringBuilder();
+
+ if (trace)
+ {
+ builder.append("[").append(sax.getLineNumber()).append(",").append(sax.getColumnNumber()).append("]");
+ builder.append(":").append(sax.getLocalizedMessage());
+ log.trace(builder.toString());
+ }
+ }
+ };
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SchemaManagerUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SchemaManagerUtil.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SchemaManagerUtil.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -0,0 +1,117 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Manages the schemas for PicketLink
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jun 30, 2011
+ */
+public class SchemaManagerUtil
+{
+ public static List<String> getXMLSchemas()
+ {
+ List<String> list = new ArrayList<String>();
+
+ list.add("schema/w3c/xmlschema/xml.xsd");
+ return list;
+ }
+
+ public static List<String> getXMLDSig()
+ {
+ List<String> list = new ArrayList<String>();
+
+ list.add("schema/w3c/xmldsig/xmldsig-core-schema.xsd");
+ return list;
+ }
+
+ public static List<String> getXMLEnc()
+ {
+ List<String> list = new ArrayList<String>();
+
+ list.add("schema/w3c/xmlenc/xenc-schema.xsd");
+ return list;
+ }
+
+ public static List<String> getXACMLSchemas()
+ {
+ List<String> list = new ArrayList<String>();
+
+ list.add("schema/access_control-xacml-2.0-policy-schema-os.xsd");
+ list.add("schema/access_control-xacml-2.0-context-schema-os.xsd");
+ return list;
+ }
+
+ public static List<String> getSAML2Schemas()
+ {
+ List<String> list = new ArrayList<String>();
+
+ list.add("schema/saml/v2/saml-schema-assertion-2.0.xsd");
+ list.add("schema/saml/v2/saml-schema-protocol-2.0.xsd");
+ list.add("schema/saml/v2/saml-schema-metadata-2.0.xsd");
+ list.add("schema/saml/v2/saml-schema-x500-2.0.xsd");
+ list.add("schema/saml/v2/saml-schema-authn-context-2.0.xsd");
+ list.add("schema/saml/v2/saml-schema-authn-context-types-2.0.xsd");
+ list.add("schema/saml/v2/saml-schema-xacml-2.0.xsd");
+ list.add("schema/saml/v2/access_control-xacml-2.0-saml-assertion-schema-os.xsd");
+ list.add("schema/saml/v2/access_control-xacml-2.0-saml-protocol-schema-os.xsd");
+ return list;
+ }
+
+ public static List<String> getSAML11Schemas()
+ {
+ List<String> list = new ArrayList<String>();
+
+ list.add("schema/saml/v1/saml-schema-assertion-1.0.xsd");
+ list.add("schema/saml/v1/oasis-sstc-saml-schema-assertion-1.1.xsd");
+ list.add("schema/saml/v1/saml-schema-protocol-1.1.xsd");
+ return list;
+ }
+
+ public static List<String> getWSTrustSchemas()
+ {
+ List<String> list = new ArrayList<String>();
+
+ list.add("schema/wstrust/v1_3/ws-trust-1.3.xsd");
+ list.add("schema/wstrust/v1_3/oasis-200401-wss-wssecurity-secext-1.0.xsd");
+ list.add("schema/wstrust/v1_3/oasis-200401-wss-wssecurity-utility-1.0.xsd");
+ list.add("schema/wstrust/v1_3/ws-policy.xsd");
+ list.add("schema/wstrust/v1_3/ws-addr.xsd");
+ return list;
+ }
+
+ public static List<String> getSchemas()
+ {
+ List<String> list = new ArrayList<String>();
+ list.addAll(getXMLSchemas());
+ list.addAll(getXMLDSig());
+ list.addAll(getXMLEnc());
+ list.addAll(getSAML2Schemas());
+ list.addAll(getSAML11Schemas());
+ list.addAll(getXACMLSchemas());
+ list.addAll(getWSTrustSchemas());
+ return list;
+ }
+}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SecurityActions.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SecurityActions.java 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SecurityActions.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -21,6 +21,7 @@
*/
package org.picketlink.identity.federation.core.util;
+import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -45,7 +46,7 @@
}
});
}
-
+
/**
* Set the system property
* @param key
@@ -63,7 +64,7 @@
}
});
}
-
+
/**
* Get the system property
* @param key
@@ -80,4 +81,32 @@
}
});
}
-}
+
+ /**
+ * Load a resource based on the passed {@link Class} classloader.
+ * Failing which try with the Thread Context CL
+ * @param clazz
+ * @param resourceName
+ * @return
+ */
+ static URL loadResource(final Class<?> clazz, final String resourceName)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>()
+ {
+ public URL run()
+ {
+ URL url = null;
+ ClassLoader clazzLoader = clazz.getClassLoader();
+ url = clazzLoader.getResource(resourceName);
+
+ if (url == null)
+ {
+ clazzLoader = Thread.currentThread().getContextClassLoader();
+ url = clazzLoader.getResource(resourceName);
+ }
+
+ return url;
+ }
+ });
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/AbstractParserTest.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/AbstractParserTest.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/AbstractParserTest.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -0,0 +1,56 @@
+/*
+ * 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.assertNotNull;
+
+import java.io.InputStream;
+import java.io.StringReader;
+
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Validator;
+
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+
+/**
+ * Base class for the parser unit tests
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jun 30, 2011
+ */
+public class AbstractParserTest
+{
+ public void validateSchema(String value) throws Exception
+ {
+ System.setProperty("jaxp.debug", "true");
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(value)));
+ }
+
+ public void validateSchema(InputStream is) throws Exception
+ {
+ System.setProperty("jaxp.debug", "true");
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(is));
+ }
+}
\ 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-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11AssertionParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -27,16 +27,11 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import java.io.StringReader;
import java.net.URI;
import java.util.List;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Validator;
-
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
-import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
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;
@@ -59,7 +54,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Jun 21, 2011
*/
-public class SAML11AssertionParserTestCase
+public class SAML11AssertionParserTestCase extends AbstractParserTest
{
@Test
public void testSAML11Assertion() throws Exception
@@ -101,10 +96,7 @@
writer.write(assertion);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -169,10 +161,7 @@
writer.write(assertion);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -202,10 +191,7 @@
writer.write(assertion);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -284,10 +270,7 @@
writer.write(assertion);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -330,9 +313,6 @@
writer.write(assertion);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
}
\ 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-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11RequestParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -27,15 +27,10 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import java.io.StringReader;
import java.util.List;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Validator;
-
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
-import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
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;
@@ -53,7 +48,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Jun 24, 2011
*/
-public class SAML11RequestParserTestCase
+public class SAML11RequestParserTestCase extends AbstractParserTest
{
@Test
public void testSAML11RequestWithAuthQuery() throws Exception
@@ -84,10 +79,7 @@
writer.write(request);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -119,10 +111,7 @@
writer.write(request);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -163,10 +152,7 @@
writer.write(request);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -192,10 +178,7 @@
writer.write(request);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
@Test
@@ -221,9 +204,6 @@
writer.write(request);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -26,16 +26,11 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import java.io.StringReader;
import java.util.List;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Validator;
-
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAML11ResponseParser;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
-import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.saml.v1.writers.SAML11ResponseWriter;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
import org.picketlink.identity.federation.core.util.StaxUtil;
@@ -49,7 +44,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Jun 23, 2011
*/
-public class SAML11ResponseParserTestCase
+public class SAML11ResponseParserTestCase extends AbstractParserTest
{
@Test
public void testSAML11Response() throws Exception
@@ -83,9 +78,6 @@
writer.write(response);
String writtenString = new String(baos.toByteArray());
System.out.println(writtenString);
-
- Validator validator = StaxParserUtil.getSchemaValidator();
- assertNotNull(validator);
- validator.validate(new StreamSource(new StringReader(writtenString)));
+ validateSchema(writtenString);
}
}
\ No newline at end of file
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 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -60,7 +60,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Oct 12, 2010
*/
-public class SAMLAssertionParserTestCase
+public class SAMLAssertionParserTestCase extends AbstractParserTest
{
@Test
public void testSAMLAssertionParsing() throws Exception
@@ -89,29 +89,13 @@
assertEquals(XMLTimeUtil.parse("2010-09-30T19:13:37.869Z"), conditions.getNotBefore());
assertEquals(XMLTimeUtil.parse("2010-09-30T21:13:37.869Z"), conditions.getNotOnOrAfter());
- /*List<JAXBElement<?>> content = subject.getContent();
-
- int size = content.size();
-
- for( int i = 0 ; i < size; i++ )
- {
- JAXBElement<?> node = content.get(i);
- if( node.getDeclaredType().equals( NameIDType.class ))
- {
- NameIDType subjectNameID = (NameIDType) node.getValue();
-
- assertEquals( "jduke", subjectNameID.getValue() );
- assertEquals( "urn:picketlink:identity-federation", subjectNameID.getNameQualifier() );
- }
-
- if( node.getDeclaredType().equals( ConditionsType.class ))
- {
- //Conditions
- ConditionsType conditions = (ConditionsType) node.getValue();
- assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.869Z" ) , conditions.getNotBefore() );
- assertEquals( XMLTimeUtil.parse( "2010-09-30T21:13:37.869Z" ) , conditions.getNotOnOrAfter() );
- }
- } */
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(assertion);
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
/**
@@ -154,6 +138,13 @@
assertEquals(1, audienceRestrictionType.getAudience().size());
assertEquals("http://services.testcorp.org/provider2", audienceRestrictionType.getAudience().get(0)
.toASCIIString());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(assertion);
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
@Test
@@ -228,7 +219,12 @@
SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
- ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+ byte[] bytes = baos.toByteArray();
+ ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
DocumentUtil.getDocument(bis); //throws exceptions
+
+ String writtenString = new String(bytes);
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
}
\ No newline at end of file
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 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAuthnRequestParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -42,7 +42,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Nov 2, 2010
*/
-public class SAMLAuthnRequestParserTestCase
+public class SAMLAuthnRequestParserTestCase extends AbstractParserTest
{
@Test
public void testSAMLAuthnRequestParse() throws Exception
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -58,7 +58,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Nov 2, 2010
*/
-public class SAMLResponseParserTestCase
+public class SAMLResponseParserTestCase extends AbstractParserTest
{
@Test
public void testSAMLResponseParse() throws Exception
@@ -128,6 +128,14 @@
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
DocumentUtil.getDocument(bis); //throws exceptions
+
+ baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ writer = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(response);
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
@Test
@@ -196,6 +204,14 @@
if (!(str.equals("employee") || str.equals("manager")))
throw new RuntimeException("attrib value not found");
}
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAMLResponseWriter writer = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(response);
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
@Test
@@ -203,14 +219,15 @@
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream("saml-xacml/saml-xacml-response-1.xml");
-
+ validateSchema(configStream);
+ configStream = tcl.getResourceAsStream("saml-xacml/saml-xacml-response-1.xml");
SAMLParser parser = new SAMLParser();
ResponseType response = (ResponseType) parser.parse(configStream);
assertNotNull("ResponseType is not null", response);
//Get the assertion
AssertionType assertion = response.getAssertions().get(0).getAssertion();
- assertEquals("ID_response-id:1", assertion.getID());
+ assertEquals("ID_response-id_1", assertion.getID());
assertEquals(XMLTimeUtil.parse("2008-03-19T22:17:13Z"), assertion.getIssueInstant());
assertEquals("2.0", assertion.getVersion());
@@ -218,5 +235,13 @@
.iterator().next();
assertNotNull(xacmlStat.getRequest());
assertNotNull(xacmlStat.getResponse());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAMLResponseWriter writer = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(response);
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
}
\ No newline at end of file
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 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -41,7 +41,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Nov 3, 2010
*/
-public class SAMLSloRequestParserTestCase
+public class SAMLSloRequestParserTestCase extends AbstractParserTest
{
@Test
public void testSAMLLogOutRequestParsing() throws Exception
@@ -66,5 +66,13 @@
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
DocumentUtil.getDocument(bis); //throws exceptions
+
+ baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ writer = new SAMLRequestWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(lotRequest);
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
}
\ 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 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -46,7 +46,7 @@
* @author Anil.Saldhana(a)redhat.com
* @since Nov 3, 2010
*/
-public class SAMLSloResponseParserTestCase
+public class SAMLSloResponseParserTestCase extends AbstractParserTest
{
@Test
public void testSAMLResponseParse() throws Exception
@@ -79,6 +79,13 @@
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
DocumentUtil.getDocument(bis); //throws exceptions
+ baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ writer = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(response, new QName(PROTOCOL_NSURI.get(), LOGOUT_RESPONSE.get(), "samlp"));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+ validateSchema(writtenString);
}
@Test
Modified: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion-x500attrib.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion-x500attrib.xml 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion-x500attrib.xml 2011-06-30 23:50:05 UTC (rev 1047)
@@ -6,8 +6,38 @@
Version="2.0"
IssueInstant="2004-12-05T09:22:05Z">
<saml:Issuer>https://idp.example.org/SAML2</saml:Issuer>
- <ds:Signature
- xmlns:ds="http://www.w3.org/2000/09/xmldsig#"></ds:Signature>
+ <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
+ <ds:SignedInfo>
+ <ds:CanonicalizationMethod
+ Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" />
+ <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmlds#rsa-sha1" />
+ <ds:Reference URI="#ID_ab0392ef-b557-4453-95a8-a7e168da8ac5">
+ <ds:Transforms>
+ <ds:Transform Algorithm="http://www.w3.org/2000/09/xmlds#enveloped-signature" />
+ <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
+ </ds:Transforms>
+ <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmlds#sha1" />
+ <ds:DigestValue>0Y9QM5c5qCShz5UWmbFzBmbuTus=</ds:DigestValue>
+ </ds:Reference>
+ </ds:SignedInfo>
+ <ds:SignatureValue>
+ se/flQ2htUQ0IUYieVkXNn9cfjnfgv6H99nFarsTNTpRI9xuSlw5OTai/2PYdZI2Va9+QzzBf99m
+ VFyigfFdfrqug6aKFhF0lsujzlFfPfmXBbDRiTFX+4SkBeV71uuy7rOUI/jRiitEA0QrKqs0e/pV
+ +C8PoaariisK96Mtt7A=
+ </ds:SignatureValue>
+ <ds:KeyInfo>
+ <ds:KeyValue>
+ <ds:RSAKeyValue>
+ <ds:Modulus>
+ suGIyhVTbFvDwZdx8Av62zmP+aGOlsBN8WUE3eEEcDtOIZgO78SImMQGwB2C0eIVMhiLRzVPqoW1
+ dCPAveTm653zHOmubaps1fY0lLJDSZbTbhjeYhoQmmaBro/tDpVw5lKJwspqVnMuRK19ju2dxpKw
+ lYGGtrP5VQv00dfNPbs=
+ </ds:Modulus>
+ <ds:Exponent>AQAB</ds:Exponent>
+ </ds:RSAKeyValue>
+ </ds:KeyValue>
+ </ds:KeyInfo>
+ </ds:Signature>
<saml:Subject>
<saml:NameID
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">
Modified: 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 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml 2011-06-30 23:50:05 UTC (rev 1047)
@@ -6,4 +6,11 @@
IssueInstant="2010-07-29T13:46:20.647-05:00"
Version="2.0" >
<Issuer>http://localhost:8080/sales/</Issuer>
+ <saml:NameID xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
+ NameQualifier="urn:jboss:1.0"
+ SPNameQualifier="http://jboss.org"
+ Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">
+ YgolvKBPsL4ABSrdOpilovLnVq+X
+ </saml:NameID>
+
</ns3:LogoutRequest>
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/resources/saml-xacml/saml-xacml-response-1.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/saml-xacml/saml-xacml-response-1.xml 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-core/src/test/resources/saml-xacml/saml-xacml-response-1.xml 2011-06-30 23:50:05 UTC (rev 1047)
@@ -1,18 +1,18 @@
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
- ID="response-id:1" Version="2.0" IssueInstant="2008-03-19T22:17:13Z">
- <samlp:Status xmlns:samlp="urn:oasixacml-context:s:names:tc:SAML:2.0:protocol">
+ ID="response-id_1" Version="2.0" IssueInstant="2008-03-19T22:17:13Z">
+ <samlp:Status xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<samlp:StatusCode xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
Value="urn:oasis:names:tc:xacml:1.0:status:ok">
</samlp:StatusCode>
</samlp:Status>
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
- Version="2.0" ID="ID_response-id:1" IssueInstant="2008-03-19T22:17:13Z">
+ Version="2.0" ID="ID_response-id_1" IssueInstant="2008-03-19T22:17:13Z">
<saml:Issuer>issuer-1</saml:Issuer>
<saml:Statement xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
- xsi:type="xacml-samlp:XACMLAuthzDecisionStatementType"
+ xsi:type="xacml-saml:XACMLAuthzDecisionStatementType"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xacml-samlp="urn:oasis:xacml:2.0:saml:protocol:schema:os"
- xmlns:xacml-saml="urn:oasis:names:tc:xacml:2.0:saml:assertion:schema:os">
+ xmlns:xacml-saml="urn:oasis:xacml:2.0:saml:assertion:schema:os">
<xacml-context:Response
xmlns:xacml-context="urn:oasis:names:tc:xacml:2.0:context:schema:os">
<xacml-context:Result>
@@ -36,7 +36,7 @@
<xacml-context:Request
xmlns:xacml-context="urn:oasis:names:tc:xacml:2.0:context:schema:os"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance/"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:oasis:names:tc:xacml:2.0:context:schema:os
http://docs.oasis-open.org/xacml/access_control-xacml-2.0-context-schema-...">
<xacml-context:Subject
Modified: federation/trunk/picketlink-fed-model/src/main/java/org/picketlink/identity/federation/saml/v2/profiles/xacml/assertion/XACMLAuthzDecisionStatementType.java
===================================================================
--- federation/trunk/picketlink-fed-model/src/main/java/org/picketlink/identity/federation/saml/v2/profiles/xacml/assertion/XACMLAuthzDecisionStatementType.java 2011-06-30 14:45:36 UTC (rev 1046)
+++ federation/trunk/picketlink-fed-model/src/main/java/org/picketlink/identity/federation/saml/v2/profiles/xacml/assertion/XACMLAuthzDecisionStatementType.java 2011-06-30 23:50:05 UTC (rev 1047)
@@ -25,7 +25,6 @@
import org.jboss.security.xacml.core.model.context.ResponseType;
import org.picketlink.identity.federation.saml.v2.assertion.StatementAbstractType;
-
/**
* <p>Java class for XACMLAuthzDecisionStatementType complex type.
*
@@ -45,13 +44,15 @@
* </pre>
*
*
- */
-public class XACMLAuthzDecisionStatementType
-extends StatementAbstractType
-{
+ */
+public class XACMLAuthzDecisionStatementType extends StatementAbstractType
+{
private static final long serialVersionUID = 1L;
- public static final String XSI_TYPE = "xacml-samlp:XACMLAuthzDecisionStatementType";
+
+ public static final String XSI_TYPE = "xacml-saml:XACMLAuthzDecisionStatementType";
+
protected ResponseType response;
+
protected RequestType request;
/**
@@ -62,7 +63,8 @@
* {@link ResponseType }
*
*/
- public ResponseType getResponse() {
+ public ResponseType getResponse()
+ {
return response;
}
@@ -74,7 +76,8 @@
* {@link ResponseType }
*
*/
- public void setResponse(ResponseType value) {
+ public void setResponse(ResponseType value)
+ {
this.response = value;
}
@@ -86,7 +89,8 @@
* {@link RequestType }
*
*/
- public RequestType getRequest() {
+ public RequestType getRequest()
+ {
return request;
}
@@ -98,7 +102,8 @@
* {@link RequestType }
*
*/
- public void setRequest(RequestType value) {
+ public void setRequest(RequestType value)
+ {
this.request = value;
}
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-model/src/main/resources/schema/saml/v1/oasis-sstc-saml-schema-assertion-1.1.xsd
===================================================================
--- federation/trunk/picketlink-fed-model/src/main/resources/schema/saml/v1/oasis-sstc-saml-schema-assertion-1.1.xsd (rev 0)
+++ federation/trunk/picketlink-fed-model/src/main/resources/schema/saml/v1/oasis-sstc-saml-schema-assertion-1.1.xsd 2011-06-30 23:50:05 UTC (rev 1047)
@@ -0,0 +1,222 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema targetNamespace="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified" version="1.1">
+ <import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>
+ <annotation>
+ <documentation>
+ Document identifier: oasis-sstc-saml-schema-assertion-1.1
+ Location: http://www.oasis-open.org/committees/documents.php?wg_abbrev=security
+ Revision history:
+ V1.0 (November, 2002):
+ Initial standard schema.
+ V1.1 (September, 2003):
+ * Note that V1.1 of this schema has the same XML namespace as V1.0.
+ Rebased ID content directly on XML Schema types
+ Added DoNotCacheCondition element and DoNotCacheConditionType
+ </documentation>
+ </annotation>
+ <simpleType name="DecisionType">
+ <restriction base="string">
+
+ <enumeration value="Permit"/>
+ <enumeration value="Deny"/>
+ <enumeration value="Indeterminate"/>
+ </restriction>
+ </simpleType>
+ <element name="AssertionIDReference" type="NCName"/>
+ <element name="Assertion" type="saml:AssertionType"/>
+ <complexType name="AssertionType">
+ <sequence>
+
+ <element ref="saml:Conditions" minOccurs="0"/>
+ <element ref="saml:Advice" minOccurs="0"/>
+ <choice maxOccurs="unbounded">
+ <element ref="saml:Statement"/>
+ <element ref="saml:SubjectStatement"/>
+ <element ref="saml:AuthenticationStatement"/>
+ <element ref="saml:AuthorizationDecisionStatement"/>
+ <element ref="saml:AttributeStatement"/>
+ </choice>
+
+ <element ref="ds:Signature" minOccurs="0"/>
+ </sequence>
+ <attribute name="MajorVersion" type="integer" use="required"/>
+ <attribute name="MinorVersion" type="integer" use="required"/>
+ <attribute name="AssertionID" type="ID" use="required"/>
+ <attribute name="Issuer" type="string" use="required"/>
+ <attribute name="IssueInstant" type="dateTime" use="required"/>
+ </complexType>
+ <element name="Conditions" type="saml:ConditionsType"/>
+
+ <complexType name="ConditionsType">
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="saml:AudienceRestrictionCondition"/>
+ <element ref="saml:DoNotCacheCondition"/>
+ <element ref="saml:Condition"/>
+ </choice>
+ <attribute name="NotBefore" type="dateTime" use="optional"/>
+ <attribute name="NotOnOrAfter" type="dateTime" use="optional"/>
+ </complexType>
+
+ <element name="Condition" type="saml:ConditionAbstractType"/>
+ <complexType name="ConditionAbstractType" abstract="true"/>
+ <element name="AudienceRestrictionCondition" type="saml:AudienceRestrictionConditionType"/>
+ <complexType name="AudienceRestrictionConditionType">
+ <complexContent>
+ <extension base="saml:ConditionAbstractType">
+ <sequence>
+ <element ref="saml:Audience" maxOccurs="unbounded"/>
+ </sequence>
+
+ </extension>
+ </complexContent>
+ </complexType>
+ <element name="Audience" type="anyURI"/>
+ <element name="DoNotCacheCondition" type="saml:DoNotCacheConditionType"/>
+ <complexType name="DoNotCacheConditionType">
+ <complexContent>
+ <extension base="saml:ConditionAbstractType"/>
+ </complexContent>
+
+ </complexType>
+ <element name="Advice" type="saml:AdviceType"/>
+ <complexType name="AdviceType">
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="saml:AssertionIDReference"/>
+ <element ref="saml:Assertion"/>
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ </complexType>
+
+ <element name="Statement" type="saml:StatementAbstractType"/>
+ <complexType name="StatementAbstractType" abstract="true"/>
+ <element name="SubjectStatement" type="saml:SubjectStatementAbstractType"/>
+ <complexType name="SubjectStatementAbstractType" abstract="true">
+ <complexContent>
+ <extension base="saml:StatementAbstractType">
+ <sequence>
+ <element ref="saml:Subject"/>
+ </sequence>
+
+ </extension>
+ </complexContent>
+ </complexType>
+ <element name="Subject" type="saml:SubjectType"/>
+ <complexType name="SubjectType">
+ <choice>
+ <sequence>
+ <element ref="saml:NameIdentifier"/>
+ <element ref="saml:SubjectConfirmation" minOccurs="0"/>
+
+ </sequence>
+ <element ref="saml:SubjectConfirmation"/>
+ </choice>
+ </complexType>
+ <element name="NameIdentifier" type="saml:NameIdentifierType"/>
+ <complexType name="NameIdentifierType">
+ <simpleContent>
+ <extension base="string">
+ <attribute name="NameQualifier" type="string" use="optional"/>
+
+ <attribute name="Format" type="anyURI" use="optional"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ <element name="SubjectConfirmation" type="saml:SubjectConfirmationType"/>
+ <complexType name="SubjectConfirmationType">
+ <sequence>
+ <element ref="saml:ConfirmationMethod" maxOccurs="unbounded"/>
+ <element ref="saml:SubjectConfirmationData" minOccurs="0"/>
+
+ <element ref="ds:KeyInfo" minOccurs="0"/>
+ </sequence>
+ </complexType>
+ <element name="SubjectConfirmationData" type="anyType"/>
+ <element name="ConfirmationMethod" type="anyURI"/>
+ <element name="AuthenticationStatement" type="saml:AuthenticationStatementType"/>
+ <complexType name="AuthenticationStatementType">
+ <complexContent>
+ <extension base="saml:SubjectStatementAbstractType">
+
+ <sequence>
+ <element ref="saml:SubjectLocality" minOccurs="0"/>
+ <element ref="saml:AuthorityBinding" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="AuthenticationMethod" type="anyURI" use="required"/>
+ <attribute name="AuthenticationInstant" type="dateTime" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <element name="SubjectLocality" type="saml:SubjectLocalityType"/>
+ <complexType name="SubjectLocalityType">
+ <attribute name="IPAddress" type="string" use="optional"/>
+ <attribute name="DNSAddress" type="string" use="optional"/>
+ </complexType>
+ <element name="AuthorityBinding" type="saml:AuthorityBindingType"/>
+ <complexType name="AuthorityBindingType">
+ <attribute name="AuthorityKind" type="QName" use="required"/>
+ <attribute name="Location" type="anyURI" use="required"/>
+
+ <attribute name="Binding" type="anyURI" use="required"/>
+ </complexType>
+ <element name="AuthorizationDecisionStatement" type="saml:AuthorizationDecisionStatementType"/>
+ <complexType name="AuthorizationDecisionStatementType">
+ <complexContent>
+ <extension base="saml:SubjectStatementAbstractType">
+ <sequence>
+ <element ref="saml:Action" maxOccurs="unbounded"/>
+ <element ref="saml:Evidence" minOccurs="0"/>
+
+ </sequence>
+ <attribute name="Resource" type="anyURI" use="required"/>
+ <attribute name="Decision" type="saml:DecisionType" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+ <element name="Action" type="saml:ActionType"/>
+ <complexType name="ActionType">
+ <simpleContent>
+
+ <extension base="string">
+ <attribute name="Namespace" type="anyURI"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ <element name="Evidence" type="saml:EvidenceType"/>
+ <complexType name="EvidenceType">
+ <choice maxOccurs="unbounded">
+ <element ref="saml:AssertionIDReference"/>
+
+ <element ref="saml:Assertion"/>
+ </choice>
+ </complexType>
+ <element name="AttributeStatement" type="saml:AttributeStatementType"/>
+ <complexType name="AttributeStatementType">
+ <complexContent>
+ <extension base="saml:SubjectStatementAbstractType">
+ <sequence>
+ <element ref="saml:Attribute" maxOccurs="unbounded"/>
+
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+ <element name="AttributeDesignator" type="saml:AttributeDesignatorType"/>
+ <complexType name="AttributeDesignatorType">
+ <attribute name="AttributeName" type="string" use="required"/>
+ <attribute name="AttributeNamespace" type="anyURI" use="required"/>
+ </complexType>
+
+ <element name="Attribute" type="saml:AttributeType"/>
+ <complexType name="AttributeType">
+ <complexContent>
+ <extension base="saml:AttributeDesignatorType">
+ <sequence>
+ <element ref="saml:AttributeValue" maxOccurs="unbounded"/>
+ </sequence>
+ </extension>
+ </complexContent>
+
+ </complexType>
+ <element name="AttributeValue" type="anyType"/>
+</schema>
Added: federation/trunk/picketlink-xmlsec-model/src/main/resources/schema/w3c/xmlschema/xml.xsd
===================================================================
--- federation/trunk/picketlink-xmlsec-model/src/main/resources/schema/w3c/xmlschema/xml.xsd (rev 0)
+++ federation/trunk/picketlink-xmlsec-model/src/main/resources/schema/w3c/xmlschema/xml.xsd 2011-06-30 23:50:05 UTC (rev 1047)
@@ -0,0 +1,120 @@
+<?xml version='1.0'?>
+<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" >
+<xs:schema targetNamespace="http://www.w3.org/XML/1998/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:lang="en">
+
+ <xs:annotation>
+ <xs:documentation>
+ See http://www.w3.org/XML/1998/namespace.html and
+ http://www.w3.org/TR/REC-xml for information about this namespace.
+
+ This schema document describes the XML namespace, in a form
+ suitable for import by other schema documents.
+
+ Note that local names in this namespace are intended to be defined
+ only by the World Wide Web Consortium or its subgroups. The
+ following names are currently defined in this namespace and should
+ not be used with conflicting semantics by any Working Group,
+ specification, or document instance:
+
+ base (as an attribute name): denotes an attribute whose value
+ provides a URI to be used as the base for interpreting any
+ relative URIs in the scope of the element on which it
+ appears; its value is inherited. This name is reserved
+ by virtue of its definition in the XML Base specification.
+
+ lang (as an attribute name): denotes an attribute whose value
+ is a language code for the natural language of the content of
+ any element; its value is inherited. This name is reserved
+ by virtue of its definition in the XML specification.
+
+ space (as an attribute name): denotes an attribute whose
+ value is a keyword indicating what whitespace processing
+ discipline is intended for the content of the element; its
+ value is inherited. This name is reserved by virtue of its
+ definition in the XML specification.
+
+ Father (in any context at all): denotes Jon Bosak, the chair of
+ the original XML Working Group. This name is reserved by
+ the following decision of the W3C XML Plenary and
+ XML Coordination groups:
+
+ In appreciation for his vision, leadership and dedication
+ the W3C XML Plenary on this 10th day of February, 2000
+ reserves for Jon Bosak in perpetuity the XML name
+ xml:Father
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:annotation>
+ <xs:documentation>This schema defines attributes and an attribute group
+ suitable for use by
+ schemas wishing to allow xml:base, xml:lang or xml:space attributes
+ on elements they define.
+
+ To enable this, such a schema must import this schema
+ for the XML namespace, e.g. as follows:
+ <schema . . .>
+ . . .
+ <import namespace="http://www.w3.org/XML/1998/namespace"
+ schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
+
+ Subsequently, qualified reference to any of the attributes
+ or the group defined below will have the desired effect, e.g.
+
+ <type . . .>
+ . . .
+ <attributeGroup ref="xml:specialAttrs"/>
+
+ will define a type which will schema-validate an instance
+ element with any of those attributes</xs:documentation>
+
+ </xs:annotation>
+
+ <xs:annotation>
+ <xs:documentation>In keeping with the XML Schema WG's standard versioning
+ policy, this schema document will persist at
+ http://www.w3.org/2001/03/xml.xsd.
+ At the date of issue it can also be found at
+ http://www.w3.org/2001/xml.xsd.
+ The schema document at that URI may however change in the future,
+ in order to remain compatible with the latest version of XML Schema
+ itself. In other words, if the XML Schema namespace changes, the version
+ of this document at
+ http://www.w3.org/2001/xml.xsd will change
+ accordingly; the version at
+ http://www.w3.org/2001/03/xml.xsd will not change.
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:attribute name="lang" type="xs:language">
+ <xs:annotation>
+ <xs:documentation>In due course, we should install the relevant ISO 2- and 3-letter
+ codes as the enumerated possible values . . .</xs:documentation>
+
+ </xs:annotation>
+ </xs:attribute>
+
+ <xs:attribute name="space" default="preserve">
+ <xs:simpleType>
+ <xs:restriction base="xs:NCName">
+ <xs:enumeration value="default"/>
+ <xs:enumeration value="preserve"/>
+ </xs:restriction>
+
+ </xs:simpleType>
+ </xs:attribute>
+
+ <xs:attribute name="base" type="xs:anyURI">
+ <xs:annotation>
+ <xs:documentation>See http://www.w3.org/TR/xmlbase/ for
+ information about this attribute.</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+
+ <xs:attributeGroup name="specialAttrs">
+ <xs:attribute ref="xml:base"/>
+ <xs:attribute ref="xml:lang"/>
+ <xs:attribute ref="xml:space"/>
+ </xs:attributeGroup>
+
+</xs:schema>
13 years, 5 months
Picketlink SVN: r1046 - in integration-tests/trunk: common-dist/jbossws and 2 other directories.
by picketlink-commits@lists.jboss.org
Author: sguilhen(a)redhat.com
Date: 2011-06-30 10:45:36 -0400 (Thu, 30 Jun 2011)
New Revision: 1046
Added:
integration-tests/trunk/common-dist/jbossws/3.4.1.GA/
integration-tests/trunk/common-dist/jbossws/3.4.1.GA/jbossws-cxf-3.4.1.GA.zip
Modified:
integration-tests/trunk/ant-scripts/ant-build.xml
integration-tests/trunk/picketlink-sts-jbas6-cxf/pom.xml
Log:
Upgraded the JBoss WS CXF version used in the integration tests
Modified: integration-tests/trunk/ant-scripts/ant-build.xml
===================================================================
--- integration-tests/trunk/ant-scripts/ant-build.xml 2011-06-29 20:20:18 UTC (rev 1045)
+++ integration-tests/trunk/ant-scripts/ant-build.xml 2011-06-30 14:45:36 UTC (rev 1046)
@@ -8,7 +8,7 @@
<property name="TOMCAT6" location="${basedir}/target/apache-tomcat-6.0.26/" />
<property name="TOMCAT6_DEPLOY" location="${basedir}/target/apache-tomcat-6.0.26/webapps/" />
<property name="TOMCAT6_LIB" location="${basedir}/target/apache-tomcat-6.0.26/lib/" />
- <property name="JBWS_CXF_ZIP" location="${basedir}/../common-dist/jbossws/3.3.1.GA/jbossws-cxf-3.3.1.GA.zip"/>
+ <property name="JBWS_CXF_ZIP" location="${basedir}/../common-dist/jbossws/3.4.1.GA/jbossws-cxf-3.4.1.GA.zip"/>
<property name="JBWS_CXF_HOME" location="${basedir}/target/jbossws-cxf-bin-dist/"/>
<property environment="env" />
Added: integration-tests/trunk/common-dist/jbossws/3.4.1.GA/jbossws-cxf-3.4.1.GA.zip
===================================================================
(Binary files differ)
Property changes on: integration-tests/trunk/common-dist/jbossws/3.4.1.GA/jbossws-cxf-3.4.1.GA.zip
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: integration-tests/trunk/picketlink-sts-jbas6-cxf/pom.xml
===================================================================
--- integration-tests/trunk/picketlink-sts-jbas6-cxf/pom.xml 2011-06-29 20:20:18 UTC (rev 1045)
+++ integration-tests/trunk/picketlink-sts-jbas6-cxf/pom.xml 2011-06-30 14:45:36 UTC (rev 1046)
@@ -55,7 +55,7 @@
<property name="depclasspath" refid="maven.dependency.classpath"/>
<property name="localRepository" value="${user.home}/.m2/repository"/>
<ant antfile="${basedir}/../ant-scripts/ant-build.xml" target="init-jboss6" />
- <ant antfile="${basedir}/../ant-scripts/ant-build.xml" target="install-jbws-cxf-jbas6" />
+ <!--ant antfile="${basedir}/../ant-scripts/ant-build.xml" target="install-jbws-cxf-jbas6" /-->
<ant antfile="${basedir}/../ant-scripts/ant-build.xml" target="copy-sts-props-jbas6" />
<ant antfile="${basedir}/../ant-scripts/ant-build.xml" target="start-jboss6" />
</tasks>
13 years, 5 months
Picketlink SVN: r1045 - in federation/trunk/picketlink-fed-core/src: test/java/org/picketlink/test/identity/federation/core/parser/saml and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-29 16:20:18 -0400 (Wed, 29 Jun 2011)
New Revision: 1045
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/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11AssertionParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-assertion-keyinfo.xml
Log:
PLFED-192: writing
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-29 20:15:26 UTC (rev 1044)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java 2011-06-29 20:20:18 UTC (rev 1045)
@@ -297,6 +297,12 @@
if (subject != null)
write(subject);
+ List<SAML11ActionType> actions = xacmlStat.getActions();
+ for (SAML11ActionType action : actions)
+ {
+ write(action);
+ }
+
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
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-29 20:15:26 UTC (rev 1044)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11AssertionParserTestCase.java 2011-06-29 20:20:18 UTC (rev 1045)
@@ -27,11 +27,16 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.io.StringReader;
import java.net.URI;
import java.util.List;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Validator;
+
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
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;
@@ -94,7 +99,12 @@
//Lets do the writing
SAML11AssertionWriter writer = new SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -157,7 +167,12 @@
//Lets do the writing
SAML11AssertionWriter writer = new SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -185,7 +200,12 @@
//Lets do the writing
SAML11AssertionWriter writer = new SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -262,7 +282,12 @@
//Lets do the writing
SAML11AssertionWriter writer = new SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -303,6 +328,11 @@
//Lets do the writing
SAML11AssertionWriter writer = new SAML11AssertionWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(assertion);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-assertion-keyinfo.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-assertion-keyinfo.xml 2011-06-29 20:15:26 UTC (rev 1044)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-assertion-keyinfo.xml 2011-06-29 20:20:18 UTC (rev 1045)
@@ -12,7 +12,7 @@
<KeyName>CN=anil, OU=PicketLink, O=JBoss, L=Chicago, ST=IL, C=US</KeyName>
<KeyValue>
<RSAKeyValue>
- <Modulus>dsfdfdskjfdsf;dfjds;fdsjfdsfdsjf</Modulus>
+ <Modulus>YWJjZA==</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
@@ -36,7 +36,7 @@
<SignatureValue>ApcX/Ddfsfdslkfd</SignatureValue>
<KeyInfo>
<X509Data>
- <X509Certificate>MIICmjdfdflkfdslfaf;sjdposafhpofhpowfowqpowqfow
+ <X509Certificate>YWJjZA==
</X509Certificate>
</X509Data>
</KeyInfo>
13 years, 5 months
Picketlink SVN: r1044 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v1/writers and 2 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-29 16:15:26 -0400 (Wed, 29 Jun 2011)
New Revision: 1044
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/SAML11RequestWriter.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.java
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/SAML11ResponseParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-request-authzquery.xml
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-response.xml
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-29 20:14:53 UTC (rev 1043)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/SAML11Constants.java 2011-06-29 20:15:26 UTC (rev 1044)
@@ -94,7 +94,7 @@
String NAME_QUALIFIER = "NameQualifier";
- String NAMESPACE = "NameSpace";
+ String NAMESPACE = "Namespace";
String PROTOCOL_11_NSURI = "urn:oasis:names:tc:SAML:1.0:protocol";
Modified: 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 2011-06-29 20:14:53 UTC (rev 1043)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11RequestWriter.java 2011-06-29 20:15:26 UTC (rev 1044)
@@ -62,6 +62,7 @@
{
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.REQUEST, namespace);
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
+ StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_11_NSURI);
StaxUtil.writeDefaultNameSpace(writer, namespace);
// Attributes
@@ -73,7 +74,8 @@
List<String> assertionIDRefs = request.getAssertionIDRef();
for (String assertionIDRef : assertionIDRefs)
{
- StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.ASSERTION_ID_REF, namespace);
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_ID_REF,
+ SAML11Constants.ASSERTION_11_NSURI);
StaxUtil.writeCharacters(writer, assertionIDRef);
StaxUtil.writeEndElement(writer);
}
@@ -166,7 +168,7 @@
public void write(SAML11AuthorizationDecisionQueryType attr) throws ProcessingException
{
- StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.ATTRIBUTE_QUERY, namespace);
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.AUTHORIZATION_DECISION_QUERY, namespace);
URI resource = attr.getResource();
if (resource != null)
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.java 2011-06-29 20:14:53 UTC (rev 1043)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.java 2011-06-29 20:15:26 UTC (rev 1044)
@@ -60,6 +60,7 @@
{
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.RESPONSE, namespace);
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
+ StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, SAML11Constants.ASSERTION_11_NSURI);
// Attributes
StaxUtil.writeAttribute(writer, SAML11Constants.RESPONSE_ID, response.getID());
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-29 20:14:53 UTC (rev 1043)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11RequestParserTestCase.java 2011-06-29 20:15:26 UTC (rev 1044)
@@ -27,10 +27,15 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.io.StringReader;
import java.util.List;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Validator;
+
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
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;
@@ -77,7 +82,12 @@
//Lets do the writing
SAML11RequestWriter writer = new SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(request);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -107,7 +117,12 @@
//Lets do the writing
SAML11RequestWriter writer = new SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(request);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -122,7 +137,7 @@
assertEquals(1, request.getMajorVersion());
assertEquals(1, request.getMinorVersion());
- assertEquals("1234", request.getID());
+ assertEquals("R1234", request.getID());
assertEquals(XMLTimeUtil.parse("2002-08-05T10:04:15"), request.getIssueInstant());
SAML11QueryAbstractType query = request.getQuery();
@@ -146,7 +161,12 @@
//Lets do the writing
SAML11RequestWriter writer = new SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(request);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -170,7 +190,12 @@
//Lets do the writing
SAML11RequestWriter writer = new SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(request);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
@Test
@@ -194,6 +219,11 @@
//Lets do the writing
SAML11RequestWriter writer = new SAML11RequestWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(request);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java 2011-06-29 20:14:53 UTC (rev 1043)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java 2011-06-29 20:15:26 UTC (rev 1044)
@@ -26,11 +26,16 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.io.StringReader;
import java.util.List;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Validator;
+
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAML11ResponseParser;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.saml.v1.writers.SAML11ResponseWriter;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
import org.picketlink.identity.federation.core.util.StaxUtil;
@@ -58,7 +63,7 @@
assertEquals(1, response.getMajorVersion());
assertEquals(1, response.getMinorVersion());
- assertEquals("_P1YaA+Q/wSM/t/8E3R8rNhcpPTM=", response.getID());
+ assertEquals("P1234", response.getID());
assertEquals(XMLTimeUtil.parse("2002-06-19T17:05:37.795Z"), response.getIssueInstant());
assertNotNull(response.getSignature());
@@ -76,6 +81,11 @@
//Lets do the writing
SAML11ResponseWriter writer = new SAML11ResponseWriter(StaxUtil.getXMLStreamWriter(baos));
writer.write(response);
- System.out.println(new String(baos.toByteArray()));
+ String writtenString = new String(baos.toByteArray());
+ System.out.println(writtenString);
+
+ Validator validator = StaxParserUtil.getSchemaValidator();
+ assertNotNull(validator);
+ validator.validate(new StreamSource(new StringReader(writtenString)));
}
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-request-authzquery.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-request-authzquery.xml 2011-06-29 20:14:53 UTC (rev 1043)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-request-authzquery.xml 2011-06-29 20:15:26 UTC (rev 1044)
@@ -1,4 +1,4 @@
-<Request RequestID="1234" MajorVersion="1" MinorVersion="1"
+<Request RequestID="R1234" MajorVersion="1" MinorVersion="1"
IssueInstant="2002-08-05T10:04:15"
xmlns="urn:oasis:names:tc:SAML:1.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
@@ -10,6 +10,6 @@
anil(a)anil.org
</saml:NameIdentifier>
</saml:Subject>
- <saml:Action NameSpace="http://www.jboss.org">create</saml:Action>
+ <saml:Action Namespace="http://www.jboss.org">create</saml:Action>
</AuthorizationDecisionQuery>
</Request>
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-response.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-response.xml 2011-06-29 20:14:53 UTC (rev 1043)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml1/saml1-response.xml 2011-06-29 20:15:26 UTC (rev 1044)
@@ -1,7 +1,7 @@
<samlp:Response
xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol"
MajorVersion="1" MinorVersion="1"
- ResponseID="_P1YaA+Q/wSM/t/8E3R8rNhcpPTM="
+ ResponseID="P1234"
IssueInstant="2002-06-19T17:05:37.795Z">
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
@@ -19,7 +19,7 @@
<SignatureValue>ApcX/Ddfsfdslkfd</SignatureValue>
<KeyInfo>
<X509Data>
- <X509Certificate>MIICmjdfdflkfdslfaf;sjdposafhpofhpowfowqpowqfow
+ <X509Certificate>YWJjZA==
</X509Certificate>
</X509Data>
</KeyInfo>
13 years, 5 months
Picketlink SVN: r1043 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-29 16:14:53 -0400 (Wed, 29 Jun 2011)
New Revision: 1043
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SecurityActions.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
Log:
PLFED-188: add validator construction in StaxParserUtil
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SecurityActions.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SecurityActions.java 2011-06-29 18:59:42 UTC (rev 1042)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SecurityActions.java 2011-06-29 20:14:53 UTC (rev 1043)
@@ -21,6 +21,7 @@
*/
package org.picketlink.identity.federation.core.parsers.util;
+import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -37,14 +38,42 @@
* @param defaultValue
* @return
*/
- static String getSystemProperty( final String key, final String defaultValue )
+ static String getSystemProperty(final String key, final String defaultValue)
{
- return AccessController.doPrivileged( new PrivilegedAction<String>()
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
{
public String run()
{
- return System.getProperty( key, defaultValue );
+ return System.getProperty(key, defaultValue);
}
- } );
+ });
}
+
+ /**
+ * Load a resource based on the passed {@link Class} classloader.
+ * Failing which try with the Thread Context CL
+ * @param clazz
+ * @param resourceName
+ * @return
+ */
+ static URL loadResource(final Class<?> clazz, final String resourceName)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>()
+ {
+ public URL run()
+ {
+ URL url = null;
+ ClassLoader clazzLoader = clazz.getClassLoader();
+ url = clazzLoader.getResource(resourceName);
+
+ if (url == null)
+ {
+ clazzLoader = Thread.currentThread().getContextClassLoader();
+ url = clazzLoader.getResource(resourceName);
+ }
+
+ return url;
+ }
+ });
+ }
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2011-06-29 18:59:42 UTC (rev 1042)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2011-06-29 20:14:53 UTC (rev 1043)
@@ -22,6 +22,7 @@
package org.picketlink.identity.federation.core.parsers.util;
import java.io.InputStream;
+import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
@@ -32,12 +33,18 @@
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
+import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stax.StAXSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+import org.apache.log4j.Logger;
import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
-import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
@@ -45,7 +52,9 @@
import org.picketlink.identity.federation.core.util.TransformerUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
/**
* Utility for the stax based parser
@@ -53,26 +62,32 @@
* @since Feb 8, 2010
*/
public class StaxParserUtil
-{
+{
+ protected static Logger log = Logger.getLogger(StaxParserUtil.class);
+
+ protected static boolean trace = log.isTraceEnabled();
+
+ protected static Validator validator = null;
+
/**
* Bypass an entire XML element block from startElement to endElement
* @param xmlEventReader
* @param tag Tag of the XML element that we need to bypass
* @throws ParsingException
*/
- public static void bypassElementBlock( XMLEventReader xmlEventReader, String tag ) throws ParsingException
+ public static void bypassElementBlock(XMLEventReader xmlEventReader, String tag) throws ParsingException
{
- while ( xmlEventReader.hasNext() )
+ while (xmlEventReader.hasNext())
{
- EndElement endElement = getNextEndElement( xmlEventReader );
- if( endElement == null )
+ EndElement endElement = getNextEndElement(xmlEventReader);
+ if (endElement == null)
return;
- if( StaxParserUtil.matches( endElement , tag ) )
+ if (StaxParserUtil.matches(endElement, tag))
return;
}
}
-
+
/**
* Given an {@code Attribute}, get its trimmed value
* @param attribute
@@ -84,22 +99,22 @@
str = StringUtil.getSystemPropertyAsString(str);
return str;
}
-
+
/**
* Get the Attribute value
* @param startElement
* @param tag localpart of the qname of the attribute
* @return
*/
- public static String getAttributeValue( StartElement startElement, String tag )
+ public static String getAttributeValue(StartElement startElement, String tag)
{
String result = null;
- Attribute attr = startElement.getAttributeByName( new QName( tag ));
- if( attr != null )
+ Attribute attr = startElement.getAttributeByName(new QName(tag));
+ if (attr != null)
result = getAttributeValue(attr);
return result;
}
-
+
/**
* Given that the {@code XMLEventReader} is in {@code XMLStreamConstants.START_ELEMENT}
* mode, we parse into a DOM Element
@@ -107,44 +122,45 @@
* @return
* @throws ParsingException
*/
- public static Element getDOMElement( XMLEventReader xmlEventReader ) throws ParsingException
+ public static Element getDOMElement(XMLEventReader xmlEventReader) throws ParsingException
{
Transformer transformer = null;
final String JDK_TRANSFORMER_PROPERTY = "picketlink.jdk.transformer";
-
- boolean useJDKTransformer = Boolean.parseBoolean( SecurityActions.getSystemProperty(JDK_TRANSFORMER_PROPERTY, "false" ));
+ boolean useJDKTransformer = Boolean.parseBoolean(SecurityActions.getSystemProperty(JDK_TRANSFORMER_PROPERTY,
+ "false"));
+
try
- {
- if( useJDKTransformer )
+ {
+ if (useJDKTransformer)
{
transformer = TransformerUtil.getTransformer();
}
else
{
transformer = TransformerUtil.getStaxSourceToDomResultTransformer();
- }
+ }
Document resultDocument = DocumentUtil.createDocument();
- DOMResult domResult = new DOMResult( resultDocument );
-
- StAXSource source = new StAXSource( xmlEventReader );
+ DOMResult domResult = new DOMResult(resultDocument);
- TransformerUtil.transform( transformer, source, domResult );
+ StAXSource source = new StAXSource(xmlEventReader);
- Document doc = ( Document ) domResult.getNode();
+ TransformerUtil.transform(transformer, source, domResult);
+
+ Document doc = (Document) domResult.getNode();
return doc.getDocumentElement();
}
- catch ( ConfigurationException e )
+ catch (ConfigurationException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
- catch ( XMLStreamException e )
+ catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
- }
+ }
/**
* Get the element text.
@@ -152,47 +168,47 @@
* @return A <b>trimmed</b> string value
* @throws ParsingException
*/
- public static String getElementText( XMLEventReader xmlEventReader ) throws ParsingException
- {
+ public static String getElementText(XMLEventReader xmlEventReader) throws ParsingException
+ {
String str = null;
try
{
- str = xmlEventReader.getElementText().trim();
+ str = xmlEventReader.getElementText().trim();
str = StringUtil.getSystemPropertyAsString(str);
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
return str;
}
-
+
/**
* Get the XML event reader
* @param is
* @return
*/
- public static XMLEventReader getXMLEventReader( InputStream is )
+ public static XMLEventReader getXMLEventReader(InputStream is)
{
XMLInputFactory xmlInputFactory = null;
XMLEventReader xmlEventReader = null;
- try
+ try
{
- xmlInputFactory = XMLInputFactory.newInstance();
- xmlInputFactory.setProperty( XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE );
- xmlInputFactory.setProperty( XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE );
- xmlInputFactory.setProperty( XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE );
- xmlInputFactory.setProperty( XMLInputFactory.IS_COALESCING, Boolean.TRUE );
-
- xmlEventReader = xmlInputFactory.createXMLEventReader(is);
- }
- catch (Exception ex)
+ xmlInputFactory = XMLInputFactory.newInstance();
+ xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
+ xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
+ xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
+ xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
+
+ xmlEventReader = xmlInputFactory.createXMLEventReader(is);
+ }
+ catch (Exception ex)
{
- throw new RuntimeException(ex);
+ throw new RuntimeException(ex);
}
return xmlEventReader;
- }
-
+ }
+
/**
* Given a {@code Location}, return a formatted string
* [lineNum,colNum]
@@ -201,79 +217,79 @@
*/
public static String getLineColumnNumber(Location location)
{
- StringBuilder builder = new StringBuilder("[");
- builder.append(location.getLineNumber()).append(",").append(location.getColumnNumber()).append("]");
- return builder.toString();
+ StringBuilder builder = new StringBuilder("[");
+ builder.append(location.getLineNumber()).append(",").append(location.getColumnNumber()).append("]");
+ return builder.toString();
}
-
+
/**
* Get the next xml event
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static XMLEvent getNextEvent( XMLEventReader xmlEventReader ) throws ParsingException
+ public static XMLEvent getNextEvent(XMLEventReader xmlEventReader) throws ParsingException
{
try
{
return xmlEventReader.nextEvent();
}
- catch ( XMLStreamException e)
+ catch (XMLStreamException e)
{
- throw new ParsingException( e );
- }
+ throw new ParsingException(e);
+ }
}
-
+
/**
* Get the next {@code StartElement }
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static StartElement getNextStartElement( XMLEventReader xmlEventReader ) throws ParsingException
+ public static StartElement getNextStartElement(XMLEventReader xmlEventReader) throws ParsingException
{
try
{
- while( xmlEventReader.hasNext() )
+ while (xmlEventReader.hasNext())
{
- XMLEvent xmlEvent = xmlEventReader.nextEvent();
-
- if( xmlEvent == null || xmlEvent.isStartElement() )
- return ( StartElement ) xmlEvent;
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+
+ if (xmlEvent == null || xmlEvent.isStartElement())
+ return (StartElement) xmlEvent;
}
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
return null;
}
-
+
/**
* Get the next {@code EndElement}
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static EndElement getNextEndElement( XMLEventReader xmlEventReader ) throws ParsingException
+ public static EndElement getNextEndElement(XMLEventReader xmlEventReader) throws ParsingException
{
try
{
- while( xmlEventReader.hasNext() )
+ while (xmlEventReader.hasNext())
{
- XMLEvent xmlEvent = xmlEventReader.nextEvent();
-
- if( xmlEvent == null || xmlEvent.isEndElement() )
- return ( EndElement ) xmlEvent;
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+
+ if (xmlEvent == null || xmlEvent.isEndElement())
+ return (EndElement) xmlEvent;
}
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
return null;
}
-
+
/**
* Return the name of the start element
* @param startElement
@@ -283,76 +299,75 @@
{
return trim(startElement.getName().getLocalPart());
}
-
+
/**
* Return the name of the end element
* @param endElement
* @return
*/
- public static String getEndElementName( EndElement endElement )
+ public static String getEndElementName(EndElement endElement)
{
- return trim( endElement.getName().getLocalPart() );
+ return trim(endElement.getName().getLocalPart());
}
-
+
/**
* Given a start element, obtain the xsi:type defined
* @param startElement
* @return
* @throws RuntimeException if xsi:type is missing
*/
- public static String getXSITypeValue( StartElement startElement )
+ public static String getXSITypeValue(StartElement startElement)
{
- Attribute xsiType = startElement.getAttributeByName( new QName( JBossSAMLURIConstants.XSI_NSURI.get(),
- JBossSAMLConstants.TYPE.get() ));
- if( xsiType == null )
- throw new RuntimeException( "xsi:type expected" );
- return StaxParserUtil.getAttributeValue( xsiType );
+ Attribute xsiType = startElement.getAttributeByName(new QName(JBossSAMLURIConstants.XSI_NSURI.get(),
+ JBossSAMLConstants.TYPE.get()));
+ if (xsiType == null)
+ throw new RuntimeException("xsi:type expected");
+ return StaxParserUtil.getAttributeValue(xsiType);
}
-
+
/**
* Return whether the next event is going to be text
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static boolean hasTextAhead( XMLEventReader xmlEventReader ) throws ParsingException
+ public static boolean hasTextAhead(XMLEventReader xmlEventReader) throws ParsingException
{
- XMLEvent event = peek( xmlEventReader );
- return event.getEventType() == XMLEvent.CHARACTERS;
+ XMLEvent event = peek(xmlEventReader);
+ return event.getEventType() == XMLEvent.CHARACTERS;
}
-
-
+
/**
* Match that the start element with the expected tag
* @param startElement
* @param tag
* @return boolean if the tags match
*/
- public static boolean matches( StartElement startElement, String tag )
+ public static boolean matches(StartElement startElement, String tag)
{
- String elementTag = getStartElementName( startElement );
- return tag.equals( elementTag );
+ String elementTag = getStartElementName(startElement);
+ return tag.equals(elementTag);
}
-
+
/**
* Match that the end element with the expected tag
* @param endElement
* @param tag
* @return boolean if the tags match
*/
- public static boolean matches( EndElement endElement, String tag )
+ public static boolean matches(EndElement endElement, String tag)
{
- String elementTag = getEndElementName( endElement );
- return tag.equals( elementTag );
+ String elementTag = getEndElementName(endElement);
+ return tag.equals(elementTag);
}
-
+
/**
* Peek at the next event
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static XMLEvent peek( XMLEventReader xmlEventReader ) throws ParsingException
+ public static XMLEvent peek(XMLEventReader xmlEventReader) throws ParsingException
{
try
{
@@ -360,62 +375,62 @@
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
}
-
+
/**
* Peek the next {@code StartElement }
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static StartElement peekNextStartElement( XMLEventReader xmlEventReader ) throws ParsingException
+ public static StartElement peekNextStartElement(XMLEventReader xmlEventReader) throws ParsingException
{
try
{
- while( true )
+ while (true)
{
- XMLEvent xmlEvent = xmlEventReader.peek();
-
- if( xmlEvent == null || xmlEvent.isStartElement() )
- return ( StartElement ) xmlEvent;
- else
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ if (xmlEvent == null || xmlEvent.isStartElement())
+ return (StartElement) xmlEvent;
+ else
xmlEvent = xmlEventReader.nextEvent();
}
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
}
-
+
/**
* Peek the next {@code EndElement}
* @param xmlEventReader
* @return
* @throws ParsingException
*/
- public static EndElement peekNextEndElement( XMLEventReader xmlEventReader ) throws ParsingException
+ public static EndElement peekNextEndElement(XMLEventReader xmlEventReader) throws ParsingException
{
try
{
- while( true )
+ while (true)
{
- XMLEvent xmlEvent = xmlEventReader.peek();
-
- if( xmlEvent == null || xmlEvent.isEndElement() )
- return ( EndElement ) xmlEvent;
- else
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ if (xmlEvent == null || xmlEvent.isEndElement())
+ return (EndElement) xmlEvent;
+ else
xmlEvent = xmlEventReader.nextEvent();
}
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException(e);
}
}
-
+
/**
* Given a string, trim it
* @param str
@@ -424,34 +439,113 @@
*/
public static final String trim(String str)
{
- if(str == null || str.length() == 0)
+ if (str == null || str.length() == 0)
throw new IllegalArgumentException("Input str is null");
return str.trim();
}
-
+
/**
* Validate that the start element has the expected tag
* @param startElement
* @param tag
* @throws RuntimeException mismatch
*/
- public static void validate( StartElement startElement, String tag )
+ public static void validate(StartElement startElement, String tag)
{
- String elementTag = getStartElementName( startElement );
- if( !tag.equals( elementTag ))
- throw new RuntimeException( "Expecting <" + tag + ">. Found <" + elementTag + ">" );
+ String elementTag = getStartElementName(startElement);
+ if (!tag.equals(elementTag))
+ throw new RuntimeException("Expecting <" + tag + ">. Found <" + elementTag + ">");
}
-
+
/**
* Validate that the end element has the expected tag
* @param endElement
* @param tag
* @throws RuntimeException mismatch
*/
- public static void validate( EndElement endElement, String tag )
+ public static void validate(EndElement endElement, String tag)
{
- String elementTag = getEndElementName( endElement );
- if( !tag.equals( elementTag ))
- throw new RuntimeException( "Expecting </" + tag + ">. Found </" + elementTag + ">" );
+ String elementTag = getEndElementName(endElement);
+ if (!tag.equals(elementTag))
+ throw new RuntimeException("Expecting </" + tag + ">. Found </" + elementTag + ">");
}
+
+ public static Validator getSchemaValidator()
+ {
+ if (validator == null)
+ {
+ try
+ {
+ final Class<?> clazz = StaxParserUtil.class;
+
+ URL saml1Assertion = SecurityActions.loadResource(clazz, "schema/saml/v1/saml-schema-assertion-1.0.xsd");
+ URL saml1Protocol = SecurityActions.loadResource(clazz, "schema/saml/v1/saml-schema-protocol-1.1.xsd");
+ URL dsig = SecurityActions.loadResource(clazz, "schema/w3c/xmldsig/xmldsig-core-schema.xsd");
+ URL xmlenc = SecurityActions.loadResource(clazz, "schema/w3c/xmlenc/xenc-schema.xsd");
+
+ if (saml1Assertion == null)
+ throw new RuntimeException("SAML11 Assertion Schema not found");
+
+ if (saml1Protocol == null)
+ throw new RuntimeException("SAML11 Protocol Schema not found");
+
+ if (dsig == null)
+ throw new RuntimeException("XML DSIG Schema not found");
+
+ if (xmlenc == null)
+ throw new RuntimeException("XML Enc Schema not found");
+
+ Source[] sources = new Source[]
+ {new StreamSource(dsig.openStream()), new StreamSource(xmlenc.openStream()),
+ new StreamSource(saml1Assertion.openStream()), new StreamSource(saml1Protocol.openStream())};
+
+ /* URL schemaURL = tcl.getResource(schemaFile);
+ if (schemaURL == null)
+ throw new RuntimeException("Cannot find schema :" + schemaFile);*/
+ SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
+ Schema schemaGrammar = schemaFactory.newSchema(sources);
+
+ validator = schemaGrammar.newValidator();
+ validator.setErrorHandler(new ErrorHandler()
+ {
+
+ public void error(SAXParseException ex) throws SAXException
+ {
+ logException(ex);
+ throw ex;
+ }
+
+ public void fatalError(SAXParseException ex) throws SAXException
+ {
+ logException(ex);
+ throw ex;
+ }
+
+ public void warning(SAXParseException ex) throws SAXException
+ {
+ logException(ex);
+ }
+
+ private void logException(SAXParseException sax)
+ {
+ StringBuilder builder = new StringBuilder();
+
+ if (trace)
+ {
+ builder.append("[").append(sax.getLineNumber()).append(",").append(sax.getColumnNumber())
+ .append("]");
+ builder.append(":").append(sax.getLocalizedMessage());
+ log.trace(builder.toString());
+ }
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ return validator;
+ }
}
\ No newline at end of file
13 years, 5 months
Picketlink SVN: r1042 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v1/writers and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-29 14:59:42 -0400 (Wed, 29 Jun 2011)
New Revision: 1042
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.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/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.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-29 18:36:59 UTC (rev 1041)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/SAML11Constants.java 2011-06-29 18:59:42 UTC (rev 1042)
@@ -78,6 +78,8 @@
String FORMAT_EMAIL_ADDRESS = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress";
+ String IN_RESPONSE_TO = "InResponseTo";
+
String IP_ADDRESS = "IPAddress";
String ISSUER = "Issuer";
@@ -96,9 +98,25 @@
String PROTOCOL_11_NSURI = "urn:oasis:names:tc:SAML:1.0:protocol";
+ String RECIPIENT = "Recipient";
+
String REQUEST = "Request";
String REQUEST_ID = "RequestID";
String RESOURCE = "Resource";
+
+ String RESPONSE = "Response";
+
+ String RESPONSE_ID = "ResponseID";
+
+ String STATUS = "Status";
+
+ String STATUS_CODE = "StatusCode";
+
+ String STATUS_DETAIL = "StatusDetail";
+
+ String STATUS_MSG = "StatusMessage";
+
+ String VALUE = "Value";
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11ResponseWriter.java 2011-06-29 18:59:42 UTC (rev 1042)
@@ -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.v1.writers;
+
+import java.net.URI;
+import java.util.List;
+
+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.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.core.util.StringUtil;
+import org.picketlink.identity.federation.saml.common.CommonStatusDetailType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11AssertionType;
+import org.picketlink.identity.federation.saml.v1.protocol.SAML11ResponseType;
+import org.picketlink.identity.federation.saml.v1.protocol.SAML11StatusCodeType;
+import org.picketlink.identity.federation.saml.v1.protocol.SAML11StatusType;
+import org.w3c.dom.Element;
+
+/**
+ * Write the {@link SAML11ResponseType} to stream
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jun 29, 2011
+ */
+public class SAML11ResponseWriter extends BaseSAML11Writer
+{
+ protected String namespace = SAML11Constants.PROTOCOL_11_NSURI;
+
+ protected SAML11AssertionWriter assertionWriter;
+
+ public SAML11ResponseWriter(XMLStreamWriter writer)
+ {
+ super(writer);
+ assertionWriter = new SAML11AssertionWriter(writer);
+ }
+
+ public void write(SAML11ResponseType response) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.RESPONSE, namespace);
+ StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, namespace);
+
+ // Attributes
+ StaxUtil.writeAttribute(writer, SAML11Constants.RESPONSE_ID, response.getID());
+ StaxUtil.writeAttribute(writer, SAML11Constants.MAJOR_VERSION, response.getMajorVersion() + "");
+ StaxUtil.writeAttribute(writer, SAML11Constants.MINOR_VERSION, response.getMinorVersion() + "");
+ StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), response.getIssueInstant().toString());
+ String inResp = response.getInResponseTo();
+ if (StringUtil.isNotNull(inResp))
+ {
+ StaxUtil.writeAttribute(writer, SAML11Constants.IN_RESPONSE_TO, inResp);
+ }
+
+ URI recipient = response.getRecipient();
+ if (recipient != null)
+ {
+ StaxUtil.writeAttribute(writer, SAML11Constants.RECIPIENT, recipient.toString());
+ }
+
+ Element sig = response.getSignature();
+ if (sig != null)
+ {
+ StaxUtil.writeDOMElement(writer, sig);
+ }
+
+ SAML11StatusType status = response.getStatus();
+ if (status != null)
+ {
+ write(status);
+ }
+
+ List<SAML11AssertionType> assertions = response.get();
+ for (SAML11AssertionType assertion : assertions)
+ {
+ assertionWriter.write(assertion);
+ }
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
+ }
+
+ public void write(SAML11StatusType status) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.STATUS, namespace);
+
+ SAML11StatusCodeType statusCode = status.getStatusCode();
+ if (statusCode != null)
+ {
+ write(statusCode);
+ }
+
+ String statusMsg = status.getStatusMessage();
+ if (StringUtil.isNotNull(statusMsg))
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.STATUS_MSG, namespace);
+ StaxUtil.writeCharacters(writer, statusMsg);
+ StaxUtil.writeEndElement(writer);
+ }
+
+ CommonStatusDetailType details = status.getStatusDetail();
+ if (details != null)
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.STATUS_DETAIL, namespace);
+ List<Object> objs = details.getAny();
+ for (Object theObj : objs)
+ {
+ StaxUtil.writeCharacters(writer, theObj.toString());
+ }
+ StaxUtil.writeEndElement(writer);
+ }
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
+ }
+
+ public void write(SAML11StatusCodeType statusCode) throws ProcessingException
+ {
+ StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, SAML11Constants.STATUS_CODE, namespace);
+
+ QName value = statusCode.getValue();
+ if (value == null)
+ throw new ProcessingException("Attribute Value is required");
+ StaxUtil.writeAttribute(writer, SAML11Constants.VALUE, value);
+
+ SAML11StatusCodeType secondCode = statusCode.getStatusCode();
+ if (secondCode != null)
+ {
+ write(secondCode);
+ }
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
+ }
+}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java 2011-06-29 18:36:59 UTC (rev 1041)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAML11ResponseParserTestCase.java 2011-06-29 18:59:42 UTC (rev 1042)
@@ -24,13 +24,16 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAML11ResponseParser;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v1.writers.SAML11ResponseWriter;
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.protocol.SAML11ResponseType;
import org.picketlink.identity.federation.saml.v1.protocol.SAML11StatusCodeType;
@@ -68,5 +71,11 @@
assertEquals(1, assertions.size());
SAML11AssertionType assertion = assertions.get(0);
assertEquals("buGxcG4gILg5NlocyLccDz6iXrUa", assertion.getID());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //Lets do the writing
+ SAML11ResponseWriter writer = new SAML11ResponseWriter(StaxUtil.getXMLStreamWriter(baos));
+ writer.write(response);
+ System.out.println(new String(baos.toByteArray()));
}
}
\ No newline at end of file
13 years, 5 months
Picketlink SVN: r1041 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v1/writers and 2 other directories.
by picketlink-commits@lists.jboss.org
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
13 years, 5 months
Picketlink SVN: r1040 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-28 11:59:54 -0400 (Tue, 28 Jun 2011)
New Revision: 1040
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java
Log:
avoid NPE
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java 2011-06-27 17:31:32 UTC (rev 1039)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java 2011-06-28 15:59:54 UTC (rev 1040)
@@ -181,14 +181,17 @@
private Node getBinaryToken(SOAPHeader soapHeader)
{
- NodeList children = soapHeader.getChildNodes();
- int length = children != null ? children.getLength() : 0;
- for (int i = 0; i < length; i++)
+ if (soapHeader != null)
{
- Node child = children.item(i);
- if (child.getNodeName().contains(WSSE.BINARY_SECURITY_TOKEN))
+ NodeList children = soapHeader.getChildNodes();
+ int length = children != null ? children.getLength() : 0;
+ for (int i = 0; i < length; i++)
{
- return child;
+ Node child = children.item(i);
+ if (child.getNodeName().contains(WSSE.BINARY_SECURITY_TOKEN))
+ {
+ return child;
+ }
}
}
return null;
13 years, 6 months
Picketlink SVN: r1039 - in federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core: util and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-27 13:31:32 -0400 (Mon, 27 Jun 2011)
New Revision: 1039
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/util/StaxUtil.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java
Log:
PLFED-192: saml writing
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-27 17:30:40 UTC (rev 1038)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2011-06-27 17:31:32 UTC (rev 1039)
@@ -39,12 +39,14 @@
import org.picketlink.identity.federation.saml.v2.assertion.AdviceType;
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.AttributeStatementType.ASTChoiceType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
import org.picketlink.identity.federation.saml.v2.assertion.AudienceRestrictionType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextClassRefType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextDeclRefType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextDeclType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType;
+import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType.AuthnContextTypeSequence;
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.ConditionAbstractType;
@@ -56,10 +58,8 @@
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;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType.STSubType;
import org.picketlink.identity.federation.saml.v2.assertion.URIType;
-import org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType.ASTChoiceType;
-import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType.AuthnContextTypeSequence;
-import org.picketlink.identity.federation.saml.v2.assertion.SubjectType.STSubType;
import org.picketlink.identity.federation.saml.v2.profiles.xacml.assertion.XACMLAuthzDecisionStatementType;
import org.picketlink.identity.xmlsec.w3.xmldsig.KeyInfoType;
import org.picketlink.identity.xmlsec.w3.xmldsig.X509CertificateType;
@@ -111,8 +111,8 @@
ConditionsType conditions = assertion.getConditions();
if (conditions != null)
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.CONDITIONS.get(), ASSERTION_NSURI
- .get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.CONDITIONS.get(),
+ ASSERTION_NSURI.get());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_BEFORE.get(), conditions.getNotBefore().toString());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_ON_OR_AFTER.get(), conditions.getNotOnOrAfter()
@@ -165,15 +165,19 @@
{
write((AttributeStatementType) statement);
}
- else if (statement instanceof XACMLAuthzDecisionStatementType )
+ else if (statement instanceof XACMLAuthzDecisionStatementType)
{
write((XACMLAuthzDecisionStatementType) statement);
}
- else
+ else
throw new RuntimeException("unknown statement type=" + statement.getClass().getName());
}
}
+ Element sig = assertion.getSignature();
+ if (sig != null)
+ StaxUtil.writeDOMElement(writer, sig);
+
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
@@ -225,7 +229,8 @@
*/
public void write(AuthnStatementType authnStatement) throws ProcessingException
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_STATEMENT.get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_STATEMENT.get(),
+ ASSERTION_NSURI.get());
XMLGregorianCalendar authnInstant = authnStatement.getAuthnInstant();
if (authnInstant != null)
@@ -240,28 +245,26 @@
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
-
- public void write( XACMLAuthzDecisionStatementType xacmlStat ) throws ProcessingException
- {
+
+ public void write(XACMLAuthzDecisionStatementType xacmlStat) throws ProcessingException
+ {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.STATEMENT.get(), ASSERTION_NSURI.get());
-
+
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeNameSpace(writer, XACML_SAML_PREFIX, JBossSAMLURIConstants.XACML_SAML_NSURI.get());
StaxUtil.writeNameSpace(writer, XACML_SAML_PROTO_PREFIX, JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get());
StaxUtil.writeNameSpace(writer, XSI_PREFIX, JBossSAMLURIConstants.XSI_NSURI.get());
-
- StaxUtil.writeAttribute( writer,
- new QName( JBossSAMLURIConstants.XSI_NSURI.get(),JBossSAMLConstants.TYPE.get(), XSI_PREFIX),
- XACMLAuthzDecisionStatementType.XSI_TYPE );
-
+ StaxUtil.writeAttribute(writer, new QName(JBossSAMLURIConstants.XSI_NSURI.get(), JBossSAMLConstants.TYPE.get(),
+ XSI_PREFIX), XACMLAuthzDecisionStatementType.XSI_TYPE);
+
ResponseType responseType = xacmlStat.getResponse();
- if( responseType == null )
- throw new RuntimeException( " XACML response is null" );
-
+ if (responseType == null)
+ throw new RuntimeException(" XACML response is null");
+
Document doc = SAMLXACMLUtil.getXACMLResponse(responseType);
- StaxUtil.writeDOMElement(writer, doc.getDocumentElement() );
-
+ StaxUtil.writeDOMElement(writer, doc.getDocumentElement());
+
/*try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -279,12 +282,12 @@
{
throw new ProcessingException( e );
}*/
-
+
RequestType requestType = xacmlStat.getRequest();
- if( requestType != null )
- {
- StaxUtil.writeDOMNode(writer, SAMLXACMLUtil.getXACMLRequest(requestType).getDocumentElement() );
-
+ if (requestType != null)
+ {
+ StaxUtil.writeDOMNode(writer, SAMLXACMLUtil.getXACMLRequest(requestType).getDocumentElement());
+
/*try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -304,7 +307,7 @@
}*/
}
StaxUtil.writeEndElement(writer);
- StaxUtil.flush(writer);
+ StaxUtil.flush(writer);
}
/**
@@ -316,7 +319,8 @@
*/
public void write(AuthnContextType authContext) throws ProcessingException
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT.get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT.get(),
+ ASSERTION_NSURI.get());
AuthnContextTypeSequence sequence = authContext.getSequence();
if (sequence != null)
@@ -337,15 +341,15 @@
{
if (uriType instanceof AuthnContextDeclType)
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION
- .get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
+ JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
StaxUtil.writeEndElement(writer);
}
if (uriType instanceof AuthnContextDeclRefType)
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF
- .get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
+ JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get(), ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
StaxUtil.writeEndElement(writer);
}
@@ -369,8 +373,6 @@
StaxUtil.flush(writer);
}
-
-
/**
* write an {@code SubjectType} to stream
*
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 2011-06-27 17:30:40 UTC (rev 1038)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2011-06-27 17:31:32 UTC (rev 1039)
@@ -102,7 +102,7 @@
throw new ProcessingException(e);
}
}
-
+
/**
* Get an {@code XMLStreamWriter}
*
@@ -110,12 +110,12 @@
* @return
* @throws ProcessingException
*/
- public static XMLStreamWriter getXMLStreamWriter(final Writer writer ) throws ProcessingException
+ public static XMLStreamWriter getXMLStreamWriter(final Writer writer) throws ProcessingException
{
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
try
{
- return xmlOutputFactory.createXMLStreamWriter( writer );
+ return xmlOutputFactory.createXMLStreamWriter(writer);
}
catch (XMLStreamException e)
{
@@ -165,6 +165,21 @@
* @param attributeValue
* @throws ProcessingException
*/
+ public static void writeAttribute(XMLStreamWriter writer, String attributeName, QName attributeValue)
+ throws ProcessingException
+ {
+ writeAttribute(writer, attributeName, attributeValue.toString());
+ }
+
+ /**
+ * Write an attribute
+ *
+ * @param writer
+ * @param attributeName
+ * QName of the attribute
+ * @param attributeValue
+ * @throws ProcessingException
+ */
public static void writeAttribute(XMLStreamWriter writer, QName attributeName, String attributeValue)
throws ProcessingException
{
@@ -244,7 +259,7 @@
throw new ProcessingException(e);
}
}
-
+
/**
* Write a string as text node
*
@@ -256,7 +271,7 @@
{
try
{
- writer.writeCData( value );
+ writer.writeCData(value);
}
catch (XMLStreamException e)
{
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java 2011-06-27 17:30:40 UTC (rev 1038)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java 2011-06-27 17:31:32 UTC (rev 1039)
@@ -29,8 +29,8 @@
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.exceptions.ProcessingException;
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.DocumentUtil;
-import org.picketlink.identity.federation.core.saml.v2.writers.SAML11AssertionWriter;
import org.picketlink.identity.federation.core.saml.v2.writers.SAMLAssertionWriter;
import org.picketlink.identity.federation.core.util.StaxUtil;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AssertionType;
13 years, 6 months
Picketlink SVN: r1038 - in federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers: util and 1 other directory.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2011-06-27 13:30:40 -0400 (Mon, 27 Jun 2011)
New Revision: 1038
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAML11AssertionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAML11ParserUtil.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java
Log:
PLFED-191: saml11 parsing
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAML11AssertionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAML11AssertionParser.java 2011-06-27 17:29:49 UTC (rev 1037)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAML11AssertionParser.java 2011-06-27 17:30:40 UTC (rev 1038)
@@ -34,7 +34,6 @@
import org.picketlink.identity.federation.core.exceptions.ProcessingException;
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import org.picketlink.identity.federation.core.parsers.util.SAML11ParserUtil;
-import org.picketlink.identity.federation.core.parsers.util.SAMLParserUtil;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.saml.v1.SAML11Constants;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
@@ -145,7 +144,7 @@
else if (SAML11Constants.AUTHENTICATION_STATEMENT.equals(tag))
{
startElement = (StartElement) xmlEvent;
- SAML11AuthenticationStatementType authStat = SAMLParserUtil.parseAuthenticationStatement(xmlEventReader);
+ SAML11AuthenticationStatementType authStat = SAML11ParserUtil.parseAuthenticationStatement(xmlEventReader);
assertion.add(authStat);
}
else if (SAML11Constants.ATTRIBUTE_STATEMENT.equalsIgnoreCase(tag))
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAML11ParserUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAML11ParserUtil.java 2011-06-27 17:29:49 UTC (rev 1037)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAML11ParserUtil.java 2011-06-27 17:30:40 UTC (rev 1038)
@@ -41,10 +41,14 @@
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AttributeStatementType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AttributeType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AudienceRestrictionCondition;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11AuthenticationStatementType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11AuthorityBindingType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AuthorizationDecisionStatementType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11ConditionsType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11DecisionType;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectConfirmationType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectLocalityType;
+import org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectStatementType;
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;
@@ -64,7 +68,120 @@
*/
public class SAML11ParserUtil
{
+
/**
+ * Parse the AuthnStatement inside the assertion
+ * @param xmlEventReader
+ * @return
+ * @throws ParsingException
+ */
+ public static SAML11AuthenticationStatementType parseAuthenticationStatement(XMLEventReader xmlEventReader)
+ throws ParsingException
+ {
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+
+ StaxParserUtil.validate(startElement, SAML11Constants.AUTHENTICATION_STATEMENT);
+
+ Attribute authMethod = startElement.getAttributeByName(new QName(SAML11Constants.AUTHENTICATION_METHOD));
+ if (authMethod == null)
+ throw new ParsingException(SAML11Constants.AUTHENTICATION_METHOD + " attribute needed");
+
+ Attribute authInstant = startElement.getAttributeByName(new QName(SAML11Constants.AUTHENTICATION_INSTANT));
+ if (authInstant == null)
+ throw new ParsingException(SAML11Constants.AUTHENTICATION_INSTANT + " attribute needed");
+
+ SAML11AuthenticationStatementType authStat = new SAML11AuthenticationStatementType(URI.create(StaxParserUtil
+ .getAttributeValue(authMethod)), XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(authInstant)));
+
+ while (xmlEventReader.hasNext())
+ {
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if (xmlEvent == null)
+ break;
+
+ if (xmlEvent instanceof EndElement)
+ {
+ xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
+ EndElement endElement = (EndElement) xmlEvent;
+ String endElementTag = StaxParserUtil.getEndElementName(endElement);
+ if (endElementTag.equals(SAML11Constants.AUTHENTICATION_STATEMENT))
+ break;
+ else
+ throw new RuntimeException("Unknown End Element:" + endElementTag);
+ }
+ startElement = null;
+
+ if (xmlEvent instanceof StartElement)
+ {
+ startElement = (StartElement) xmlEvent;
+ }
+ else
+ {
+ startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+ }
+ if (startElement == null)
+ break;
+
+ String tag = StaxParserUtil.getStartElementName(startElement);
+
+ if (JBossSAMLConstants.SUBJECT.get().equalsIgnoreCase(tag))
+ {
+ SAML11SubjectParser subjectParser = new SAML11SubjectParser();
+ SAML11SubjectType subject = (SAML11SubjectType) subjectParser.parse(xmlEventReader);
+ SAML11SubjectStatementType subStat = new SAML11SubjectStatementType();
+ subStat.setSubject(subject);
+
+ authStat.setSubject(subject);
+ }
+ else if (JBossSAMLConstants.SUBJECT_LOCALITY.get().equals(tag))
+ {
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ SAML11SubjectLocalityType subjectLocalityType = new SAML11SubjectLocalityType();
+ Attribute address = startElement.getAttributeByName(new QName(SAML11Constants.IP_ADDRESS));
+ if (address != null)
+ {
+ subjectLocalityType.setIpAddress(StaxParserUtil.getAttributeValue(address));
+ }
+ Attribute dns = startElement.getAttributeByName(new QName(SAML11Constants.DNS_ADDRESS));
+ if (dns != null)
+ {
+ subjectLocalityType.setDnsAddress(StaxParserUtil.getAttributeValue(dns));
+ }
+ authStat.setSubjectLocality(subjectLocalityType);
+ StaxParserUtil.validate(StaxParserUtil.getNextEndElement(xmlEventReader),
+ JBossSAMLConstants.SUBJECT_LOCALITY.get());
+ }
+ else if (SAML11Constants.AUTHORITY_BINDING.equals(tag))
+ {
+ Attribute authorityKindAttr = startElement.getAttributeByName(new QName(SAML11Constants.AUTHORITY_KIND));
+ if (authorityKindAttr == null)
+ throw new ParsingException("Required attribute AuthorityKind");
+
+ Attribute locationAttr = startElement.getAttributeByName(new QName(SAML11Constants.LOCATION));
+ if (locationAttr == null)
+ throw new ParsingException("Required attribute Location");
+ URI location = URI.create(StaxParserUtil.getAttributeValue(locationAttr));
+
+ Attribute bindingAttr = startElement.getAttributeByName(new QName(SAML11Constants.BINDING));
+ if (bindingAttr == null)
+ throw new ParsingException("Required attribute Binding");
+ URI binding = URI.create(StaxParserUtil.getAttributeValue(bindingAttr));
+
+ QName authorityKind = QName.valueOf(StaxParserUtil.getAttributeValue(authorityKindAttr));
+
+ SAML11AuthorityBindingType authorityBinding = new SAML11AuthorityBindingType(authorityKind, location,
+ binding);
+ authStat.add(authorityBinding);
+ }
+ else
+ throw new RuntimeException("Unknown tag:" + tag + "::Location=" + startElement.getLocation());
+
+ }
+
+ return authStat;
+ }
+
+ /**
* Parse the {@link SAML11SubjectConfirmationType}
* @param xmlEventReader
* @return
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java 2011-06-27 17:29:49 UTC (rev 1037)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java 2011-06-27 17:30:40 UTC (rev 1038)
@@ -35,15 +35,10 @@
import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
-import org.picketlink.identity.federation.core.parsers.saml.SAML11SubjectParser;
-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.saml.v2.constants.JBossSAMLURIConstants;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
import org.picketlink.identity.federation.core.util.StringUtil;
-import org.picketlink.identity.federation.saml.v1.assertion.SAML11AuthenticationStatementType;
-import org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectStatementType;
-import org.picketlink.identity.federation.saml.v1.assertion.SAML11SubjectType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType.ASTChoiceType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
@@ -326,101 +321,6 @@
}
/**
- * Parse the AuthnStatement inside the assertion
- * @param xmlEventReader
- * @return
- * @throws ParsingException
- */
- public static SAML11AuthenticationStatementType parseAuthenticationStatement(XMLEventReader xmlEventReader)
- throws ParsingException
- {
- StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
-
- StaxParserUtil.validate(startElement, SAML11Constants.AUTHENTICATION_STATEMENT);
-
- Attribute authMethod = startElement.getAttributeByName(new QName(SAML11Constants.AUTHENTICATION_METHOD));
- if (authMethod == null)
- throw new ParsingException(SAML11Constants.AUTHENTICATION_METHOD + " attribute needed");
-
- Attribute authInstant = startElement.getAttributeByName(new QName(SAML11Constants.AUTHENTICATION_INSTANT));
- if (authInstant == null)
- throw new ParsingException(SAML11Constants.AUTHENTICATION_INSTANT + " attribute needed");
-
- SAML11AuthenticationStatementType authStat = new SAML11AuthenticationStatementType(URI.create(StaxParserUtil
- .getAttributeValue(authMethod)), XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(authInstant)));
-
- while (xmlEventReader.hasNext())
- {
- XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
- if (xmlEvent == null)
- break;
-
- if (xmlEvent instanceof EndElement)
- {
- xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
- EndElement endElement = (EndElement) xmlEvent;
- String endElementTag = StaxParserUtil.getEndElementName(endElement);
- if (endElementTag.equals(SAML11Constants.AUTHENTICATION_STATEMENT))
- break;
- else
- throw new RuntimeException("Unknown End Element:" + endElementTag);
- }
- startElement = null;
-
- if (xmlEvent instanceof StartElement)
- {
- startElement = (StartElement) xmlEvent;
- }
- else
- {
- startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
- }
- if (startElement == null)
- break;
-
- String tag = StaxParserUtil.getStartElementName(startElement);
-
- if (JBossSAMLConstants.SUBJECT.get().equalsIgnoreCase(tag))
- {
- SAML11SubjectParser subjectParser = new SAML11SubjectParser();
- SAML11SubjectType subject = (SAML11SubjectType) subjectParser.parse(xmlEventReader);
- SAML11SubjectStatementType subStat = new SAML11SubjectStatementType();
- subStat.setSubject(subject);
-
- authStat.setSubject(subject);
- }
-
- /*if (JBossSAMLConstants.SUBJECT_LOCALITY.get().equals(tag))
- {
- startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- SubjectLocalityType subjectLocalityType = new SubjectLocalityType();
- Attribute address = startElement.getAttributeByName(new QName(JBossSAMLConstants.ADDRESS.get()));
- if (address != null)
- {
- subjectLocalityType.setAddress(StaxParserUtil.getAttributeValue(address));
- }
- Attribute dns = startElement.getAttributeByName(new QName(JBossSAMLConstants.DNS_NAME.get()));
- if (dns != null)
- {
- subjectLocalityType.setDNSName(StaxParserUtil.getAttributeValue(dns));
- }
- authnStatementType.setSubjectLocality(subjectLocalityType);
- StaxParserUtil.validate(StaxParserUtil.getNextEndElement(xmlEventReader),
- JBossSAMLConstants.SUBJECT_LOCALITY.get());
- }
- else if (JBossSAMLConstants.AUTHN_CONTEXT.get().equals(tag))
- {
- authnStatementType.setAuthnContext(parseAuthnContextType(xmlEventReader));
- }*/
- else
- throw new RuntimeException("Unknown tag:" + tag + "::Location=" + startElement.getLocation());
-
- }
-
- return authStat;
- }
-
- /**
* Parse a {@code NameIDType}
* @param xmlEventReader
* @return
13 years, 6 months