Author: anil.saldhana(a)jboss.com
Date: 2010-10-14 17:57:41 -0400 (Thu, 14 Oct 2010)
New Revision: 474
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/ParserController.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsp/
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsp/WSPolicyParser.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssueAppliesToTestCase.java
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: PLFED-110:
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/ParserController.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/ParserController.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/ParserController.java 2010-10-14
21:57:41 UTC (rev 474)
@@ -0,0 +1,120 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.parsers.wsa.WSAddressingParser;
+import org.picketlink.identity.federation.core.parsers.wsp.WSPolicyParser;
+import org.picketlink.identity.federation.core.parsers.wst.WSTrustParser;
+
+/**
+ * <p>
+ * A Controller that can act as the front door
+ * for parsing or when you need to locate a parser
+ * that is capable of parsing a {@code QName}
+ * <p>
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 14, 2010
+ */
+public class ParserController
+{
+ private static List<ParserNamespaceSupport> parsers = new
ArrayList<ParserNamespaceSupport>();
+
+ private static RuntimePermission PARSER_PERM = new RuntimePermission (
"org.picketlink.parser.permission" );
+
+
+ static
+ {
+ add( new SAMLParser() );
+ add( new WSTrustParser() );
+ add( new WSPolicyParser() );
+ add( new WSAddressingParser() );
+ };
+
+ /**
+ * <p>
+ * Add an {@code ParserNamespaceSupport} parser
+ * </p>
+ *
+ * <p>
+ * Under a Java security manager, the following run time permission is required.
+ * "org.picketlink.parser.permission"
+ * </p>
+ * @param parser
+ */
+ public static void add( ParserNamespaceSupport parser )
+ {
+ if( System.getSecurityManager() != null )
+ {
+ System.getSecurityManager().checkPermission( PARSER_PERM );
+ }
+
+ parsers.add( parser );
+ }
+
+ /**
+ * Get an {@code ParserNamespaceSupport} that supports parsing the qname
+ * @param qname
+ * @return A supporting parser or null
+ */
+ public static ParserNamespaceSupport get( QName qname )
+ {
+ int size = parsers.size();
+ if( size > 0 )
+ {
+ for( ParserNamespaceSupport parser : parsers )
+ {
+ if( parser.supports(qname) )
+ return parser;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * <p>
+ * Clear the registered parsers.
+ * <b>Note:</b> You really need to have a reason to perform this
operation.
+ * Once you have cleared the parsers, you have the opportunity to register
+ * new parsers with {@code #add(ParserNamespaceSupport)} call.
+ * </p>
+ *
+ * <p>
+ * Under a Java security manager, the following run time permission is required.
+ * "org.picketlink.parser.permission"
+ * </p>
+ */
+ public static void clearAll()
+ {
+ if( System.getSecurityManager() != null )
+ {
+ System.getSecurityManager().checkPermission( PARSER_PERM );
+ }
+
+ parsers.clear();
+ }
+}
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java 2010-10-14
21:57:41 UTC (rev 474)
@@ -0,0 +1,103 @@
+/*
+ * 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.wsa;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+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.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;
+import org.picketlink.identity.federation.ws.addressing.AttributedURIType;
+import org.picketlink.identity.federation.ws.addressing.EndpointReferenceType;
+import org.picketlink.identity.federation.ws.addressing.ObjectFactory;
+
+/**
+ * <p>
+ * Able to parse the WS-Addressing pieces in WS-T RST.
+ * <p>
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 14, 2010
+ */
+public class WSAddressingParser extends AbstractParser
+{
+ public static final String ENDPOINT_REFERENCE = "EndpointReference";
+ public static final String ADDRESS = "Address";
+
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = StaxParserUtil.peek( xmlEventReader );
+
+ if( xmlEvent instanceof StartElement )
+ {
+ StartElement startElement = (StartElement) xmlEvent;
+
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+ if( elementName.equalsIgnoreCase( ENDPOINT_REFERENCE ))
+ {
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StaxParserUtil.validate(startElement, ENDPOINT_REFERENCE );
+
+ //Lets get the wsa:Address
+ startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StaxParserUtil.validate(startElement, ADDRESS );
+
+ String endpointURI = StaxParserUtil.getElementText( xmlEventReader );
+
+ AttributedURIType attributedURI = new AttributedURIType();
+ attributedURI.setValue(endpointURI);
+ EndpointReferenceType reference = new EndpointReferenceType();
+ reference.setAddress(attributedURI);
+
+ //Lets get the end element
+ EndElement endElement = (EndElement)
StaxParserUtil.getNextEvent(xmlEventReader);
+ StaxParserUtil.validate( endElement, ENDPOINT_REFERENCE );
+
+ return new ObjectFactory().createEndpointReference( reference );
+ }
+ }
+ else
+ {
+ StaxParserUtil.getNextEvent(xmlEventReader);
+ }
+ }
+ throw new RuntimeException( "WSAddressing Parsing has failed" );
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ return WSTrustConstants.WSA_NS.equals( qname.getNamespaceURI() );
+ }
+}
\ No newline at end of file
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsp/WSPolicyParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsp/WSPolicyParser.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsp/WSPolicyParser.java 2010-10-14
21:57:41 UTC (rev 474)
@@ -0,0 +1,101 @@
+/*
+ * 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.wsp;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+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.ParserController;
+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.ws.policy.AppliesTo;
+
+/**
+ * <p>
+ * Parses the WS-Policy elements that can be part
+ * of the WS-T RST
+ * </p>
+ *
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 14, 2010
+ */
+public class WSPolicyParser extends AbstractParser
+{
+ public static final String APPLIES_TO = "AppliesTo";
+
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = StaxParserUtil.peek( xmlEventReader );
+
+ if( xmlEvent instanceof StartElement )
+ {
+ StartElement startElement = (StartElement) xmlEvent;
+
+ String elementName = StaxParserUtil.getStartElementName( startElement );
+ if( elementName.equalsIgnoreCase( APPLIES_TO ))
+ {
+ //Get the AppliesTo element
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+
+ AppliesTo appliesTo = new AppliesTo();
+
+ //Now we do not do anything to the applies to element. We go further
+ startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+
+ QName qname = startElement.getName();
+ ParserNamespaceSupport parser = ParserController.get( qname );
+ if( parser == null )
+ throw new RuntimeException( "Unable to parse:" + qname );
+
+ Object parsedObject = parser.parse( xmlEventReader );
+ appliesTo.getAny().add( parsedObject );
+ return appliesTo;
+ }
+ }
+ else
+ {
+ StaxParserUtil.getNextEvent(xmlEventReader);
+ }
+ }
+ throw new RuntimeException( "WSPolicy Parsing has failed" );
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ String nsURI = qname.getNamespaceURI();
+
+ return WSTrustConstants.WSP_NS.equals( nsURI );
+ }
+}
\ 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
20:42:04 UTC (rev 473)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-14
21:57:41 UTC (rev 474)
@@ -32,10 +32,12 @@
import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserController;
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;
+import org.picketlink.identity.federation.ws.policy.AppliesTo;
import org.picketlink.identity.federation.ws.trust.CancelTargetType;
import org.picketlink.identity.federation.ws.trust.ValidateTargetType;
@@ -76,23 +78,29 @@
try
{
- StartElement subEvent = StaxParserUtil.getNextStartElement( xmlEventReader
);
+ StartElement subEvent = StaxParserUtil.peekNextStartElement( xmlEventReader
);
if( subEvent == null )
break;
String tag = StaxParserUtil.getStartElementName( subEvent );
if( tag.equals( WSTrustConstants.REQUEST_TYPE ))
{
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+
String value = StaxParserUtil.getElementText(xmlEventReader);
requestToken.setRequestType( new URI( value ));
}
else if( tag.equals( WSTrustConstants.TOKEN_TYPE ))
{
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+
String value = StaxParserUtil.getElementText(xmlEventReader);
requestToken.setTokenType( new URI( value ));
}
else if( tag.equals( WSTrustConstants.CANCEL_TARGET ))
{
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(subEvent, WSTrustConstants.CANCEL_TARGET );
WSTCancelTargetParser wstCancelTargetParser = new
WSTCancelTargetParser();
CancelTargetType cancelTarget = (CancelTargetType)
wstCancelTargetParser.parse( xmlEventReader );
requestToken.setCancelTarget( cancelTarget );
@@ -101,12 +109,27 @@
}
else if( tag.equals( WSTrustConstants.VALIDATE_TARGET ))
{
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+
WSTValidateTargetParser wstValidateTargetParser = new
WSTValidateTargetParser();
ValidateTargetType validateTarget = (ValidateTargetType)
wstValidateTargetParser.parse( xmlEventReader );
requestToken.setValidateTarget( validateTarget );
EndElement validateTargetEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
StaxParserUtil.validate( validateTargetEndElement,
WSTrustConstants.VALIDATE_TARGET ) ;
}
+ else
+ {
+ QName qname = subEvent.getName();
+ ParserNamespaceSupport parser = ParserController.get( qname );
+ if( parser == null )
+ throw new RuntimeException( "Cannot parse " + qname );
+
+ Object parsedObject = parser.parse( xmlEventReader );
+ if( parsedObject instanceof AppliesTo )
+ {
+ requestToken.setAppliesTo( (AppliesTo) parsedObject );
+ }
+ }
}
catch (URISyntaxException e)
{
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
20:42:04 UTC (rev 473)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-14
21:57:41 UTC (rev 474)
@@ -63,6 +63,7 @@
// WSS namespaces values.
public static final String WSA_NS = "http://www.w3.org/2005/08/addressing";
+ public static final String WSP_NS =
"http://schemas.xmlsoap.org/ws/2004/09/policy";
public static final String WSU_NS =
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
public static final String WSSE_NS =
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
public static final String WSSE11_NS =
"http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd";
Added:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssueAppliesToTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssueAppliesToTestCase.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssueAppliesToTestCase.java 2010-10-14
21:57:41 UTC (rev 474)
@@ -0,0 +1,62 @@
+/*
+ * 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 java.io.InputStream;
+
+import javax.xml.bind.JAXBElement;
+
+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.ws.addressing.EndpointReferenceType;
+import org.picketlink.identity.federation.ws.policy.AppliesTo;
+
+/**
+ * Validate the wst applies to parsing
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 14, 2010
+ */
+public class WSTrustIssueAppliesToTestCase
+{
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testAppliesTo() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream(
"parser/wst/wst-issue-appliesto.xml" );
+
+ WSTrustParser parser = new WSTrustParser();
+ RequestSecurityToken requestToken = ( RequestSecurityToken ) parser.parse(
configStream );
+
+ assertEquals( "testcontext", requestToken.getContext() );
+ assertEquals( WSTrustConstants.ISSUE_REQUEST ,
requestToken.getRequestType().toASCIIString() );
+
+ AppliesTo appliesTo = requestToken.getAppliesTo();
+ JAXBElement<EndpointReferenceType> jaxb =
(JAXBElement<EndpointReferenceType>) appliesTo.getAny().get(0);
+ EndpointReferenceType endpoint = jaxb.getValue();
+ assertEquals( "http://services.testcorp.org/provider2",
endpoint.getAddress().getValue() );
+ }
+}
\ No newline at end of file