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() ); */
+ }
+
+}