[jboss-cvs] Picketlink SVN: r489 - in federation/trunk/picketlink-fed-core/src: test/java/org/picketlink/test/identity/federation/core/parser/wst and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 18 18:10:22 EDT 2010


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

Added:
   federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssuePublicKeyTestCase.java
Modified:
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
Log:
PLFED-109: parse the rsa pub key as part of RST use key

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 21:47:33 UTC (rev 488)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java	2010-10-18 22:10:21 UTC (rev 489)
@@ -57,6 +57,7 @@
 public class WSTRequestSecurityTokenParser implements ParserNamespaceSupport
 {  
    public static final String X509CERTIFICATE = "X509Certificate";
+   public static final String KEYVALUE = "KeyValue";
    
    /**
     * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
@@ -161,12 +162,21 @@
                 * There has to be a better way of parsing a sub section into a DOM element
                 */
                subEvent = StaxParserUtil.getNextStartElement(xmlEventReader); 
-               StaxParserUtil.validate( subEvent, X509CERTIFICATE ) ;
-               
-               Element domElement = getX509CertificateAsDomElement( subEvent, xmlEventReader );
+               if( StaxParserUtil.matches(subEvent, X509CERTIFICATE ))
+               {
+                  Element domElement = getX509CertificateAsDomElement( subEvent, xmlEventReader );
 
-               useKeyType.setAny( domElement );
-               requestToken.setUseKey( useKeyType ); 
+                  useKeyType.setAny( domElement );
+                  requestToken.setUseKey( useKeyType );   
+               } 
+               else if( StaxParserUtil.matches(subEvent, KEYVALUE ))
+               {
+                  Element domElement = getKeyValueAsDomElement( subEvent, xmlEventReader );
+
+                  useKeyType.setAny( domElement );
+                  requestToken.setUseKey( useKeyType );   
+               }
+               else throw new RuntimeException( "unsupported " + StaxParserUtil.getStartElementName( subEvent )); 
             }  
             else
             {
@@ -255,4 +265,86 @@
       
       return domElement;
    }
+   
+   
+   private Element getKeyValueAsDomElement( StartElement subEvent, XMLEventReader xmlEventReader  ) throws ParsingException
+   {
+      StringBuilder builder = new StringBuilder();
+      
+      QName subEventName = subEvent.getName();
+      String prefix = subEventName.getPrefix();
+      String localPart = subEventName.getLocalPart();
+      
+      //ds:KeyValue
+      builder.append( "<" ).append(  prefix ).append( ":").append( localPart );
+      
+      @SuppressWarnings("unchecked")
+      Iterator<Attribute> iter = subEvent.getAttributes();
+      
+      while( iter != null && iter.hasNext() )
+      {
+         Attribute attr = iter.next();
+         QName attrName = attr.getName();
+         if( attrName.getNamespaceURI().equals( WSTrustConstants.DSIG_NS ) )
+         {
+            builder.append( " ").append( prefix ).append( ":" ).append( attrName.getLocalPart() );
+            builder.append( "=" ).append( StaxParserUtil.getAttributeValue( attr )); 
+         }
+      }
+      
+      @SuppressWarnings("unchecked")
+      Iterator<Namespace> namespaces = subEvent.getNamespaces();
+      while( namespaces != null && namespaces.hasNext() )
+      {
+         Namespace namespace = namespaces.next();
+         builder.append( " ").append( namespace.toString() ); 
+      }
+      builder.append( ">" );
+      subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+      StaxParserUtil.validate( subEvent, "RSAKeyValue" );
+      builder.append( "<") .append( prefix) .append( ":" ).append( "RSAKeyValue>" );
+      
+      subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+      StaxParserUtil.validate( subEvent, "Modulus" );
+      builder.append( "<") .append( prefix) .append( ":" ).append( "Modulus>" );
+      
+      builder.append( StaxParserUtil.getElementText(xmlEventReader) ); //We are at the end of tag
+      
+      builder.append( "</" ).append( prefix ).append( ":" ).append( "Modulus" ).append( ">" );
+      
+
+      subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+      StaxParserUtil.validate( subEvent, "Exponent" );
+
+      builder.append( "<") .append( prefix) .append( ":" ).append( "Exponent>" );
+      
+      builder.append( StaxParserUtil.getElementText(xmlEventReader) ); //We are at the end of tag
+      
+      builder.append( "</" ).append( prefix ).append( ":" ).append( "Exponent" ).append( ">" );
+      
+      EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
+      StaxParserUtil.validate(endElement, "RSAKeyValue" );
+      builder.append( "</" ).append( prefix ).append( ":" ).append( "RSAKeyValue" ).append( ">" );
+      
+      endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
+      StaxParserUtil.validate(endElement, KEYVALUE );
+      builder.append( "</" ).append( prefix ).append( ":" ).append( KEYVALUE ).append( ">" );
+      
+      
+      Element domElement = null;
+      try
+      {
+         domElement = DocumentUtil.getDocument( builder.toString() ).getDocumentElement() ;
+      }
+      catch (ConfigurationException e)
+      {
+         throw new ParsingException( e );
+      }
+      catch (ProcessingException e)
+      {
+         throw new ParsingException( e );
+      }
+      
+      return domElement; 
+   }
 }
\ No newline at end of file

Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssuePublicKeyTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssuePublicKeyTestCase.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/wst/WSTrustIssuePublicKeyTestCase.java	2010-10-18 22:10:21 UTC (rev 489)
@@ -0,0 +1,74 @@
+/*
+ * 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.WSTRequestSecurityTokenParser;
+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;
+import org.picketlink.identity.federation.ws.trust.UseKeyType;
+import org.w3c.dom.Element;
+
+/**
+ * Validate parsing of RST with Use Key set to a X509 certificate
+ * @author Anil.Saldhana at redhat.com
+ * @since Oct 18, 2010
+ */
+public class WSTrustIssuePublicKeyTestCase
+{
+
+   @SuppressWarnings("unchecked")
+   @Test
+   public void testPublicKey() throws Exception
+   {
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      InputStream configStream = tcl.getResourceAsStream( "parser/wst/wst-issue-public-key.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() );
+      
+      
+      assertEquals( "http://docs.oasis-open.org/ws-sx/ws-trust/200512/PublicKey", requestToken.getKeyType().toASCIIString() );
+      
+      UseKeyType useKeyType = requestToken.getUseKey();
+      Element certEl = (Element) useKeyType.getAny(); 
+      
+      assertEquals( "ds:" + WSTRequestSecurityTokenParser.KEYVALUE, certEl.getTagName() );
+   }
+}
\ No newline at end of file



More information about the jboss-cvs-commits mailing list