Author: anil.saldhana(a)jboss.com
Date: 2010-11-03 13:41:54 -0400 (Wed, 03 Nov 2010)
New Revision: 520
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.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/SAMLRequestAbstractParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.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-109: PLFED-110: parse SLO request response
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-03
14:15:54 UTC (rev 519)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -31,7 +31,6 @@
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.protocol.AuthnRequestType;
import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
@@ -59,23 +58,13 @@
startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
if( startElement == null )
break;
+ super.parseCommonElements(startElement, xmlEventReader, authnRequest);
+
String elementName = StaxParserUtil.getStartElementName( startElement );
- if( JBossSAMLConstants.ISSUER.get().equals( elementName ))
+ if( JBossSAMLConstants.NAMEID_POLICY.get().equals( elementName ))
{
startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
- NameIDType issuer = new NameIDType();
- issuer.setValue( StaxParserUtil.getElementText( xmlEventReader ));
- authnRequest.setIssuer( issuer );
- }
- else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
- {
- startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
- StaxParserUtil.bypassElementBlock(xmlEventReader,
JBossSAMLConstants.SIGNATURE.get() );
- }
- else if( JBossSAMLConstants.NAMEID_POLICY.get().equals( elementName ))
- {
- startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
authnRequest.setNameIDPolicy( getNameIDPolicy( startElement ));
}
}
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-11-03
14:15:54 UTC (rev 519)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -68,6 +68,18 @@
return authNRequestParser.parse( xmlEventReader );
}
else if( JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( nsURI )
&&
+ JBossSAMLConstants.LOGOUT_REQUEST.get().equals(
startElementName.getLocalPart() ))
+ {
+ SAMLSloRequestParser sloParser = new SAMLSloRequestParser();
+ return sloParser.parse( xmlEventReader );
+ }
+ else if( JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( nsURI )
&&
+ JBossSAMLConstants.LOGOUT_RESPONSE.get().equals(
startElementName.getLocalPart() ))
+ {
+ SAMLSloResponseParser sloParser = new SAMLSloResponseParser();
+ return sloParser.parse( xmlEventReader );
+ }
+ else if( JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( nsURI )
&&
JBossSAMLConstants.RESPONSE.get().equals(
startElementName.getLocalPart() ))
{
SAMLResponseParser responseParser = new SAMLResponseParser();
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java 2010-11-03
14:15:54 UTC (rev 519)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -22,12 +22,15 @@
package org.picketlink.identity.federation.core.parsers.saml;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
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.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
import org.picketlink.identity.federation.saml.v2.protocol.RequestAbstractType;
/**
@@ -68,4 +71,23 @@
if( consent != null )
request.setConsent( StaxParserUtil.getAttributeValue( consent ));
}
+
+ protected void parseCommonElements( StartElement startElement, XMLEventReader
xmlEventReader,
+ RequestAbstractType request ) throws ParsingException
+ {
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+
+ if( JBossSAMLConstants.ISSUER.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ NameIDType issuer = new NameIDType();
+ issuer.setValue( StaxParserUtil.getElementText( xmlEventReader ));
+ request.setIssuer( issuer );
+ }
+ else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StaxParserUtil.bypassElementBlock(xmlEventReader,
JBossSAMLConstants.SIGNATURE.get() );
+ }
+ }
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java 2010-11-03
14:15:54 UTC (rev 519)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -23,10 +23,7 @@
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.ConfigurationException;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
@@ -36,8 +33,6 @@
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.protocol.ResponseType;
-import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
-import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
/**
* Parse the SAML Response
@@ -115,52 +110,5 @@
return response;
}
- /**
- * Parse the status element
- * @param xmlEventReader
- * @return
- * @throws ParsingException
- */
- private StatusType parseStatus( XMLEventReader xmlEventReader ) throws
ParsingException
- {
- //Get the Start Element
- StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- String STATUS = JBossSAMLConstants.STATUS.get();
- StaxParserUtil.validate(startElement, STATUS );
-
- StatusType status = new StatusType();
-
- while( xmlEventReader.hasNext() )
- {
- startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
- QName startElementName = startElement.getName();
- String elementTag = startElementName.getLocalPart();
-
- StatusCodeType statusCode = new StatusCodeType();
-
- if( JBossSAMLConstants.STATUS_CODE.get().equals( elementTag ))
- {
- startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
- Attribute valueAttr = startElement.getAttributeByName( new QName(
"Value" ));
- if( valueAttr != null )
- {
- statusCode.setValue( StaxParserUtil.getAttributeValue( valueAttr ));
- }
- //Get the next end element
- StaxParserUtil.getNextEndElement(xmlEventReader);
- }
-
- status.setStatusCode( statusCode );
-
- //Get the next end element
- XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
- if( xmlEvent instanceof EndElement )
- {
- EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- if( StaxParserUtil.matches(endElement, STATUS ))
- break;
- }
- }
- return status;
- }
+
}
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -0,0 +1,106 @@
+/*
+ * 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 static
org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants.LOGOUT_REQUEST;
+import static
org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.PROTOCOL_NSURI;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+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.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.LogoutRequestType;
+
+/**
+ * Parse the Single Log Out requests
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloRequestParser extends SAMLRequestAbstractParser implements
ParserNamespaceSupport
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ //Get the startelement
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(startElement, LOGOUT_REQUEST.get() );
+
+ LogoutRequestType logoutRequest = parseBaseAttributes( startElement );
+
+ while( xmlEventReader.hasNext() )
+ {
+ //Let us peek at the next start element
+ startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( startElement == null )
+ break;
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+
+ parseCommonElements(startElement, xmlEventReader, logoutRequest );
+
+ if( JBossSAMLConstants.SESSION_INDEX.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ logoutRequest.getSessionIndex().add( StaxParserUtil.getElementText(
xmlEventReader ) );
+ }
+ }
+ return logoutRequest;
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ return PROTOCOL_NSURI.get().equals( qname.getNamespaceURI() )
+ && LOGOUT_REQUEST.equals( qname.getLocalPart() );
+ }
+
+ /**
+ * Parse the attributes at the log out request element
+ * @param startElement
+ * @return
+ * @throws ParsingException
+ */
+ private LogoutRequestType parseBaseAttributes( StartElement startElement ) throws
ParsingException
+ {
+ LogoutRequestType logoutRequest = new LogoutRequestType();
+ //Let us get the attributes
+ super.parseBaseAttributes(startElement, logoutRequest );
+
+ Attribute reason = startElement.getAttributeByName( new QName( "Reason"
));
+ if( reason != null )
+ logoutRequest.setReason( StaxParserUtil.getAttributeValue( reason ));
+
+ Attribute notOnOrAfter = startElement.getAttributeByName( new QName(
"NotOnOrAfter" ));
+ if( notOnOrAfter != null )
+ logoutRequest.setNotOnOrAfter( XMLTimeUtil.parse(
StaxParserUtil.getAttributeValue( notOnOrAfter )));
+ return logoutRequest;
+ }
+}
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloResponseParser.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -0,0 +1,111 @@
+/*
+ * 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 static
org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants.LOGOUT_RESPONSE;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
+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.protocol.ResponseType;
+
+/**
+ * Parse the SLO Response
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloResponseParser extends SAMLStatusResponseTypeParser implements
ParserNamespaceSupport
+{
+
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ //Get the startelement
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(startElement, LOGOUT_RESPONSE.get() );
+
+ ResponseType response = parseBaseAttributes(startElement);
+
+ while( xmlEventReader.hasNext() )
+ {
+ //Let us peek at the next start element
+ startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( startElement == null )
+ break;
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+
+ if( JBossSAMLConstants.ISSUER.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ NameIDType issuer = new NameIDType();
+ issuer.setValue( StaxParserUtil.getElementText( xmlEventReader ));
+ response.setIssuer( issuer );
+ }
+ else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StaxParserUtil.bypassElementBlock(xmlEventReader,
JBossSAMLConstants.SIGNATURE.get() );
+ }
+ else if( JBossSAMLConstants.ASSERTION.get().equals( elementName ))
+ {
+ SAMLAssertionParser assertionParser = new SAMLAssertionParser();
+ response.getAssertionOrEncryptedAssertion().add(
assertionParser.parse(xmlEventReader));
+ }
+ else if( JBossSAMLConstants.STATUS.get().equals( elementName ))
+ {
+ response.setStatus( parseStatus(xmlEventReader) );
+ }
+ }
+ return response;
+ }
+
+ /**
+ * Parse the attributes at the response element
+ * @param startElement
+ * @return
+ * @throws ConfigurationException
+ */
+ private ResponseType parseBaseAttributes( StartElement startElement ) throws
ParsingException
+ {
+ ResponseType response = new ResponseType();
+ super.parseBaseAttributes( startElement, response );
+
+ return response;
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ return JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( qname.getNamespaceURI()
)
+ && LOGOUT_RESPONSE.equals( qname.getLocalPart() );
+ }
+}
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java 2010-11-03
14:15:54 UTC (rev 519)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -22,13 +22,19 @@
package org.picketlink.identity.federation.core.parsers.saml;
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.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
/**
* Base Class for all Response Type parsing for SAML2
@@ -71,6 +77,73 @@
Attribute inResponseTo = startElement.getAttributeByName( new QName(
"InResponseTo" ));
if( inResponseTo != null )
response.setInResponseTo( StaxParserUtil.getAttributeValue( inResponseTo ));
- }
+ }
+
+ /**
+ * Parse the status element
+ * @param xmlEventReader
+ * @return
+ * @throws ParsingException
+ */
+ protected StatusType parseStatus( XMLEventReader xmlEventReader ) throws
ParsingException
+ {
+ //Get the Start Element
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ String STATUS = JBossSAMLConstants.STATUS.get();
+ StaxParserUtil.validate(startElement, STATUS );
+
+ StatusType status = new StatusType();
+
+ while( xmlEventReader.hasNext() )
+ {
+ startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+ if( startElement == null )
+ break;
+
+ QName startElementName = startElement.getName();
+ String elementTag = startElementName.getLocalPart();
+
+ StatusCodeType statusCode = new StatusCodeType();
+
+ if( JBossSAMLConstants.STATUS_CODE.get().equals( elementTag ))
+ {
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ if( startElement == null )
+ break;
+ Attribute valueAttr = startElement.getAttributeByName( new QName(
"Value" ));
+ if( valueAttr != null )
+ {
+ statusCode.setValue( StaxParserUtil.getAttributeValue( valueAttr ));
+ }
+ status.setStatusCode( statusCode );
+
+ //Peek at the next start element to see if it is status code
+ startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ if( JBossSAMLConstants.STATUS_CODE.get().equals(
startElement.getName().getLocalPart() ))
+ {
+ StatusCodeType subStatusCodeType = new StatusCodeType();
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ Attribute subValueAttr = startElement.getAttributeByName( new QName(
"Value" ));
+ if( subValueAttr != null )
+ {
+ subStatusCodeType.setValue( StaxParserUtil.getAttributeValue(
subValueAttr ));
+ }
+ statusCode.setStatusCode( subStatusCodeType );
+ }
+ else
+ break;
+ }
+
+ //Get the next end element
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if( xmlEvent instanceof EndElement )
+ {
+ EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
+ if( StaxParserUtil.matches(endElement, STATUS ))
+ break;
+ }
+ }
+ return status;
+ }
}
\ 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-11-03
14:15:54 UTC (rev 519)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -47,6 +47,8 @@
ISSUE_INSTANT( "IssueInstant" ),
ISSUER( "Issuer" ),
LANG_EN("en"),
+ LOGOUT_REQUEST( "LogoutRequest" ),
+ LOGOUT_RESPONSE( "LogoutResponse" ),
METADATA_MIME("application/samlmetadata+xml"),
METHOD( "Method" ),
NAMEID( "NameID" ),
@@ -55,6 +57,7 @@
NOT_BEFORE( "NotBefore" ),
NOT_ON_OR_AFTER( "NotOnOrAfter" ),
RESPONSE( "Response" ),
+ SESSION_INDEX( "SessionIndex" ),
SP_PROVIDED_ID( "SPProvidedID" ),
SP_NAME_QUALIFIER( "SPNameQualifier" ),
SIGNATURE( "Signature" ),
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-11-03
14:15:54 UTC (rev 519)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -28,10 +28,10 @@
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.core.saml.v2.util.XMLTimeUtil;
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;
@@ -47,9 +47,7 @@
{
@Test
public void testSAMLAssertionParsing() throws Exception
- {
- DatatypeFactory dtf = DatatypeFactory.newInstance();
-
+ {
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-assertion.xml" );
@@ -58,16 +56,14 @@
assertNotNull( assertion );
assertEquals( "ID_ab0392ef-b557-4453-95a8-a7e168da8ac5",
assertion.getID() );
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.869Z" ),
assertion.getIssueInstant() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.869Z" ),
assertion.getIssueInstant() );
//Issuer
assertEquals( "Test STS", assertion.getIssuer().getValue() );
//Subject
SubjectType subject = assertion.getSubject();
- List<JAXBElement<?>> content = subject.getContent();
+ List<JAXBElement<?>> content = subject.getContent();
-
-
int size = content.size();
for( int i = 0 ; i < size; i++ )
@@ -86,8 +82,8 @@
//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() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.869Z" ) ,
conditions.getNotBefore() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T21:13:37.869Z" ) ,
conditions.getNotOnOrAfter() );
}
}
@@ -100,9 +96,7 @@
*/
@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" );
@@ -111,7 +105,7 @@
assertNotNull( assertion );
assertEquals( "ID_cf9efbf0-9d7f-4b4a-b77f-d83ecaafd374",
assertion.getID() );
- assertEquals( dtf.newXMLGregorianCalendar( "2010-09-30T19:13:37.911Z" ),
assertion.getIssueInstant() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.911Z" ),
assertion.getIssueInstant() );
assertEquals( "2.0", assertion.getVersion() );
//Issuer
@@ -140,8 +134,8 @@
{
//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() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T19:13:37.911Z" ) ,
conditions.getNotBefore() );
+ assertEquals( XMLTimeUtil.parse( "2010-09-30T21:13:37.911Z" ) ,
conditions.getNotOnOrAfter() );
//Audience Restriction
AudienceRestrictionType audienceRestrictionType =
Added:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloRequestParserTestCase.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -0,0 +1,57 @@
+/*
+ * 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 org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.LogoutRequestType;
+
+/**
+ * Validate the parsing of SLO (log out) Request
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloRequestParserTestCase
+{
+ @Test
+ public void testSAMLLogOutRequestParsing() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-logout-request.xml" );
+
+ SAMLParser parser = new SAMLParser();
+ LogoutRequestType lotRequest = ( LogoutRequestType ) parser.parse(configStream);
+ assertNotNull( lotRequest );
+
+ assertEquals( "ID_c3b5ae86-7fea-4d8b-a438-a3f47d8e92c3",
lotRequest.getID() );
+ assertEquals( XMLTimeUtil.parse( "2010-07-29T13:46:20.647-05:00" ),
lotRequest.getIssueInstant() );
+ assertEquals( "2.0", lotRequest.getVersion() );
+ //Issuer
+ assertEquals( "http://localhost:8080/sales/",
lotRequest.getIssuer().getValue() );
+ }
+}
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLSloResponseParserTestCase.java 2010-11-03
17:41:54 UTC (rev 520)
@@ -0,0 +1,64 @@
+/*
+ * 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 org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
+
+/**
+ * Validate the parsing of SLO Response
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Nov 3, 2010
+ */
+public class SAMLSloResponseParserTestCase
+{
+ @Test
+ public void testSAMLResponseParse() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream(
"parser/saml2/saml2-logout-response.xml" );
+
+ SAMLParser parser = new SAMLParser();
+ ResponseType response = ( ResponseType ) parser.parse(configStream);
+ assertNotNull( "ResponseType is not null", response );
+
+ assertEquals( XMLTimeUtil.parse( "2010-07-29T13:46:03.862-05:00" ),
response.getIssueInstant() );
+ assertEquals( "2.0", response.getVersion() );
+ assertEquals( "ID_97d332a8-3224-4653-a1ff-65c966e56852", response.getID()
);
+
+ //Issuer
+ assertEquals( "http://localhost:8080/employee-post/",
response.getIssuer().getValue() );
+
+ //Status
+ StatusType status = response.getStatus();
+ assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Responder",
status.getStatusCode().getValue() );
+ assertEquals( "urn:oasis:names:tc:SAML:2.0:status:Success",
status.getStatusCode().getStatusCode().getValue() );
+ }
+}
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-request.xml 2010-11-03
17:41:54 UTC (rev 520)
@@ -0,0 +1,9 @@
+<ns3:LogoutRequest xmlns:ns3="urn:oasis:names:tc:SAML:2.0:protocol"
+ xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
+
xmlns:ns2="http://www.w3.org/2000/09/xmldsig#"
+
xmlns:ns4="http://www.w3.org/2001/04/xmlenc#"
+ ID="ID_c3b5ae86-7fea-4d8b-a438-a3f47d8e92c3"
+ IssueInstant="2010-07-29T13:46:20.647-05:00"
+ Version="2.0" >
+ <Issuer>http://localhost:8080/sales/</Issuer>
+</ns3:LogoutRequest>
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-logout-response.xml 2010-11-03
17:41:54 UTC (rev 520)
@@ -0,0 +1,15 @@
+<ns3:LogoutResponse xmlns:ns3="urn:oasis:names:tc:SAML:2.0:protocol"
+ xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
+
xmlns:ns2="http://www.w3.org/2000/09/xmldsig#"
+
xmlns:ns4="http://www.w3.org/2001/04/xmlenc#"
+ ID="ID_97d332a8-3224-4653-a1ff-65c966e56852"
+ InResponseTo="ID_230a1668-c2ab-47af-83f7-79613f9994d9"
+ IssueInstant="2010-07-29T13:46:03.862-05:00"
+ Version="2.0">
+ <Issuer>http://localhost:8080/employee-post/</Issuer>
+ <ns3:Status>
+ <ns3:StatusCode
Value="urn:oasis:names:tc:SAML:2.0:status:Responder">
+ <ns3:StatusCode
Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
+ </ns3:StatusCode>
+ </ns3:Status>
+</ns3:LogoutResponse>
\ No newline at end of file