Author: anil.saldhana(a)jboss.com
Date: 2010-10-18 13:10:59 -0400 (Mon, 18 Oct 2010)
New Revision: 485
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/WSSecurityParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustOnBehalfOfParser.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustOnBehalfOfTestCase.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/wsse/WSSecurityParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/WSSecurityParser.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/WSSecurityParser.java 2010-10-18
17:10:59 UTC (rev 485)
@@ -0,0 +1,114 @@
+/*
+ * 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.wsse;
+
+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.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.wss.secext.AttributedString;
+import org.picketlink.identity.federation.ws.wss.secext.UsernameTokenType;
+
+/**
+ * <p>
+ * Parses the WS-Security elements that can be part
+ * of the WS-T RST
+ * </p>
+ *
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 14, 2010
+ */
+public class WSSecurityParser extends AbstractParser
+{
+ public static final String USERNAME_TOKEN = "UsernameToken";
+
+ /**
+ * @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( USERNAME_TOKEN ))
+ {
+ //Get the AppliesTo element
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+
+ UsernameTokenType userNameToken = new UsernameTokenType();
+
+ //Get the Id attribute
+ QName idQName = new QName( WSTrustConstants.WSU_NS, "Id" );
+ Attribute idAttribute = startElement.getAttributeByName( idQName );
+
+ if( idAttribute == null )
+ throw new RuntimeException( "missing wsu:Id attribute" );
+
+ userNameToken.setId( StaxParserUtil.getAttributeValue( idAttribute ));
+
+ startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ String userName = StaxParserUtil.getElementText(xmlEventReader);
+
+ AttributedString attributedString = new AttributedString();
+ attributedString.setValue(userName);
+
+ userNameToken.setUsername( attributedString );
+
+ //Get the end element
+ EndElement onBehalfOfEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
+ StaxParserUtil.validate( onBehalfOfEndElement, USERNAME_TOKEN ) ;
+
+ return userNameToken;
+ }
+ }
+ else
+ {
+ StaxParserUtil.getNextEvent(xmlEventReader);
+ }
+ }
+ throw new RuntimeException( "WSSecurity Parsing has failed" );
+ }
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ String nsURI = qname.getNamespaceURI();
+
+ return WSTrustConstants.WSSE_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-15
17:13:07 UTC (rev 484)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-18
17:10:59 UTC (rev 485)
@@ -39,6 +39,7 @@
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.OnBehalfOfType;
import org.picketlink.identity.federation.ws.trust.ValidateTargetType;
/**
@@ -117,6 +118,16 @@
EndElement validateTargetEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
StaxParserUtil.validate( validateTargetEndElement,
WSTrustConstants.VALIDATE_TARGET ) ;
}
+ else if( tag.equals( WSTrustConstants.On_BEHALF_OF ))
+ {
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+
+ WSTrustOnBehalfOfParser wstOnBehalfOfParser = new
WSTrustOnBehalfOfParser();
+ OnBehalfOfType onBehalfOf = (OnBehalfOfType)
wstOnBehalfOfParser.parse(xmlEventReader);
+ requestToken.setOnBehalfOf(onBehalfOf);
+ EndElement onBehalfOfEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
+ StaxParserUtil.validate( onBehalfOfEndElement,
WSTrustConstants.On_BEHALF_OF ) ;
+ }
else
{
QName qname = subEvent.getName();
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustOnBehalfOfParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustOnBehalfOfParser.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTrustOnBehalfOfParser.java 2010-10-18
17:10:59 UTC (rev 485)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.parsers.wst;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.parsers.wsse.WSSecurityParser;
+import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
+import org.picketlink.identity.federation.ws.trust.OnBehalfOfType;
+import org.picketlink.identity.federation.ws.wss.secext.UsernameTokenType;
+
+/**
+ * Parser to parse the OnBehalfOf tag
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 18, 2010
+ */
+public class WSTrustOnBehalfOfParser implements ParserNamespaceSupport
+{
+ /**
+ * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+ */
+ public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+ {
+ OnBehalfOfType onBehalfType = new OnBehalfOfType();
+ StartElement startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ String tag = StaxParserUtil.getStartElementName( startElement );
+
+ if( tag.equals( WSSecurityParser.USERNAME_TOKEN ) )
+ {
+ WSSecurityParser wsseParser = new WSSecurityParser();
+
+ UsernameTokenType userNameToken = (UsernameTokenType) wsseParser.parse(
xmlEventReader );
+ onBehalfType.setAny( userNameToken );
+ }
+
+ return onBehalfType;
+ }
+
+
+ /**
+ * @see {@link ParserNamespaceSupport#supports(QName)}
+ */
+ public boolean supports(QName qname)
+ {
+ String nsURI = qname.getNamespaceURI();
+ String localPart = qname.getLocalPart();
+
+ return WSTrustConstants.BASE_NAMESPACE.equals( nsURI )
+ && WSTrustConstants.On_BEHALF_OF.equals( localPart );
+ }
+}
\ No newline at end of file
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-15
17:13:07 UTC (rev 484)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java 2010-10-18
17:10:59 UTC (rev 485)
@@ -82,6 +82,7 @@
public static final String RSTR_STATUS_TOKEN_TYPE =
"http://docs.oasis-open.org/ws-sx/ws-trust/200512/RSTR/Status";
//Element Names
+ public static final String On_BEHALF_OF = "OnBehalfOf";
public static final String RST = "RequestSecurityToken";
public static final String RST_COLLECTION =
"RequestSecurityTokenCollection";
public static final String REQUEST_TYPE = "RequestType";
Added:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustOnBehalfOfTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustOnBehalfOfTestCase.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustOnBehalfOfTestCase.java 2010-10-18
17:10:59 UTC (rev 485)
@@ -0,0 +1,59 @@
+/*
+ * 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 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.trust.OnBehalfOfType;
+import org.picketlink.identity.federation.ws.wss.secext.UsernameTokenType;
+
+/**
+ * Validate the OnBehalfOf parsing
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 18, 2010
+ */
+public class WSTrustOnBehalfOfTestCase
+{
+ @Test
+ public void testOnBehalfOfParsing() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream configStream = tcl.getResourceAsStream(
"parser/wst/wst-issue-onbehalfof.xml" );
+
+ WSTrustParser parser = new WSTrustParser();
+ RequestSecurityToken requestToken = ( RequestSecurityToken ) parser.parse(
configStream );
+
+ assertEquals( "testcontext", requestToken.getContext() );
+ assertEquals( WSTrustConstants.ISSUE_REQUEST ,
requestToken.getRequestType().toASCIIString() );
+
+ OnBehalfOfType onBehalfOf = requestToken.getOnBehalfOf();
+ UsernameTokenType userNameToken = (UsernameTokenType) onBehalfOf.getAny();
+ assertEquals( "id", userNameToken.getId() );
+ assertEquals( "anotherduke", userNameToken.getUsername().getValue() );
+ }
+}
\ No newline at end of file