[jboss-cvs] Picketlink SVN: r517 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 2 19:41:04 EDT 2010


Author: anil.saldhana at jboss.com
Date: 2010-11-02 19:41:04 -0400 (Tue, 02 Nov 2010)
New Revision: 517

Added:
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java
Modified:
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
Log:
PLFED-109: PLFED-110: add some base class

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java	2010-11-02 22:39:23 UTC (rev 516)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java	2010-11-02 23:41:04 UTC (rev 517)
@@ -31,7 +31,6 @@
 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.saml.v2.constants.JBossSAMLURIConstants;
-import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
 import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
 import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
 import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
@@ -41,7 +40,7 @@
  * @author Anil.Saldhana at redhat.com
  * @since Nov 2, 2010
  */
-public class SAMLAuthNRequestParser implements ParserNamespaceSupport
+public class SAMLAuthNRequestParser extends SAMLRequestAbstractParser implements ParserNamespaceSupport
 {
    /**
     * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
@@ -101,10 +100,7 @@
    { 
       AuthnRequestType authnRequest = new AuthnRequestType();
       //Let us get the attributes
-      Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
-      if( idAttr == null )
-         throw new RuntimeException( "ID attribute is missing" );
-      authnRequest.setID( StaxParserUtil.getAttributeValue( idAttr ));
+      super.parseBaseAttributes(startElement, authnRequest );
       
       Attribute assertionConsumerServiceURL = startElement.getAttributeByName( new QName( "AssertionConsumerServiceURL" ));
       if( assertionConsumerServiceURL != null )
@@ -114,15 +110,6 @@
       if( assertionConsumerServiceIndex != null )
          authnRequest.setAssertionConsumerServiceIndex( Integer.parseInt( StaxParserUtil.getAttributeValue( assertionConsumerServiceIndex )));
       
-      Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
-      if( destination != null )
-         authnRequest.setDestination( StaxParserUtil.getAttributeValue( destination ));
-      
-      Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
-      if( issueInstant == null )
-         throw new RuntimeException( "IssueInstant attribute required in AuthnRequest" ); 
-      authnRequest.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant )));  
-      
       Attribute protocolBinding = startElement.getAttributeByName( new QName( "ProtocolBinding" ));
       if( protocolBinding != null )
          authnRequest.setProtocolBinding( StaxParserUtil.getAttributeValue( protocolBinding ));
@@ -131,15 +118,6 @@
       if( providerName != null )
          authnRequest.setProviderName( StaxParserUtil.getAttributeValue( providerName ));
       
-      Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
-      if( consent != null )
-         authnRequest.setConsent( StaxParserUtil.getAttributeValue( consent ));
-      
-      Attribute version = startElement.getAttributeByName( new QName( "Version" ));
-      if( version == null )
-         throw new RuntimeException( "Version attribute required in AuthnRequest" );
-      authnRequest.setVersion( StaxParserUtil.getAttributeValue( version ));
-      
       Attribute forceAuthn = startElement.getAttributeByName( new QName( "ForceAuthn" ));
       if( forceAuthn != null )
       {

Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java	2010-11-02 23:41:04 UTC (rev 517)
@@ -0,0 +1,71 @@
+/*
+ * 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.saml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil; 
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.RequestAbstractType;
+
+/**
+ * Base Class for SAML Request Parsing
+ * @author Anil.Saldhana at redhat.com
+ * @since Nov 2, 2010
+ */
+public abstract class SAMLRequestAbstractParser
+{
+   /**
+    * Parse the attributes that are common to all SAML Request Types
+    * @param startElement
+    * @param request
+    * @throws ParsingException
+    */
+   protected void parseBaseAttributes(  StartElement startElement , RequestAbstractType request ) throws ParsingException
+   {
+      Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
+      if( idAttr == null )
+         throw new RuntimeException( "ID attribute is missing" );
+      request.setID( StaxParserUtil.getAttributeValue( idAttr )); 
+      
+      Attribute version = startElement.getAttributeByName( new QName( "Version" ));
+      if( version == null )
+         throw new RuntimeException( "Version attribute required in Request" );
+      request.setVersion( StaxParserUtil.getAttributeValue( version ));
+      
+      Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
+      if( issueInstant == null )
+         throw new RuntimeException( "IssueInstant attribute required in Request" ); 
+      request.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant ))); 
+      
+      Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
+      if( destination != null )
+         request.setDestination( StaxParserUtil.getAttributeValue( destination ));
+      
+      Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
+      if( consent != null )
+         request.setConsent( StaxParserUtil.getAttributeValue( consent )); 
+   } 
+}
\ No newline at end of file

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java	2010-11-02 22:39:23 UTC (rev 516)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLResponseParser.java	2010-11-02 23:41:04 UTC (rev 517)
@@ -34,7 +34,6 @@
 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.saml.v2.constants.JBossSAMLURIConstants;
