[jboss-cvs] Picketlink SVN: r461 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/parsers/saml and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 12 18:28:12 EDT 2010
Author: anil.saldhana at 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 at 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 at 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 at 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 at 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 at 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
More information about the jboss-cvs-commits
mailing list