[jboss-cvs] Picketlink SVN: r493 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/parsers/wst and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 18 18:42:06 EDT 2010


Author: anil.saldhana at jboss.com
Date: 2010-10-18 18:42:05 -0400 (Mon, 18 Oct 2010)
New Revision: 493

Added:
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRenewTargetParser.java
   federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustRenewTargetParsingTestCase.java
Modified:
   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/wst/WSTRequestSecurityTokenParser.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java
Log:
PLFED-109: parse renew target

Modified: 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	2010-10-18 22:30:10 UTC (rev 492)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/ParserController.java	2010-10-18 22:42:05 UTC (rev 493)
@@ -31,6 +31,7 @@
 import org.picketlink.identity.federation.core.parsers.wsp.WSPolicyParser;
 import org.picketlink.identity.federation.core.parsers.wsse.WSSecurityParser;
 import org.picketlink.identity.federation.core.parsers.wst.WSTCancelTargetParser;
+import org.picketlink.identity.federation.core.parsers.wst.WSTRenewTargetParser;
 import org.picketlink.identity.federation.core.parsers.wst.WSTRequestSecurityTokenCollectionParser;
 import org.picketlink.identity.federation.core.parsers.wst.WSTRequestSecurityTokenParser;
 import org.picketlink.identity.federation.core.parsers.wst.WSTValidateTargetParser;
@@ -66,6 +67,7 @@
       
       add( new WSTrustOnBehalfOfParser() );
       add( new WSTValidateTargetParser() );
+      add( new WSTRenewTargetParser() );
       add( new WSTCancelTargetParser() );
       add( new WSTRequestSecurityTokenParser() );
       add( new WSTRequestSecurityTokenCollectionParser() ); 

Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRenewTargetParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRenewTargetParser.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRenewTargetParser.java	2010-10-18 22:42:05 UTC (rev 493)
@@ -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.saml.SAMLParser;
+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.wstrust.WSTrustConstants;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.ws.trust.RenewTargetType;
+
+/**
+ * Stax parser for the wst:RenewTarget element
+ * @author Anil.Saldhana at redhat.com
+ * @since Oct 13, 2010
+ */
+public class WSTRenewTargetParser implements ParserNamespaceSupport
+{
+   /**
+    * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+    */
+   public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+   {  
+      RenewTargetType renewTargetType = new RenewTargetType();
+      
+      StartElement startElement =  StaxParserUtil.peekNextStartElement( xmlEventReader ); 
+      String tag = StaxParserUtil.getStartElementName( startElement );
+      
+      if( tag.equals( JBossSAMLConstants.ASSERTION.get() ) )
+      {
+         SAMLParser assertionParser = new SAMLParser();
+         AssertionType assertion = (AssertionType) assertionParser.parse( xmlEventReader );
+         renewTargetType.setAny( assertion );
+      }
+      
+      return renewTargetType;
+   }
+
+   /**
+    * @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.RENEW_TARGET.equals( localPart );
+   } 
+}
\ 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-18 22:30:10 UTC (rev 492)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java	2010-10-18 22:42:05 UTC (rev 493)
@@ -47,6 +47,7 @@
 import org.picketlink.identity.federation.ws.trust.CancelTargetType;
 import org.picketlink.identity.federation.ws.trust.EntropyType;
 import org.picketlink.identity.federation.ws.trust.OnBehalfOfType;
+import org.picketlink.identity.federation.ws.trust.RenewTargetType;
 import org.picketlink.identity.federation.ws.trust.UseKeyType;
 import org.picketlink.identity.federation.ws.trust.ValidateTargetType;
 import org.w3c.dom.Element;
@@ -129,7 +130,17 @@
                requestToken.setValidateTarget( validateTarget ); 
                EndElement validateTargetEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
                StaxParserUtil.validate( validateTargetEndElement, WSTrustConstants.VALIDATE_TARGET ) ;
-            }  
+            } 
+            else if( tag.equals( WSTrustConstants.RENEW_TARGET ))
+            {
+               subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+               
+               WSTRenewTargetParser wstValidateTargetParser = new WSTRenewTargetParser();
+               RenewTargetType validateTarget = (RenewTargetType) wstValidateTargetParser.parse( xmlEventReader );
+               requestToken.setRenewTarget( validateTarget ); 
+               EndElement validateTargetEndElement = StaxParserUtil.getNextEndElement(xmlEventReader);
+               StaxParserUtil.validate( validateTargetEndElement, WSTrustConstants.RENEW_TARGET ) ;
+            } 
             else if( tag.equals( WSTrustConstants.On_BEHALF_OF ))
             {
                subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);

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-18 22:30:10 UTC (rev 492)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/WSTrustConstants.java	2010-10-18 22:42:05 UTC (rev 493)
@@ -92,6 +92,7 @@
    public static final String REQUEST_TYPE = "RequestType";
    public static final String TOKEN_TYPE = "TokenType";
    public static final String CANCEL_TARGET = "CancelTarget";
+   public static final String RENEW_TARGET = "RenewTarget";
    public static final String VALIDATE_TARGET = "ValidateTarget";
    public static final String USE_KEY = "UseKey";
    

Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustRenewTargetParsingTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustRenewTargetParsingTestCase.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustRenewTargetParsingTestCase.java	2010-10-18 22:42:05 UTC (rev 493)
@@ -0,0 +1,69 @@
+/*
+ * 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.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
+import org.picketlink.identity.federation.ws.trust.RenewTargetType;
+
+/**
+ * Validate the parsing of wst-batch-validate.xml
+ * @author Anil.Saldhana at redhat.com
+ * @since Oct 12, 2010
+ */
+public class WSTrustRenewTargetParsingTestCase
+{
+   @Test 
+   public void testWST_RenewTarget() throws Exception
+   {
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      InputStream configStream = tcl.getResourceAsStream( "parser/wst/wst-renew-saml.xml" );
+      
+      WSTrustParser parser = new WSTrustParser();
+      RequestSecurityToken requestToken = (RequestSecurityToken) parser.parse( configStream );  
+      assertEquals( "renewcontext", requestToken.getContext() );
+      assertEquals( WSTrustConstants.RENEW_REQUEST , requestToken.getRequestType().toASCIIString() );
+      assertEquals( WSTrustConstants.SAML2_TOKEN_TYPE , requestToken.getTokenType().toASCIIString() ); 
+      
+      RenewTargetType renewTarget = requestToken.getRenewTarget();
+      AssertionType assertion = (AssertionType) renewTarget.getAny();
+      assertEquals( "ID_654b6092-c725-40ea-8044-de453b59cb28", assertion.getID() );
+      assertEquals( "Test STS", assertion.getIssuer().getValue() );
+      SubjectType subject = assertion.getSubject();
+      
+      @SuppressWarnings("unchecked")
+      JAXBElement<NameIDType> nameID = (JAXBElement<NameIDType>) subject.getContent().get(0);
+      assertEquals( "jduke", nameID.getValue().getValue());
+      
+   } 
+}
\ No newline at end of file



More information about the jboss-cvs-commits mailing list