Picketlink SVN: r469 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-14 12:07:45 -0400 (Thu, 14 Oct 2010)
New Revision: 469
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java
Log:
PLFED-110: saml parsing
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-10-14 15:10:28 UTC (rev 468)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-10-14 16:07:45 UTC (rev 469)
@@ -35,6 +35,7 @@
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
@@ -70,6 +71,7 @@
XMLEvent xmlEvent = StaxParserUtil.peek( xmlEventReader );
if( xmlEvent == null )
break;
+
if( xmlEvent instanceof EndElement )
{
xmlEvent = StaxParserUtil.getNextEvent( xmlEventReader );
@@ -78,6 +80,7 @@
if( endElementTag.equals( JBossSAMLConstants.ASSERTION.get() ) )
break;
}
+
StartElement peekedElement = null;
if( xmlEvent instanceof StartElement )
@@ -154,9 +157,18 @@
*/
public boolean supports(QName qname)
{
- return false;
+ String nsURI = qname.getNamespaceURI();
+ String localPart = qname.getLocalPart();
+
+ return nsURI.equals( JBossSAMLURIConstants.ASSERTION_NSURI.get() )
+ && localPart.equals( JBossSAMLConstants.ASSERTION.get() );
}
+ /**
+ * We really don't care about the ds:signature stuff for building the object model
+ * @param xmlEventReader
+ * @throws ParsingException
+ */
private void bypassXMLSignatureBlock( XMLEventReader xmlEventReader ) throws ParsingException
{
while ( xmlEventReader.hasNext() )
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java 2010-10-14 15:10:28 UTC (rev 468)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java 2010-10-14 16:07:45 UTC (rev 469)
@@ -55,27 +55,26 @@
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
{
StaxParserUtil.getNextEvent(xmlEventReader);
-
+
SubjectType subject = new SubjectType();
-
+
//Peek at the next event
while( xmlEventReader.hasNext() )
{
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
if( xmlEvent instanceof EndElement )
{
- EndElement endElement = (EndElement) xmlEvent;
- String endElementValue = StaxParserUtil.getEndElementName(endElement);
- if( endElementValue.equalsIgnoreCase( JBossSAMLConstants.SUBJECT.get() ))
+ EndElement endElement = (EndElement) xmlEvent;
+ if( StaxParserUtil.matches(endElement , JBossSAMLConstants.SUBJECT.get() ))
break;
}
-
+
StartElement peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
if( peekedElement == null )
break;
String tag = StaxParserUtil.getStartElementName( peekedElement );
-
+
if( JBossSAMLConstants.NAMEID.get().equalsIgnoreCase( tag ) )
{
try
@@ -85,50 +84,51 @@
if( nameQualifier == null )
nameQualifier = nameIDElement.getAttributeByName( new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(),
JBossSAMLConstants.NAME_QUALIFIER.get() ));
-
+
String nameIDValue = xmlEventReader.getElementText();
-
+
NameIDType nameID = new NameIDType();
nameID.setValue( nameIDValue );
if( nameQualifier != null )
{
nameID.setNameQualifier( StaxParserUtil.getAttributeValue(nameQualifier) );
}
-
+
JAXBElement<NameIDType> jaxbNameID = objectFactory.createNameID( nameID );
subject.getContent().add( jaxbNameID );
-
+
//There is no need to get the end tag as the "getElementText" call above puts us past that
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException( e );
}
}
else if( JBossSAMLConstants.SUBJECT_CONFIRMATION.get().equalsIgnoreCase( tag ) )
{
- StartElement subjectConfirmationElement = StaxParserUtil.getNextStartElement( xmlEventReader );
- Attribute method = subjectConfirmationElement.getAttributeByName( new QName( "", JBossSAMLConstants.METHOD.get() ));
- if( method == null )
- method = subjectConfirmationElement.getAttributeByName( new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(),
- JBossSAMLConstants.METHOD.get() ));
-
- SubjectConfirmationType subjectConfirmationType = new SubjectConfirmationType();
-
- if( method != null )
- {
- subjectConfirmationType.setMethod( StaxParserUtil.getAttributeValue( method ) );
- }
-
- JAXBElement<SubjectConfirmationType> jaxbSubjectConf = objectFactory.createSubjectConfirmation( subjectConfirmationType );
- subject.getContent().add(jaxbSubjectConf);
-
- //Get the end tag
- StaxParserUtil.getNextEvent(xmlEventReader);
+ StartElement subjectConfirmationElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ Attribute method = subjectConfirmationElement.getAttributeByName( new QName( "", JBossSAMLConstants.METHOD.get() ));
+ if( method == null )
+ method = subjectConfirmationElement.getAttributeByName( new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(),
+ JBossSAMLConstants.METHOD.get() ));
+
+ SubjectConfirmationType subjectConfirmationType = new SubjectConfirmationType();
+
+ if( method != null )
+ {
+ subjectConfirmationType.setMethod( StaxParserUtil.getAttributeValue( method ) );
+ }
+
+ JAXBElement<SubjectConfirmationType> jaxbSubjectConf = objectFactory.createSubjectConfirmation( subjectConfirmationType );
+ subject.getContent().add(jaxbSubjectConf);
+
+ //Get the end tag
+ EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
+ StaxParserUtil.matches(endElement, JBossSAMLConstants.SUBJECT_CONFIRMATION.get() );
}
else throw new RuntimeException( "Unknown tag:" + tag );
}
-
+
return subject;
}
14 years, 2 months
Picketlink SVN: r468 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-14 11:10:28 -0400 (Thu, 14 Oct 2010)
New Revision: 468
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTValidateTargetParser.java
Log:
PLFED-109: wst stax parsing
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTValidateTargetParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTValidateTargetParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTValidateTargetParser.java 2010-10-14 15:10:28 UTC (rev 468)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.parsers.wst;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.ws.trust.ValidateTargetType;
+
+/**
+ * Stax parser for the wst:ValidateTarget element
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 13, 2010
+ */
+public class WSTValidateTargetParser implements ParserNamespaceSupport
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ ValidateTargetType validateTargetType = new ValidateTargetType();
+
+ StartElement startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ String tag = StaxParserUtil.getStartElementName( startElement );
+
+ if( tag.equals( JBossSAMLConstants.ASSERTION.get() ) )
+ {
+ SAMLParser assertionParser = new SAMLParser();
+ AssertionType assertion = (AssertionType) assertionParser.parse( xmlEventReader );
+ validateTargetType.setAny( assertion );
+ }
+
+ return validateTargetType;
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ return false;
+ }
+}
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r467 - in federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core: saml/v2/constants and 1 other directory.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-14 11:10:08 -0400 (Thu, 14 Oct 2010)
New Revision: 467
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
Log:
PLFED-110: saml parsing
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-10-14 15:05:47 UTC (rev 466)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-10-14 15:10:08 UTC (rev 467)
@@ -96,13 +96,13 @@
if( tag.equals( JBossSAMLConstants.ASSERTION.get() ))
{
StartElement nextElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- Attribute idAttribute = nextElement.getAttributeByName( new QName( "", "ID" ) );
+ Attribute idAttribute = nextElement.getAttributeByName( new QName( "", JBossSAMLConstants.ID.get() ) );
assertion.setID( StaxParserUtil.getAttributeValue( idAttribute ));
- Attribute versionAttribute = nextElement.getAttributeByName( new QName( "", "Version" ));
+ Attribute versionAttribute = nextElement.getAttributeByName( new QName( "", JBossSAMLConstants.VERSION.get() ));
assertion.setVersion( StaxParserUtil.getAttributeValue(versionAttribute) );
- Attribute issueInstantAttribute = nextElement.getAttributeByName( new QName( "", "IssueInstant" ));
+ Attribute issueInstantAttribute = nextElement.getAttributeByName( new QName( "", JBossSAMLConstants.ISSUE_INSTANT.get() ));
if( issueInstantAttribute != null )
{
assertion.setIssueInstant( dtf.newXMLGregorianCalendar( StaxParserUtil.getAttributeValue(issueInstantAttribute )));
@@ -143,8 +143,7 @@
SAMLConditionsParser conditionsParser = new SAMLConditionsParser();
ConditionsType conditions = (ConditionsType) conditionsParser.parse(xmlEventReader);
- assertion.setConditions( conditions );
-
+ assertion.setConditions( conditions );
}
}
return assertion;
@@ -166,7 +165,7 @@
if( endElement == null )
return;
- if( StaxParserUtil.getEndElementName(endElement).equals( "Signature" ) )
+ if( StaxParserUtil.matches( endElement , JBossSAMLConstants.SIGNATURE.get() ) )
return;
}
}
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-10-14 15:05:47 UTC (rev 466)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-10-14 15:10:08 UTC (rev 467)
@@ -32,6 +32,8 @@
AUDIENCE( "Audience" ),
AUDIENCE_RESTRICTION( "AudienceRestriction" ),
CONDITIONS( "Conditions" ),
+ ID( "ID" ),
+ ISSUE_INSTANT( "IssueInstant" ),
ISSUER( "Issuer" ),
LANG_EN("en"),
METADATA_MIME("application/samlmetadata+xml"),
@@ -45,6 +47,7 @@
SIGNATURE_SHA1_WITH_RSA("http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
SUBJECT( "Subject" ),
SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
+ VERSION( "Version" ),
VERSION_2_0("2.0"),
HTTP_POST_BINDING("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
14 years, 2 months
Picketlink SVN: r466 - in federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core: wstrust and 1 other directory.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-14 11:05:47 -0400 (Thu, 14 Oct 2010)
New Revision: 466
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
Log:
PLFED-109: wst stax parsing
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-14 15:02:51 UTC (rev 465)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-14 15:05:47 UTC (rev 466)
@@ -55,7 +55,7 @@
RequestSecurityToken requestToken = new RequestSecurityToken();
- QName contextQName = new QName( "", "Context" );
+ QName contextQName = new QName( "", WSTrustConstants.RST_CONTEXT );
Attribute contextAttribute = startElement.getAttributeByName( contextQName );
String contextValue = StaxParserUtil.getAttributeValue( contextAttribute );
requestToken.setContext( contextValue );
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-14 15:02:51 UTC (rev 465)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-14 15:05:47 UTC (rev 466)
@@ -85,4 +85,7 @@
public static final String REQUEST_TYPE = "RequestType";
public static final String TOKEN_TYPE = "TokenType";
public static final String VALIDATE_TARGET = "ValidateTarget";
+
+ //Attribute Names
+ public static final String RST_CONTEXT = "Context";
}
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r465 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/parsers/wst and 2 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-14 11:02:51 -0400 (Thu, 14 Oct 2010)
New Revision: 465
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/wst/WSTRequestSecurityTokenCollectionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java
Log:
PLFED-109: wst stax parsing
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 2010-10-14 15:02:21 UTC (rev 464)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2010-10-14 15:02:51 UTC (rev 465)
@@ -53,6 +53,24 @@
}
/**
+ * Get the element text.
+ * @param xmlEventReader
+ * @return A <b>trimmed</b> string value
+ * @throws ParsingException
+ */
+ public static String getElementText( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ try
+ {
+ return xmlEventReader.getElementText().trim();
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+
+ /**
* Get the XML event reader
* @param is
* @return
@@ -91,6 +109,12 @@
return builder.toString();
}
+ /**
+ * Get the next xml event
+ * @param xmlEventReader
+ * @return
+ * @throws ParsingException
+ */
public static XMLEvent getNextEvent( XMLEventReader xmlEventReader ) throws ParsingException
{
try
@@ -173,6 +197,37 @@
return trim( endElement.getName().getLocalPart() );
}
+
+ /**
+ * 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 )
+ {
+ 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 )
+ {
+ 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
{
try
@@ -249,4 +304,30 @@
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 )
+ {
+ 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 )
+ {
+ String elementTag = getEndElementName( endElement );
+ if( !tag.equals( elementTag ))
+ throw new RuntimeException( "Expecting <" + tag + ">. Found <" + elementTag + ">" );
+ }
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenCollectionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenCollectionParser.java 2010-10-14 15:02:21 UTC (rev 464)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenCollectionParser.java 2010-10-14 15:02:51 UTC (rev 465)
@@ -39,9 +39,10 @@
* @since Oct 11, 2010
*/
public class WSTRequestSecurityTokenCollectionParser implements ParserNamespaceSupport
-{
- public static final String LOCALPART = "RequestSecurityTokenCollection";
-
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
public Object parse( XMLEventReader xmlEventReader ) throws ParsingException
{
try
@@ -53,19 +54,18 @@
throw new ParsingException( e );
}
- RequestSecurityTokenCollection requestCollection = new RequestSecurityTokenCollection();
+ RequestSecurityTokenCollection requestCollection = new RequestSecurityTokenCollection();
-
//Peek at the next event
while( true )
{
StartElement peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
- if( peekedElement == null )
- break;
-
+ if( peekedElement == null )
+ break;
+
String tag = StaxParserUtil.getStartElementName( peekedElement );
- if( WSTRequestSecurityTokenParser.LOCALPART.equalsIgnoreCase( tag ) )
+ if( WSTrustConstants.RST.equalsIgnoreCase( tag ) )
{
WSTRequestSecurityTokenParser rstParser = new WSTRequestSecurityTokenParser();
RequestSecurityToken rst = ( RequestSecurityToken ) rstParser.parse( xmlEventReader );
@@ -75,9 +75,12 @@
return requestCollection;
}
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
public boolean supports( QName qname )
{
return ( qname.getNamespaceURI().equals( WSTrustConstants.BASE_NAMESPACE )
- && qname.getLocalPart().equals( WSTRequestSecurityTokenCollectionParser.LOCALPART ) );
+ && qname.getLocalPart().equals( WSTrustConstants.RST_COLLECTION ) );
}
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-14 15:02:21 UTC (rev 464)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-14 15:02:51 UTC (rev 465)
@@ -37,6 +37,7 @@
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken;
+import org.picketlink.identity.federation.ws.trust.ValidateTargetType;
/**
* Parse the WS-Trust RequestSecurityToken
@@ -44,9 +45,10 @@
* @since Oct 11, 2010
*/
public class WSTRequestSecurityTokenParser implements ParserNamespaceSupport
-{
- public static final String LOCALPART = "RequestSecurityToken";
-
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
{
StartElement startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
@@ -58,8 +60,20 @@
String contextValue = StaxParserUtil.getAttributeValue( contextAttribute );
requestToken.setContext( contextValue );
- while( true )
+ 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( WSTrustConstants.RST ) )
+ break;
+ }
+
try
{
StartElement subEvent = StaxParserUtil.getNextStartElement( xmlEventReader );
@@ -70,21 +84,22 @@
if( tag.equals( WSTrustConstants.REQUEST_TYPE ))
{
String value = xmlEventReader.getElementText();
- requestToken.setRequestType( new URI( value ));
+ requestToken.setRequestType( new URI( value ));
}
else if( tag.equals( WSTrustConstants.TOKEN_TYPE ))
{
String value = xmlEventReader.getElementText();
requestToken.setTokenType( new URI( value ));
}
-
- XMLEvent xmlEvent = xmlEventReader.peek();
- if( xmlEvent.isEndElement() )
+ else if( tag.equals( WSTrustConstants.VALIDATE_TARGET ))
{
- EndElement endElement = (EndElement) xmlEvent;
- if( StaxParserUtil.getEndElementName( endElement ).equalsIgnoreCase( WSTrustConstants.RST ) )
- break;
- }
+ WSTValidateTargetParser wstValidateTargetParser = new WSTValidateTargetParser();
+ ValidateTargetType validateTarget = (ValidateTargetType) wstValidateTargetParser.parse( xmlEventReader );
+ requestToken.setValidateTarget( validateTarget );
+ EndElement validateTargetEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
+ if( !StaxParserUtil.getEndElementName( validateTargetEndElement ).equals( WSTrustConstants.VALIDATE_TARGET ) )
+ throw new RuntimeException( "</" + WSTrustConstants.VALIDATE_TARGET + "> expected" );
+ }
}
catch( XMLStreamException e )
{
@@ -99,6 +114,9 @@
return requestToken;
}
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
public boolean supports(QName qname)
{
return false;
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java 2010-10-14 15:02:21 UTC (rev 464)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java 2010-10-14 15:02:51 UTC (rev 465)
@@ -63,11 +63,16 @@
StartElement startElement = (StartElement) xmlEvent;
String elementName = StaxParserUtil.getStartElementName( startElement );
- if( elementName.equalsIgnoreCase( WSTRequestSecurityTokenCollectionParser.LOCALPART ))
+ if( elementName.equalsIgnoreCase( WSTrustConstants.RST_COLLECTION ))
{
WSTRequestSecurityTokenCollectionParser wstrcoll = new WSTRequestSecurityTokenCollectionParser();
return wstrcoll.parse(xmlEventReader);
}
+ else if( elementName.equalsIgnoreCase( WSTrustConstants.RST ))
+ {
+ WSTRequestSecurityTokenParser wst = new WSTRequestSecurityTokenParser();
+ return wst.parse(xmlEventReader);
+ }
}
else
{
@@ -81,7 +86,7 @@
}
}
}
- return null;
+ throw new RuntimeException( "WSTrust Parsing has failed" );
}
/**
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-14 15:02:21 UTC (rev 464)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-14 15:02:51 UTC (rev 465)
@@ -40,6 +40,7 @@
public static final String RENEW_REQUEST = BASE_NAMESPACE + "/Renew";
public static final String CANCEL_REQUEST = BASE_NAMESPACE + "/Cancel";
public static final String VALIDATE_REQUEST = BASE_NAMESPACE + "/Validate";
+ public static final String BATCH_VALIDATE_REQUEST = BASE_NAMESPACE + "/BatchValidate";
// WS-Trust validation constants.
public static final String STATUS_TYPE = BASE_NAMESPACE + "/RSTR/Status";
@@ -76,9 +77,11 @@
//Token Types
public static final String SAML2_TOKEN_TYPE = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0";
+ public static final String RSTR_STATUS_TOKEN_TYPE = "http://docs.oasis-open.org/ws-sx/ws-trust/200512/RSTR/Status";
//Element Names
public static final String RST = "RequestSecurityToken";
+ public static final String RST_COLLECTION = "RequestSecurityTokenCollection";
public static final String REQUEST_TYPE = "RequestType";
public static final String TOKEN_TYPE = "TokenType";
public static final String VALIDATE_TARGET = "ValidateTarget";
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java 2010-10-14 15:02:21 UTC (rev 464)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java 2010-10-14 15:02:51 UTC (rev 465)
@@ -27,7 +27,6 @@
import java.io.InputStream;
import java.util.List;
-import org.junit.Ignore;
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.wst.WSTrustParser;
import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
@@ -35,13 +34,13 @@
import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityTokenCollection;
/**
+ * Validate the parsing of wst-batch-validate.xml
* @author Anil.Saldhana(a)redhat.com
* @since Oct 12, 2010
*/
public class WSTrustBatchValidateParsingTestCase
{
- @Test
- @Ignore
+ @Test
public void testWST_BatchValidate() throws Exception
{
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
@@ -54,15 +53,15 @@
List<RequestSecurityToken> tokens = requestCollection.getRequestSecurityTokens();
assertEquals( 2, tokens.size() );
- /*RequestSecurityToken rst1 = tokens.get( 0 );
- assertEquals( "context1", rst1.getContext() );
- assertEquals( WSTrustConstants.BATCH_ISSUE_REQUEST, rst1.getRequestType().toASCIIString() );
- assertEquals( WSTrustConstants.SAML2_TOKEN_TYPE, rst1.getTokenType().toASCIIString() );
+ RequestSecurityToken rst1 = tokens.get( 0 );
+ assertEquals( "validatecontext1", rst1.getContext() );
+ assertEquals( WSTrustConstants.BATCH_VALIDATE_REQUEST, rst1.getRequestType().toASCIIString() );
+ assertEquals( WSTrustConstants.RSTR_STATUS_TOKEN_TYPE, rst1.getTokenType().toASCIIString() );
RequestSecurityToken rst2 = tokens.get( 1 );
- assertEquals( "context2", rst2.getContext() );
- assertEquals( WSTrustConstants.BATCH_ISSUE_REQUEST , rst2.getRequestType().toASCIIString() );
- assertEquals( "http://www.tokens.org/SpecialToken" , rst2.getTokenType().toASCIIString() ); */
+ assertEquals( "validatecontext2", rst2.getContext() );
+ assertEquals( WSTrustConstants.BATCH_VALIDATE_REQUEST , rst2.getRequestType().toASCIIString() );
+ assertEquals( WSTrustConstants.RSTR_STATUS_TOKEN_TYPE , rst2.getTokenType().toASCIIString() );
}
}
14 years, 2 months
Picketlink SVN: r464 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v2/constants and 2 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-14 11:02:21 -0400 (Thu, 14 Oct 2010)
New Revision: 464
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion-audiencerestriction.xml
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java
Log:
PLFED-110: saml parsing
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-10-12 22:29:13 UTC (rev 463)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-10-14 15:02:21 UTC (rev 464)
@@ -23,18 +23,18 @@
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
-import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
-import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
@@ -46,118 +46,128 @@
* @since Oct 12, 2010
*/
public class SAMLAssertionParser implements ParserNamespaceSupport
-{
- public static final String LOCALPART = "Assertion";
-
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
{
+ DatatypeFactory dtf;
try
{
- xmlEventReader.nextEvent();
+ dtf = DatatypeFactory.newInstance();
}
- catch (XMLStreamException e)
+ catch (DatatypeConfigurationException e )
{
throw new ParsingException( e );
- }
-
+ }
+
AssertionType assertion = new AssertionType();
-
+
//Peek at the next event
while( xmlEventReader.hasNext() )
- {
- StartElement peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
- if( peekedElement == null )
- break;
-
+ {
+ 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( JBossSAMLConstants.ASSERTION.get() ) )
+ break;
+ }
+ StartElement peekedElement = null;
+
+ if( xmlEvent instanceof StartElement )
+ {
+ peekedElement = (StartElement) xmlEvent;
+ }
+ else
+ {
+ peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ }
+ if( peekedElement == null )
+ break;
+
String tag = StaxParserUtil.getStartElementName( peekedElement );
-
+
+ if( tag.equals( JBossSAMLConstants.ASSERTION.get() ))
+ {
+ StartElement nextElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ Attribute idAttribute = nextElement.getAttributeByName( new QName( "", "ID" ) );
+ assertion.setID( StaxParserUtil.getAttributeValue( idAttribute ));
+
+ Attribute versionAttribute = nextElement.getAttributeByName( new QName( "", "Version" ));
+ assertion.setVersion( StaxParserUtil.getAttributeValue(versionAttribute) );
+
+ Attribute issueInstantAttribute = nextElement.getAttributeByName( new QName( "", "IssueInstant" ));
+ if( issueInstantAttribute != null )
+ {
+ assertion.setIssueInstant( dtf.newXMLGregorianCalendar( StaxParserUtil.getAttributeValue(issueInstantAttribute )));
+ }
+ continue;
+ }
+
+ if( tag.equals( JBossSAMLConstants.SIGNATURE.get() ) )
+ {
+ bypassXMLSignatureBlock( xmlEventReader );
+ continue;
+ }
+
if( JBossSAMLConstants.ISSUER.get().equalsIgnoreCase( tag ) )
{
try
{
StaxParserUtil.getNextStartElement( xmlEventReader );
String issuerValue = xmlEventReader.getElementText();
-
+
NameIDType issuer = new NameIDType();
issuer.setValue( issuerValue );
-
+
assertion.setIssuer( issuer );
}
catch (XMLStreamException e)
{
- throw new ParsingException( e );
+ throw new ParsingException( e );
}
}
else if( JBossSAMLConstants.SUBJECT.get().equalsIgnoreCase( tag ) )
{
- SAMLSubjectParser subjectParser = new SAMLSubjectParser();
- assertion.setSubject( (SubjectType) subjectParser.parse(xmlEventReader));
+ SAMLSubjectParser subjectParser = new SAMLSubjectParser();
+ assertion.setSubject( (SubjectType) subjectParser.parse(xmlEventReader));
}
else if( JBossSAMLConstants.CONDITIONS.get().equalsIgnoreCase( tag ) )
{
- try
- {
- QName notBeforeQName = new QName( "", JBossSAMLConstants.NOT_BEFORE.get() );
- QName notBeforeQNameWithNS = new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.NOT_BEFORE.get() );
-
- QName notAfterQName = new QName( "", JBossSAMLConstants.NOT_ON_OR_AFTER.get() );
- QName notAfterQNameWithNS = new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.NOT_ON_OR_AFTER.get() );
-
- StartElement conditionsElement = StaxParserUtil.getNextStartElement( xmlEventReader );
-
- Attribute notBeforeAttribute = conditionsElement.getAttributeByName( notBeforeQName );
- if( notBeforeAttribute == null )
- notBeforeAttribute = conditionsElement.getAttributeByName( notBeforeQNameWithNS );
-
- Attribute notAfterAttribute = conditionsElement.getAttributeByName( notAfterQName );
- if( notAfterAttribute == null )
- notAfterAttribute = conditionsElement.getAttributeByName( notAfterQNameWithNS );
-
-
- ConditionsType conditions = new ConditionsType();
-
- if( notBeforeAttribute != null )
- {
- String notBeforeValue = StaxParserUtil.getAttributeValue( notBeforeAttribute );
-
- DatatypeFactory dtf = DatatypeFactory.newInstance();
- XMLGregorianCalendar xmlcal = dtf.newXMLGregorianCalendar( notBeforeValue );
- conditions.setNotBefore( xmlcal );
- }
-
- if( notAfterAttribute != null )
- {
- String notAfterValue = StaxParserUtil.getAttributeValue( notAfterAttribute );
-
- DatatypeFactory dtf = DatatypeFactory.newInstance();
- XMLGregorianCalendar xmlcal = dtf.newXMLGregorianCalendar( notAfterValue );
- conditions.setNotOnOrAfter( xmlcal );
- }
-
- assertion.setConditions( conditions );
- }
- catch (DatatypeConfigurationException e)
- {
- throw new ParsingException( e );
- }
- }
- else
- {
- try
- {
- xmlEventReader.nextEvent();
- }
- catch (XMLStreamException e)
- {
- throw new ParsingException( e );
- }
+ SAMLConditionsParser conditionsParser = new SAMLConditionsParser();
+ ConditionsType conditions = (ConditionsType) conditionsParser.parse(xmlEventReader);
+
+ assertion.setConditions( conditions );
+
}
}
return assertion;
}
-
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
public boolean supports(QName qname)
{
return false;
}
+
+ private void bypassXMLSignatureBlock( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ while ( xmlEventReader.hasNext() )
+ {
+ EndElement endElement = StaxParserUtil.getNextEndElement( xmlEventReader );
+ if( endElement == null )
+ return;
+
+ if( StaxParserUtil.getEndElementName(endElement).equals( "Signature" ) )
+ return;
+ }
+ }
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java 2010-10-14 15:02:21 UTC (rev 464)
@@ -0,0 +1,178 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.parsers.saml;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
+import org.picketlink.identity.federation.saml.v2.assertion.AudienceRestrictionType;
+import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
+
+/**
+ * Parse the <conditions> in the saml assertion
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 14, 2010
+ */
+public class SAMLConditionsParser implements ParserNamespaceSupport
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ //We are entering this method with <conditions> as the next start element
+ //and we have to exit after seeing the </conditions> end tag
+
+ StartElement conditionsElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(conditionsElement, JBossSAMLConstants.CONDITIONS.get() );
+
+ DatatypeFactory dtf;
+ try
+ {
+ dtf = DatatypeFactory.newInstance();
+ }
+ catch (DatatypeConfigurationException e )
+ {
+ throw new ParsingException( e );
+ }
+
+ ConditionsType conditions = new ConditionsType();
+
+ String assertionNS = JBossSAMLURIConstants.ASSERTION_NSURI.get();
+
+ QName notBeforeQName = new QName( "", JBossSAMLConstants.NOT_BEFORE.get() );
+ QName notBeforeQNameWithNS = new QName( assertionNS , JBossSAMLConstants.NOT_BEFORE.get() );
+
+ QName notAfterQName = new QName( "", JBossSAMLConstants.NOT_ON_OR_AFTER.get() );
+ QName notAfterQNameWithNS = new QName( assertionNS , JBossSAMLConstants.NOT_ON_OR_AFTER.get() );
+
+ Attribute notBeforeAttribute = conditionsElement.getAttributeByName( notBeforeQName );
+ if( notBeforeAttribute == null )
+ notBeforeAttribute = conditionsElement.getAttributeByName( notBeforeQNameWithNS );
+
+ Attribute notAfterAttribute = conditionsElement.getAttributeByName( notAfterQName );
+ if( notAfterAttribute == null )
+ notAfterAttribute = conditionsElement.getAttributeByName( notAfterQNameWithNS );
+
+ if( notBeforeAttribute != null )
+ {
+ String notBeforeValue = StaxParserUtil.getAttributeValue( notBeforeAttribute );
+
+ XMLGregorianCalendar xmlcal = dtf.newXMLGregorianCalendar( notBeforeValue );
+ conditions.setNotBefore( xmlcal );
+ }
+
+ if( notAfterAttribute != null )
+ {
+ String notAfterValue = StaxParserUtil.getAttributeValue( notAfterAttribute );
+ XMLGregorianCalendar xmlcal = dtf.newXMLGregorianCalendar( notAfterValue );
+ conditions.setNotOnOrAfter( xmlcal );
+ }
+
+
+ //Let us find additional elements
+
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = StaxParserUtil.peek( xmlEventReader );
+
+ if( xmlEvent instanceof EndElement )
+ {
+ EndElement nextEndElement = (EndElement) xmlEvent;
+ if( StaxParserUtil.matches(nextEndElement, JBossSAMLConstants.CONDITIONS.get() ))
+ break;
+ }
+
+ String tag = null;
+
+ if( xmlEvent instanceof StartElement )
+ {
+ StartElement peekedElement = (StartElement) xmlEvent;
+ tag = StaxParserUtil.getStartElementName(peekedElement);
+ }
+
+ if( JBossSAMLConstants.AUDIENCE_RESTRICTION.get().equals( tag ) )
+ {
+ AudienceRestrictionType audienceRestriction = getAudienceRestriction(xmlEventReader);
+ conditions.getConditionOrAudienceRestrictionOrOneTimeUse().add( audienceRestriction );
+ }
+ else throw new RuntimeException( "Unknown tag:" + tag );
+ }
+ return conditions;
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ return false;
+ }
+
+ /**
+ * Parse the <audiencerestriction/> element
+ * @param xmlEventReader
+ * @return
+ * @throws ParsingException
+ */
+ private AudienceRestrictionType getAudienceRestriction( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ StartElement audienceRestElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.matches(audienceRestElement, JBossSAMLConstants.AUDIENCE_RESTRICTION.get() );
+
+ AudienceRestrictionType audience = new AudienceRestrictionType();
+
+ while( xmlEventReader.hasNext() )
+ {
+ StartElement audienceElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ if( !StaxParserUtil.matches(audienceElement, JBossSAMLConstants.AUDIENCE.get() ) )
+ break;
+
+ String audienceValue = StaxParserUtil.getElementText( xmlEventReader );
+ audience.getAudience().add( audienceValue );
+
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if( xmlEvent instanceof EndElement )
+ {
+ EndElement endElement = (EndElement) xmlEvent;
+ if( StaxParserUtil.matches(endElement, JBossSAMLConstants.AUDIENCE_RESTRICTION.get() ))
+ {
+ StaxParserUtil.getNextEvent(xmlEventReader); //Just get the end element
+ break;
+ }
+ }
+ }
+ return audience;
+ }
+}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-10-12 22:29:13 UTC (rev 463)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-10-14 15:02:21 UTC (rev 464)
@@ -29,7 +29,9 @@
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.parsers.AbstractParser;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
/**
@@ -39,6 +41,9 @@
*/
public class SAMLParser extends AbstractParser
{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
{
while( xmlEventReader.hasNext() )
@@ -58,7 +63,7 @@
StartElement startElement = (StartElement) xmlEvent;
String elementName = StaxParserUtil.getStartElementName( startElement );
- if( elementName.equalsIgnoreCase( SAMLAssertionParser.LOCALPART ))
+ if( elementName.equalsIgnoreCase( JBossSAMLConstants.ASSERTION.get() ))
{
SAMLAssertionParser assertionParser = new SAMLAssertionParser();
return assertionParser.parse( xmlEventReader );
@@ -76,9 +81,12 @@
}
}
}
- return null;
+ throw new RuntimeException( "SAML Parsing has failed" );
}
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
public boolean supports(QName qname)
{
return JBossSAMLURIConstants.ASSERTION_NSURI.get().equals( qname.getNamespaceURI() );
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java 2010-10-12 22:29:13 UTC (rev 463)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java 2010-10-14 15:02:21 UTC (rev 464)
@@ -49,6 +49,9 @@
{
private ObjectFactory objectFactory = new ObjectFactory();
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
{
StaxParserUtil.getNextEvent(xmlEventReader);
@@ -129,9 +132,11 @@
return subject;
}
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
public boolean supports(QName qname)
{
return false;
}
-
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-10-12 22:29:13 UTC (rev 463)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-10-14 15:02:21 UTC (rev 464)
@@ -28,6 +28,9 @@
*/
public enum JBossSAMLConstants
{
+ ASSERTION( "Assertion" ),
+ AUDIENCE( "Audience" ),
+ AUDIENCE_RESTRICTION( "AudienceRestriction" ),
CONDITIONS( "Conditions" ),
ISSUER( "Issuer" ),
LANG_EN("en"),
@@ -37,6 +40,7 @@
NAME_QUALIFIER( "NameQualifier" ),
NOT_BEFORE( "NotBefore" ),
NOT_ON_OR_AFTER( "NotOnOrAfter" ),
+ SIGNATURE( "Signature" ),
SIGNATURE_SHA1_WITH_DSA("http://www.w3.org/2000/09/xmldsig#dsa-sha1"),
SIGNATURE_SHA1_WITH_RSA("http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
SUBJECT( "Subject" ),
Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-10-12 22:29:13 UTC (rev 463)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-10-14 15:02:21 UTC (rev 464)
@@ -33,11 +33,13 @@
import org.junit.Test;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.AudienceRestrictionType;
import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
/**
+ * Test the parsing of saml assertions
* @author Anil.Saldhana(a)redhat.com
* @since Oct 12, 2010
*/
@@ -46,12 +48,17 @@
@Test
public void testSAMLAssertionParsing() throws Exception
{
+ DatatypeFactory dtf = DatatypeFactory.newInstance();
+
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-assertion.xml" );
SAMLParser parser = new SAMLParser();
AssertionType assertion = (AssertionType) parser.parse(configStream);
assertNotNull( assertion );
+
+ assertEquals( "ID_ab0392ef-b557-4453-95a8-a7e168da8ac5", assertion.getID() );
+ assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.869Z" ), assertion.getIssueInstant() );
//Issuer
assertEquals( "Test STS", assertion.getIssuer().getValue() );
@@ -60,7 +67,6 @@
List<JAXBElement<?>> content = subject.getContent();
- DatatypeFactory dtf = DatatypeFactory.newInstance();
int size = content.size();
@@ -86,4 +92,63 @@
}
}
}
+
+
+ /**
+ * This test validates the parsing of audience restrictions inside the conditions
+ * @throws Exception
+ */
+ @Test
+ public void testSAMLAssertionParsingWithAudienceRestriction() throws Exception
+ {
+ DatatypeFactory dtf = DatatypeFactory.newInstance();
+
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-assertion-audiencerestriction.xml" );
+
+ SAMLParser parser = new SAMLParser();
+ AssertionType assertion = (AssertionType) parser.parse(configStream);
+ assertNotNull( assertion );
+
+ assertEquals( "ID_cf9efbf0-9d7f-4b4a-b77f-d83ecaafd374", assertion.getID() );
+ assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.911Z" ), assertion.getIssueInstant() );
+ assertEquals( "2.0", assertion.getVersion() );
+
+ //Issuer
+ assertEquals( "Test STS", assertion.getIssuer().getValue() );
+
+ //Subject
+ SubjectType subject = assertion.getSubject();
+ 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( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.911Z" ) , conditions.getNotBefore() );
+ assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T21:13:37.911Z" ) , conditions.getNotOnOrAfter() );
+
+ //Audience Restriction
+ AudienceRestrictionType audienceRestrictionType =
+ (AudienceRestrictionType) conditions.getConditionOrAudienceRestrictionOrOneTimeUse();
+ assertEquals( 1, audienceRestrictionType.getAudience().size() );
+ assertEquals( "http://services.testcorp.org/provider2", audienceRestrictionType.getAudience().get( 0 ));
+ }
+ }
+ }
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion-audiencerestriction.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion-audiencerestriction.xml (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion-audiencerestriction.xml 2010-10-14 15:02:21 UTC (rev 464)
@@ -0,0 +1,48 @@
+<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
+ ID="ID_cf9efbf0-9d7f-4b4a-b77f-d83ecaafd374" IssueInstant="2010-09-30T19:13:37.911Z"
+ Version="2.0">
+ <saml2:Issuer>Test STS</saml2:Issuer>
+ <saml2:Subject>
+ <saml2:NameID NameQualifier="urn:picketlink:identity-federation">jduke</saml2:NameID>
+ <saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer" />
+ </saml2:Subject>
+ <saml2:Conditions NotBefore="2010-09-30T19:13:37.911Z"
+ NotOnOrAfter="2010-09-30T21:13:37.911Z">
+ <saml2:AudienceRestriction>
+ <saml2:Audience>http://services.testcorp.org/provider2
+ </saml2:Audience>
+ </saml2:AudienceRestriction>
+ </saml2:Conditions>
+ <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_cf9efbf0-9d7f-4b4a-b77f-d83ecaafd374">
+ <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>TMZdBOA0MvR7aNpCAg2CXggkdZc=</ds:DigestValue>
+ </ds:Reference>
+ </ds:SignedInfo>
+ <ds:SignatureValue>
+ Q8mEzGWlnWmSmb+KUkP0wju4LOINaUYXBBXNF5vRhYVBixSUe8HSHKzNIdQ+ZGtijaV1vh0LUFbT
+ //faZKyHRgPXtskDn8cJTVT6obp7rUIOCKMoCs5p9/bUAbtaQHYjfWpifdT3PaTdlehpS8INK2P0
+ JUQYU3q8F3u7je9VHbA=
+ </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>
+</saml2:Assertion>
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r463 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/parsers/wst and 2 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-12 18:29:13 -0400 (Tue, 12 Oct 2010)
New Revision: 463
Added:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java
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/wst/WSTRequestSecurityTokenCollectionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
Log:
PLFED-109: ws-t payload via stax
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 2010-10-12 22:28:48 UTC (rev 462)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2010-10-12 22:29:13 UTC (rev 463)
@@ -25,12 +25,14 @@
import javax.xml.stream.Location;
import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
/**
@@ -89,42 +91,66 @@
return builder.toString();
}
+ public static XMLEvent getNextEvent( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ try
+ {
+ return xmlEventReader.nextEvent();
+ }
+ catch ( XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+
/**
* Get the next {@code StartElement }
* @param xmlEventReader
* @return
- * @throws XMLStreamException
+ * @throws ParsingException
*/
- public static StartElement getNextStartElement( XMLEventReader xmlEventReader ) throws XMLStreamException
+ public static StartElement getNextStartElement( XMLEventReader xmlEventReader ) throws ParsingException
{
- while( true )
+ try
{
- XMLEvent xmlEvent = xmlEventReader.nextEvent();
-
- if( xmlEvent == null || xmlEvent.isStartElement() )
- return ( StartElement ) xmlEvent;
- else
- xmlEvent = xmlEventReader.nextEvent();
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+
+ if( xmlEvent == null || xmlEvent.isStartElement() )
+ return ( StartElement ) xmlEvent;
+ }
}
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ return null;
}
/**
* Get the next {@code EndElement}
* @param xmlEventReader
* @return
- * @throws XMLStreamException
+ * @throws ParsingException
*/
- public static EndElement getNextEndElement( XMLEventReader xmlEventReader ) throws XMLStreamException
+ public static EndElement getNextEndElement( XMLEventReader xmlEventReader ) throws ParsingException
{
- while( true )
+ try
{
- XMLEvent xmlEvent = xmlEventReader.nextEvent();
-
- if( xmlEvent == null || xmlEvent.isEndElement() )
- return ( EndElement ) xmlEvent;
- else
- xmlEvent = xmlEventReader.nextEvent();
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+
+ if( xmlEvent == null || xmlEvent.isEndElement() )
+ return ( EndElement ) xmlEvent;
+ }
}
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ return null;
}
/**
@@ -147,42 +173,68 @@
return trim( endElement.getName().getLocalPart() );
}
+ public static XMLEvent peek( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ try
+ {
+ return xmlEventReader.peek();
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+
/**
* Peek the next {@code StartElement }
* @param xmlEventReader
* @return
- * @throws XMLStreamException
+ * @throws ParsingException
*/
- public static StartElement peekNextStartElement( XMLEventReader xmlEventReader ) throws XMLStreamException
+ public static StartElement peekNextStartElement( XMLEventReader xmlEventReader ) throws ParsingException
{
- while( true )
+ try
{
- XMLEvent xmlEvent = xmlEventReader.peek();
-
- if( xmlEvent == null || xmlEvent.isStartElement() )
- return ( StartElement ) xmlEvent;
- else
- xmlEvent = xmlEventReader.nextEvent();
+ while( true )
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ if( xmlEvent == null || xmlEvent.isStartElement() )
+ return ( StartElement ) xmlEvent;
+ else
+ xmlEvent = xmlEventReader.nextEvent();
+ }
}
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
}
/**
* Peek the next {@code EndElement}
* @param xmlEventReader
* @return
- * @throws XMLStreamException
+ * @throws ParsingException
*/
- public static EndElement peekNextEndElement( XMLEventReader xmlEventReader ) throws XMLStreamException
+ public static EndElement peekNextEndElement( XMLEventReader xmlEventReader ) throws ParsingException
{
- while( true )
+ try
{
- XMLEvent xmlEvent = xmlEventReader.peek();
-
- if( xmlEvent == null || xmlEvent.isEndElement() )
- return ( EndElement ) xmlEvent;
- else
- xmlEvent = xmlEventReader.nextEvent();
+ while( true )
+ {
+ XMLEvent xmlEvent = xmlEventReader.peek();
+
+ if( xmlEvent == null || xmlEvent.isEndElement() )
+ return ( EndElement ) xmlEvent;
+ else
+ xmlEvent = xmlEventReader.nextEvent();
+ }
}
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
}
/**
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenCollectionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenCollectionParser.java 2010-10-12 22:28:48 UTC (rev 462)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenCollectionParser.java 2010-10-12 22:29:13 UTC (rev 463)
@@ -59,17 +59,10 @@
//Peek at the next event
while( true )
{
- StartElement peekedElement = null;
- try
- {
- peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ StartElement peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
if( peekedElement == null )
- break;
- }
- catch (XMLStreamException e)
- {
- throw new ParsingException( e );
- }
+ break;
+
String tag = StaxParserUtil.getStartElementName( peekedElement );
if( WSTRequestSecurityTokenParser.LOCALPART.equalsIgnoreCase( tag ) )
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-12 22:28:48 UTC (rev 462)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-12 22:29:13 UTC (rev 463)
@@ -49,15 +49,7 @@
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
{
- StartElement startElement = null;
- try
- {
- startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
- }
- catch (XMLStreamException e)
- {
- throw new ParsingException( e );
- }
+ StartElement startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
RequestSecurityToken requestToken = new RequestSecurityToken();
@@ -71,13 +63,16 @@
try
{
StartElement subEvent = StaxParserUtil.getNextStartElement( xmlEventReader );
+ if( subEvent == null )
+ break;
+
String tag = StaxParserUtil.getStartElementName( subEvent );
- if( tag.equals( "RequestType" ))
+ if( tag.equals( WSTrustConstants.REQUEST_TYPE ))
{
String value = xmlEventReader.getElementText();
requestToken.setRequestType( new URI( value ));
}
- else if( tag.equals( "TokenType" ))
+ else if( tag.equals( WSTrustConstants.TOKEN_TYPE ))
{
String value = xmlEventReader.getElementText();
requestToken.setTokenType( new URI( value ));
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java 2010-10-12 22:28:48 UTC (rev 462)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustParser.java 2010-10-12 22:29:13 UTC (rev 463)
@@ -21,17 +21,14 @@
*/
package org.picketlink.identity.federation.core.parsers.wst;
-import java.io.InputStream;
-
import javax.xml.namespace.QName;
-import javax.xml.stream.EventFilter;
import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.AbstractParser;
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
@@ -42,43 +39,9 @@
* @author Anil.Saldhana(a)redhat.com
* @since Oct 11, 2010
*/
-public class WSTrustParser implements ParserNamespaceSupport
-{
+public class WSTrustParser extends AbstractParser
+{
/**
- * Parse an InputStream for WS-Trust payload
- * @param configStream
- * @return
- * @throws {@link IllegalArgumentException}
- * @throws {@link IllegalArgumentException} when the configStream is null
- */
- public Object parse( InputStream configStream ) throws ParsingException
- {
- if( configStream == null )
- throw new IllegalArgumentException( " Input Stream is null " );
-
- XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
- //XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(xmlSource);
- XMLEventReader xmlEventReader = StaxParserUtil.getXMLEventReader( configStream );
-
- try
- {
- xmlEventReader = xmlInputFactory.createFilteredReader( xmlEventReader, new EventFilter()
- {
- public boolean accept(XMLEvent xmlEvent)
- {
- return xmlEvent.isStartElement() || xmlEvent.isEndElement();
- }
- });
- }
- catch (XMLStreamException e)
- {
- throw new ParsingException( e );
- }
-
- return parse( xmlEventReader );
- }
-
- /**
* @see {@link ParserNamespaceSupport#parse(XMLEventReader)}}
*/
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-12 22:28:48 UTC (rev 462)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-12 22:29:13 UTC (rev 463)
@@ -79,4 +79,7 @@
//Element Names
public static final String RST = "RequestSecurityToken";
+ public static final String REQUEST_TYPE = "RequestType";
+ public static final String TOKEN_TYPE = "TokenType";
+ public static final String VALIDATE_TARGET = "ValidateTarget";
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustBatchValidateParsingTestCase.java 2010-10-12 22:29:13 UTC (rev 463)
@@ -0,0 +1,68 @@
+/*
+ * 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.wst;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.wst.WSTrustParser;
+import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
+import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken;
+import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityTokenCollection;
+
+/**
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 12, 2010
+ */
+public class WSTrustBatchValidateParsingTestCase
+{
+ @Test
+ @Ignore
+ public void testWST_BatchValidate() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream( "parser/wst/wst-batch-validate.xml" );
+
+ WSTrustParser parser = new WSTrustParser();
+ RequestSecurityTokenCollection requestCollection = (RequestSecurityTokenCollection) parser.parse( configStream );
+ assertNotNull( "Request Security Token Collection is null?", requestCollection );
+
+ List<RequestSecurityToken> tokens = requestCollection.getRequestSecurityTokens();
+ assertEquals( 2, tokens.size() );
+
+ /*RequestSecurityToken rst1 = tokens.get( 0 );
+ assertEquals( "context1", rst1.getContext() );
+ assertEquals( WSTrustConstants.BATCH_ISSUE_REQUEST, rst1.getRequestType().toASCIIString() );
+ assertEquals( WSTrustConstants.SAML2_TOKEN_TYPE, rst1.getTokenType().toASCIIString() );
+
+ RequestSecurityToken rst2 = tokens.get( 1 );
+ assertEquals( "context2", rst2.getContext() );
+ assertEquals( WSTrustConstants.BATCH_ISSUE_REQUEST , rst2.getRequestType().toASCIIString() );
+ assertEquals( "http://www.tokens.org/SpecialToken" , rst2.getTokenType().toASCIIString() ); */
+ }
+
+}
14 years, 2 months
Picketlink SVN: r462 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-12 18:28:48 -0400 (Tue, 12 Oct 2010)
New Revision: 462
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
Log:
PLFED-110: saml payload via stax
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-10-12 22:28:12 UTC (rev 461)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-10-12 22:28:48 UTC (rev 462)
@@ -28,10 +28,19 @@
*/
public enum JBossSAMLConstants
{
+ CONDITIONS( "Conditions" ),
+ ISSUER( "Issuer" ),
LANG_EN("en"),
METADATA_MIME("application/samlmetadata+xml"),
+ METHOD( "Method" ),
+ NAMEID( "NameID" ),
+ NAME_QUALIFIER( "NameQualifier" ),
+ NOT_BEFORE( "NotBefore" ),
+ NOT_ON_OR_AFTER( "NotOnOrAfter" ),
SIGNATURE_SHA1_WITH_DSA("http://www.w3.org/2000/09/xmldsig#dsa-sha1"),
SIGNATURE_SHA1_WITH_RSA("http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
+ SUBJECT( "Subject" ),
+ SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
VERSION_2_0("2.0"),
HTTP_POST_BINDING("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
14 years, 2 months
Picketlink SVN: r461 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/parsers/saml and 4 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-12 18:28:12 -0400 (Tue, 12 Oct 2010)
New Revision: 461
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/
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/resources/parser/saml2/
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion.xml
Log:
PLFED-110: saml payload via stax
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java 2010-10-12 22:28:12 UTC (rev 461)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.parsers;
+
+import java.io.InputStream;
+
+import javax.xml.stream.EventFilter;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+
+
+/**
+ * Base class for parsers
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 12, 2010
+ */
+public abstract class AbstractParser implements ParserNamespaceSupport
+{
+ /**
+ * Parse an InputStream for payload
+ * @param configStream
+ * @return
+ * @throws {@link IllegalArgumentException}
+ * @throws {@link IllegalArgumentException} when the configStream is null
+ */
+ public Object parse( InputStream configStream ) throws ParsingException
+ {
+ if( configStream == null )
+ throw new IllegalArgumentException( " Input Stream is null " );
+
+ XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+ //XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(xmlSource);
+ XMLEventReader xmlEventReader = StaxParserUtil.getXMLEventReader( configStream );
+
+ try
+ {
+ xmlEventReader = xmlInputFactory.createFilteredReader( xmlEventReader, new EventFilter()
+ {
+ public boolean accept(XMLEvent xmlEvent)
+ {
+ return xmlEvent.isStartElement() || xmlEvent.isEndElement();
+ }
+ });
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+
+ return parse( xmlEventReader );
+ }
+
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAssertionParser.java 2010-10-12 22:28:12 UTC (rev 461)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.parsers.saml;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
+
+/**
+ * Parse the saml assertion
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 12, 2010
+ */
+public class SAMLAssertionParser implements ParserNamespaceSupport
+{
+ public static final String LOCALPART = "Assertion";
+
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ try
+ {
+ xmlEventReader.nextEvent();
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+
+ AssertionType assertion = new AssertionType();
+
+ //Peek at the next event
+ while( xmlEventReader.hasNext() )
+ {
+ StartElement peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( peekedElement == null )
+ break;
+
+ String tag = StaxParserUtil.getStartElementName( peekedElement );
+
+ if( JBossSAMLConstants.ISSUER.get().equalsIgnoreCase( tag ) )
+ {
+ try
+ {
+ StaxParserUtil.getNextStartElement( xmlEventReader );
+ String issuerValue = xmlEventReader.getElementText();
+
+ NameIDType issuer = new NameIDType();
+ issuer.setValue( issuerValue );
+
+ assertion.setIssuer( issuer );
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+ else if( JBossSAMLConstants.SUBJECT.get().equalsIgnoreCase( tag ) )
+ {
+ SAMLSubjectParser subjectParser = new SAMLSubjectParser();
+ assertion.setSubject( (SubjectType) subjectParser.parse(xmlEventReader));
+ }
+ else if( JBossSAMLConstants.CONDITIONS.get().equalsIgnoreCase( tag ) )
+ {
+ try
+ {
+ QName notBeforeQName = new QName( "", JBossSAMLConstants.NOT_BEFORE.get() );
+ QName notBeforeQNameWithNS = new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.NOT_BEFORE.get() );
+
+ QName notAfterQName = new QName( "", JBossSAMLConstants.NOT_ON_OR_AFTER.get() );
+ QName notAfterQNameWithNS = new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.NOT_ON_OR_AFTER.get() );
+
+ StartElement conditionsElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+
+ Attribute notBeforeAttribute = conditionsElement.getAttributeByName( notBeforeQName );
+ if( notBeforeAttribute == null )
+ notBeforeAttribute = conditionsElement.getAttributeByName( notBeforeQNameWithNS );
+
+ Attribute notAfterAttribute = conditionsElement.getAttributeByName( notAfterQName );
+ if( notAfterAttribute == null )
+ notAfterAttribute = conditionsElement.getAttributeByName( notAfterQNameWithNS );
+
+
+ ConditionsType conditions = new ConditionsType();
+
+ if( notBeforeAttribute != null )
+ {
+ String notBeforeValue = StaxParserUtil.getAttributeValue( notBeforeAttribute );
+
+ DatatypeFactory dtf = DatatypeFactory.newInstance();
+ XMLGregorianCalendar xmlcal = dtf.newXMLGregorianCalendar( notBeforeValue );
+ conditions.setNotBefore( xmlcal );
+ }
+
+ if( notAfterAttribute != null )
+ {
+ String notAfterValue = StaxParserUtil.getAttributeValue( notAfterAttribute );
+
+ DatatypeFactory dtf = DatatypeFactory.newInstance();
+ XMLGregorianCalendar xmlcal = dtf.newXMLGregorianCalendar( notAfterValue );
+ conditions.setNotOnOrAfter( xmlcal );
+ }
+
+ assertion.setConditions( conditions );
+ }
+ catch (DatatypeConfigurationException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+ else
+ {
+ try
+ {
+ xmlEventReader.nextEvent();
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+ }
+ return assertion;
+ }
+
+ public boolean supports(QName qname)
+ {
+ return false;
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-10-12 22:28:12 UTC (rev 461)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.parsers.saml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.AbstractParser;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
+
+/**
+ * Parse SAML payload
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 12, 2010
+ */
+public class SAMLParser extends AbstractParser
+{
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = null;
+ try
+ {
+ xmlEvent = xmlEventReader.peek();
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+
+ if( xmlEvent instanceof StartElement )
+ {
+ StartElement startElement = (StartElement) xmlEvent;
+
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+ if( elementName.equalsIgnoreCase( SAMLAssertionParser.LOCALPART ))
+ {
+ SAMLAssertionParser assertionParser = new SAMLAssertionParser();
+ return assertionParser.parse( xmlEventReader );
+ }
+ }
+ else
+ {
+ try
+ {
+ xmlEventReader.nextEvent();
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+ }
+ return null;
+ }
+
+ public boolean supports(QName qname)
+ {
+ return JBossSAMLURIConstants.ASSERTION_NSURI.get().equals( qname.getNamespaceURI() );
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSubjectParser.java 2010-10-12 22:28:12 UTC (rev 461)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.parsers.saml;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.ObjectFactory;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
+
+/**
+ * Parse the saml subject
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 12, 2010
+ */
+public class SAMLSubjectParser implements ParserNamespaceSupport
+{
+ private ObjectFactory objectFactory = new ObjectFactory();
+
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ StaxParserUtil.getNextEvent(xmlEventReader);
+
+ SubjectType subject = new SubjectType();
+
+ //Peek at the next event
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if( xmlEvent instanceof EndElement )
+ {
+ EndElement endElement = (EndElement) xmlEvent;
+ String endElementValue = StaxParserUtil.getEndElementName(endElement);
+ if( endElementValue.equalsIgnoreCase( JBossSAMLConstants.SUBJECT.get() ))
+ break;
+ }
+
+ StartElement peekedElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( peekedElement == null )
+ break;
+
+ String tag = StaxParserUtil.getStartElementName( peekedElement );
+
+ if( JBossSAMLConstants.NAMEID.get().equalsIgnoreCase( tag ) )
+ {
+ try
+ {
+ StartElement nameIDElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ Attribute nameQualifier = nameIDElement.getAttributeByName( new QName( "", JBossSAMLConstants.NAME_QUALIFIER.get() ));
+ if( nameQualifier == null )
+ nameQualifier = nameIDElement.getAttributeByName( new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(),
+ JBossSAMLConstants.NAME_QUALIFIER.get() ));
+
+ String nameIDValue = xmlEventReader.getElementText();
+
+ NameIDType nameID = new NameIDType();
+ nameID.setValue( nameIDValue );
+ if( nameQualifier != null )
+ {
+ nameID.setNameQualifier( StaxParserUtil.getAttributeValue(nameQualifier) );
+ }
+
+ JAXBElement<NameIDType> jaxbNameID = objectFactory.createNameID( nameID );
+ subject.getContent().add( jaxbNameID );
+
+ //There is no need to get the end tag as the "getElementText" call above puts us past that
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+ else if( JBossSAMLConstants.SUBJECT_CONFIRMATION.get().equalsIgnoreCase( tag ) )
+ {
+ StartElement subjectConfirmationElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ Attribute method = subjectConfirmationElement.getAttributeByName( new QName( "", JBossSAMLConstants.METHOD.get() ));
+ if( method == null )
+ method = subjectConfirmationElement.getAttributeByName( new QName( JBossSAMLURIConstants.ASSERTION_NSURI.get(),
+ JBossSAMLConstants.METHOD.get() ));
+
+ SubjectConfirmationType subjectConfirmationType = new SubjectConfirmationType();
+
+ if( method != null )
+ {
+ subjectConfirmationType.setMethod( StaxParserUtil.getAttributeValue( method ) );
+ }
+
+ JAXBElement<SubjectConfirmationType> jaxbSubjectConf = objectFactory.createSubjectConfirmation( subjectConfirmationType );
+ subject.getContent().add(jaxbSubjectConf);
+
+ //Get the end tag
+ StaxParserUtil.getNextEvent(xmlEventReader);
+ }
+ else throw new RuntimeException( "Unknown tag:" + tag );
+ }
+
+ return subject;
+ }
+
+ public boolean supports(QName qname)
+ {
+ return false;
+ }
+
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-10-12 22:28:12 UTC (rev 461)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.test.identity.federation.core.parser.saml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+import java.util.List;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.datatype.DatatypeFactory;
+
+import org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
+
+/**
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 12, 2010
+ */
+public class SAMLAssertionParserTestCase
+{
+ @Test
+ public void testSAMLAssertionParsing() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream( "parser/saml2/saml2-assertion.xml" );
+
+ SAMLParser parser = new SAMLParser();
+ AssertionType assertion = (AssertionType) parser.parse(configStream);
+ assertNotNull( assertion );
+ //Issuer
+ assertEquals( "Test STS", assertion.getIssuer().getValue() );
+
+ //Subject
+ SubjectType subject = assertion.getSubject();
+ List<JAXBElement<?>> content = subject.getContent();
+
+
+ DatatypeFactory dtf = DatatypeFactory.newInstance();
+
+ 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( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.869Z" ) , conditions.getNotBefore() );
+ assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T21:13:37.869Z" ) , conditions.getNotOnOrAfter() );
+
+ }
+ }
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion.xml (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-assertion.xml 2010-10-12 22:28:12 UTC (rev 461)
@@ -0,0 +1,43 @@
+<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
+ ID="ID_ab0392ef-b557-4453-95a8-a7e168da8ac5" IssueInstant="2010-09-30T19:13:37.869Z"
+ Version="2.0">
+ <saml2:Issuer>Test STS</saml2:Issuer>
+ <saml2:Subject>
+ <saml2:NameID NameQualifier="urn:picketlink:identity-federation">jduke</saml2:NameID>
+ <saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer" />
+ </saml2:Subject>
+ <saml2:Conditions NotBefore="2010-09-30T19:13:37.869Z"
+ NotOnOrAfter="2010-09-30T21:13:37.869Z" />
+ <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>
+</saml2:Assertion>
\ No newline at end of file
14 years, 2 months
Picketlink SVN: r460 - in federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core: parsers/wst and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-12 13:57:55 -0400 (Tue, 12 Oct 2010)
New Revision: 460
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/wst/WSTRequestSecurityTokenParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
Log:
PLFED-109: stax parsing for ws-trust
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 2010-10-12 17:49:08 UTC (rev 459)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2010-10-12 17:57:55 UTC (rev 460)
@@ -138,6 +138,16 @@
}
/**
+ * Return the name of the end element
+ * @param endElement
+ * @return
+ */
+ public static String getEndElementName( EndElement endElement )
+ {
+ return trim( endElement.getName().getLocalPart() );
+ }
+
+ /**
* Peek the next {@code StartElement }
* @param xmlEventReader
* @return
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-12 17:49:08 UTC (rev 459)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-12 17:57:55 UTC (rev 460)
@@ -28,11 +28,14 @@
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken;
/**
@@ -63,13 +66,11 @@
String contextValue = StaxParserUtil.getAttributeValue( contextAttribute );
requestToken.setContext( contextValue );
- int index = 0;
-
- while( index < 2 )
+ while( true )
{
try
{
- StartElement subEvent = (StartElement) xmlEventReader.nextEvent();
+ StartElement subEvent = StaxParserUtil.getNextStartElement( xmlEventReader );
String tag = StaxParserUtil.getStartElementName( subEvent );
if( tag.equals( "RequestType" ))
{
@@ -80,7 +81,15 @@
{
String value = xmlEventReader.getElementText();
requestToken.setTokenType( new URI( value ));
- }
+ }
+
+ XMLEvent xmlEvent = xmlEventReader.peek();
+ if( xmlEvent.isEndElement() )
+ {
+ EndElement endElement = (EndElement) xmlEvent;
+ if( StaxParserUtil.getEndElementName( endElement ).equalsIgnoreCase( WSTrustConstants.RST ) )
+ break;
+ }
}
catch( XMLStreamException e )
{
@@ -89,8 +98,7 @@
catch (URISyntaxException e)
{
throw new ParsingException( e );
- }
- index++;
+ }
}
return requestToken;
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-12 17:49:08 UTC (rev 459)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-12 17:57:55 UTC (rev 460)
@@ -76,4 +76,7 @@
//Token Types
public static final String SAML2_TOKEN_TYPE = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0";
+
+ //Element Names
+ public static final String RST = "RequestSecurityToken";
}
\ No newline at end of file
14 years, 2 months