-import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
 import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
 import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
 import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
@@ -45,7 +44,7 @@
  * @author Anil.Saldhana at redhat.com
  * @since Nov 2, 2010
  */
-public class SAMLResponseParser implements ParserNamespaceSupport
+public class SAMLResponseParser extends SAMLStatusResponseTypeParser implements ParserNamespaceSupport
 { 
    private String RESPONSE = JBossSAMLConstants.RESPONSE.get();
    /**
@@ -111,29 +110,8 @@
    private ResponseType parseBaseAttributes( StartElement startElement ) throws ParsingException
    { 
       ResponseType response = new ResponseType();
-      //Let us get the attributes
-      Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
-      if( idAttr == null )
-         throw new RuntimeException( "ID attribute is missing" );
-      response.setID( StaxParserUtil.getAttributeValue( idAttr ));
+      super.parseBaseAttributes( startElement, response ); 
       
-      Attribute inResponseTo = startElement.getAttributeByName( new QName( "InResponseTo" ));
-      if( inResponseTo != null )
-         response.setInResponseTo( StaxParserUtil.getAttributeValue( inResponseTo ));
-      
-      Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
-      if( destination != null )
-         response.setDestination( StaxParserUtil.getAttributeValue( destination ));
-      
-      Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
-      if( issueInstant != null )
-      {
-         response.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant ))); 
-      }
-      
-      Attribute version = startElement.getAttributeByName( new QName( "Version" ));
-      if( version != null )
-         response.setVersion( StaxParserUtil.getAttributeValue( version ));
       return response; 
    } 
    

Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLStatusResponseTypeParser.java	2010-11-02 23:41:04 UTC (rev 517)
@@ -0,0 +1,76 @@
+/*
+ * 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.saml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
+
+/**
+ * Base Class for all Response Type parsing for SAML2
+ * @author Anil.Saldhana at redhat.com
+ * @since Nov 2, 2010
+ */
+public abstract class SAMLStatusResponseTypeParser
+{
+   /**
+    * Parse the attributes that are common to all SAML Response Types
+    * @param startElement
+    * @param response
+    * @throws ParsingException
+    */
+   protected void parseBaseAttributes(  StartElement startElement , StatusResponseType response ) throws ParsingException
+   {
+      Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
+      if( idAttr == null )
+         throw new RuntimeException( "ID attribute is missing" );
+      response.setID( StaxParserUtil.getAttributeValue( idAttr )); 
+      
+      Attribute version = startElement.getAttributeByName( new QName( "Version" ));
+      if( version == null )
+         throw new RuntimeException( "Version attribute required in Response" );
+      response.setVersion( StaxParserUtil.getAttributeValue( version ));
+      
+      Attribute issueInstant = startElement.getAttributeByName( new QName( "IssueInstant" ));
+      if( issueInstant == null )
+         throw new RuntimeException( "IssueInstant attribute required in Response" ); 
+      response.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstant ))); 
+      
+      Attribute destination = startElement.getAttributeByName( new QName( "Destination" ));
+      if( destination != null )
+         response.setDestination( StaxParserUtil.getAttributeValue( destination ));
+      
+      Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
+      if( consent != null )
+         response.setConsent( StaxParserUtil.getAttributeValue( consent ));  
+      
+      Attribute inResponseTo = startElement.getAttributeByName( new QName( "InResponseTo" ));
+      if( inResponseTo != null )
+         response.setInResponseTo( StaxParserUtil.getAttributeValue( inResponseTo ));
+   } 
+
+}
\ No newline at end of file



More information about the jboss-cvs-commits mailing list