[jboss-cvs] Picketlink SVN: r1057 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v2/constants and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 1 17:44:58 EDT 2011


Author: anil.saldhana at jboss.com
Date: 2011-07-01 17:44:58 -0400 (Fri, 01 Jul 2011)
New Revision: 1057

Added:
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLArtifactResponseParser.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAttributeQueryParser.java
   federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAttributeQueryParserTestCase.java
   federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-attributequery.xml
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/SAMLParser.java
   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/saml/v2/constants/JBossSAMLConstants.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
Log:
PLFED-117: parse and write saml attribute query

Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLArtifactResponseParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLArtifactResponseParser.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLArtifactResponseParser.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -0,0 +1,124 @@
+/*
+ * 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.XMLEventReader;
+import javax.xml.stream.events.StartElement;
+
+import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
+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.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.protocol.ArtifactResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
+import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
+import org.w3c.dom.Element;
+
+/**
+ * Parse the SAML Response
+ * @author Anil.Saldhana at redhat.com
+ * @since July 1, 2011
+ */
+public class SAMLArtifactResponseParser extends SAMLStatusResponseTypeParser implements ParserNamespaceSupport
+{
+   private final String ARTIFACT_RESPONSE = JBossSAMLConstants.ARTIFACT_RESPONSE.get();
+
+   /**
+    * @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
+    */
+   public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+   {
+      //Get the startelement
+      StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+      StaxParserUtil.validate(startElement, ARTIFACT_RESPONSE);
+
+      ArtifactResponseType response = (ArtifactResponseType) parseBaseAttributes(startElement);
+
+      while (xmlEventReader.hasNext())
+      {
+         //Let us peek at the next start element
+         startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+         if (startElement == null)
+            break;
+         String elementName = StaxParserUtil.getStartElementName(startElement);
+
+         if (JBossSAMLConstants.ISSUER.get().equals(elementName))
+         {
+            startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+            NameIDType issuer = new NameIDType();
+            issuer.setValue(StaxParserUtil.getElementText(xmlEventReader));
+            response.setIssuer(issuer);
+         }
+         else if (JBossSAMLConstants.SIGNATURE.get().equals(elementName))
+         {
+            Element sig = StaxParserUtil.getDOMElement(xmlEventReader);
+            response.setSignature(sig);
+         }
+         else if (JBossSAMLConstants.AUTHN_REQUEST.get().equals(elementName))
+         {
+            SAMLAuthNRequestParser authnParser = new SAMLAuthNRequestParser();
+            AuthnRequestType authn = (AuthnRequestType) authnParser.parse(xmlEventReader);
+            response.setAny(authn);
+         }
+         else if (JBossSAMLConstants.RESPONSE.get().equals(elementName))
+         {
+            SAMLResponseParser authnParser = new SAMLResponseParser();
+            ResponseType authn = (ResponseType) authnParser.parse(xmlEventReader);
+            response.setAny(authn);
+         }
+         else if (JBossSAMLConstants.STATUS.get().equals(elementName))
+         {
+            response.setStatus(parseStatus(xmlEventReader));
+         }
+         else
+            throw new RuntimeException("Unknown tag=" + elementName + "::location=" + startElement.getLocation());
+      }
+
+      return response;
+   }
+
+   /**
+    * @see {@link ParserNamespaceSupport#supports(QName)}
+    */
+   public boolean supports(QName qname)
+   {
+      return JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals(qname.getNamespaceURI())
+            && ARTIFACT_RESPONSE.equals(qname.getLocalPart());
+   }
+
+   /**
+    * Parse the attributes at the response element
+    * @param startElement
+    * @return
+    * @throws ConfigurationException
+    */
+   protected StatusResponseType parseBaseAttributes(StartElement startElement) throws ParsingException
+   {
+      ArtifactResponseType response = new ArtifactResponseType(super.parseBaseAttributes(startElement));
+      return response;
+   }
+}
\ No newline at end of file

Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAttributeQueryParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAttributeQueryParser.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAttributeQueryParser.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -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.saml;
+
+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.SAMLParserUtil;
+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.saml.v2.protocol.ArtifactResolveType;
+import org.picketlink.identity.federation.saml.v2.protocol.AttributeQueryType;
+
+/**
+ * Parse the {@link ArtifactResolveType}
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 1, 2011
+ */
+public class SAMLAttributeQueryParser extends SAMLRequestAbstractParser implements ParserNamespaceSupport
+{
+   public Object parse(XMLEventReader xmlEventReader) throws ParsingException
+   {
+      //Get the startelement
+      StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+      StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE_QUERY.get());
+
+      AttributeQueryType attributeQuery = parseBaseAttributes(startElement);
+
+      while (xmlEventReader.hasNext())
+      {
+         //Let us peek at the next start element
+         startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
+         if (startElement == null)
+            break;
+         super.parseCommonElements(startElement, xmlEventReader, attributeQuery);
+         String elementName = StaxParserUtil.getStartElementName(startElement);
+
+         if (JBossSAMLConstants.SUBJECT.get().equals(elementName))
+         {
+            attributeQuery.setSubject(getSubject(xmlEventReader));
+         }
+         else if (JBossSAMLConstants.ATTRIBUTE.get().equals(elementName))
+         {
+            attributeQuery.add(SAMLParserUtil.parseAttribute(xmlEventReader));
+         }
+         else if (JBossSAMLConstants.ISSUER.get().equals(elementName))
+         {
+            continue;
+         }
+         else if (JBossSAMLConstants.SIGNATURE.get().equals(elementName))
+         {
+            continue;
+         }
+         else
+            throw new RuntimeException("Unknown Element:" + elementName + "::location=" + startElement.getLocation());
+      }
+      return attributeQuery;
+   }
+
+   public boolean supports(QName qname)
+   {
+      return JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals(qname.getNamespaceURI());
+   }
+
+   /**
+    * Parse the attributes at the authnrequesttype element
+    * @param startElement
+    * @return 
+    * @throws ParsingException 
+    */
+   private AttributeQueryType parseBaseAttributes(StartElement startElement) throws ParsingException
+   {
+      super.parseRequiredAttributes(startElement);
+      AttributeQueryType authnRequest = new AttributeQueryType(id, issueInstant);
+      //Let us get the attributes
+      super.parseBaseAttributes(startElement, authnRequest);
+
+      return authnRequest;
+   }
+}
\ No newline at end of file

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	2011-07-01 20:57:08 UTC (rev 1056)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -34,7 +34,6 @@
 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.saml.v2.assertion.ConditionsType;
-import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
 import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
 import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
 import org.picketlink.identity.federation.saml.v2.protocol.RequestedAuthnContextType;
@@ -180,12 +179,6 @@
       return nameIDPolicy;
    }
 
-   private SubjectType getSubject(XMLEventReader xmlEventReader) throws ParsingException
-   {
-      SAMLSubjectParser subjectParser = new SAMLSubjectParser();
-      return (SubjectType) subjectParser.parse(xmlEventReader);
-   }
-
    private RequestedAuthnContextType getRequestedAuthnContextType(XMLEventReader xmlEventReader)
          throws ParsingException
    {

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java	2011-07-01 20:57:08 UTC (rev 1056)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -121,6 +121,12 @@
                SAMLArtifactResponseParser responseParser = new SAMLArtifactResponseParser();
                return responseParser.parse(xmlEventReader);
             }
+            else if (JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals(nsURI)
+                  && JBossSAMLConstants.ATTRIBUTE_QUERY.get().equals(startElementName.getLocalPart()))
+            {
+               SAMLAttributeQueryParser responseParser = new SAMLAttributeQueryParser();
+               return responseParser.parse(xmlEventReader);
+            }
             else if (JBossSAMLConstants.XACML_AUTHZ_DECISION_QUERY.get().equals(localPart))
             {
                SAMLXACMLRequestParser samlXacmlParser = new SAMLXACMLRequestParser();

Modified: 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	2011-07-01 20:57:08 UTC (rev 1056)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -32,8 +32,9 @@
 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.constants.JBossSAMLConstants;
-import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil; 
+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.assertion.SubjectType;
 import org.picketlink.identity.federation.saml.v2.protocol.RequestAbstractType;
 
 /**
@@ -44,62 +45,70 @@
 public abstract class SAMLRequestAbstractParser
 {
    protected String id;
+
    protected String version;
-   protected XMLGregorianCalendar issueInstant; 
-   
-   protected void parseRequiredAttributes( StartElement startElement ) throws ParsingException
+
+   protected XMLGregorianCalendar issueInstant;
+
+   protected void parseRequiredAttributes(StartElement startElement) throws ParsingException
    {
-      Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
-      if( idAttr == null )
-         throw new RuntimeException( "ID attribute is missing" );
-      
-      id =  StaxParserUtil.getAttributeValue( idAttr ); 
-      
-      Attribute versionAttr = startElement.getAttributeByName( new QName( "Version" ));
-      if( versionAttr == null )
-         throw new RuntimeException( "Version attribute required in Request" );
-      version = StaxParserUtil.getAttributeValue( versionAttr );
-      
-      Attribute issueInstantAttr = startElement.getAttributeByName( new QName( "IssueInstant" ));
-      if( issueInstantAttr == null )
-         throw new RuntimeException( "IssueInstant attribute required in Request" ); 
-      issueInstant =  XMLTimeUtil.parse( StaxParserUtil.getAttributeValue( issueInstantAttr )); 
+      Attribute idAttr = startElement.getAttributeByName(new QName("ID"));
+      if (idAttr == null)
+         throw new RuntimeException("ID attribute is missing");
+
+      id = StaxParserUtil.getAttributeValue(idAttr);
+
+      Attribute versionAttr = startElement.getAttributeByName(new QName("Version"));
+      if (versionAttr == null)
+         throw new RuntimeException("Version attribute required in Request");
+      version = StaxParserUtil.getAttributeValue(versionAttr);
+
+      Attribute issueInstantAttr = startElement.getAttributeByName(new QName("IssueInstant"));
+      if (issueInstantAttr == null)
+         throw new RuntimeException("IssueInstant attribute required in Request");
+      issueInstant = XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(issueInstantAttr));
    }
-   
+
    /**
     * 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 destinationAttr = startElement.getAttributeByName( new QName( "Destination" ));
-      if( destinationAttr != null )
-         request.setDestination( URI.create( StaxParserUtil.getAttributeValue( destinationAttr ) ));
-      
-      Attribute consent = startElement.getAttributeByName( new QName( "Consent" ));
-      if( consent != null )
-         request.setConsent( StaxParserUtil.getAttributeValue( consent )); 
-   } 
-   
-   protected void parseCommonElements( StartElement startElement, XMLEventReader xmlEventReader,
-         RequestAbstractType request ) throws ParsingException
+   protected void parseBaseAttributes(StartElement startElement, RequestAbstractType request) throws ParsingException
    {
-      if( startElement == null )
-         throw new IllegalArgumentException( " startElement is null" );
-      String elementName = StaxParserUtil.getStartElementName( startElement );
+      Attribute destinationAttr = startElement.getAttributeByName(new QName("Destination"));
+      if (destinationAttr != null)
+         request.setDestination(URI.create(StaxParserUtil.getAttributeValue(destinationAttr)));
 
-      if( JBossSAMLConstants.ISSUER.get().equals( elementName ))
+      Attribute consent = startElement.getAttributeByName(new QName("Consent"));
+      if (consent != null)
+         request.setConsent(StaxParserUtil.getAttributeValue(consent));
+   }
+
+   protected void parseCommonElements(StartElement startElement, XMLEventReader xmlEventReader,
+         RequestAbstractType request) throws ParsingException
+   {
+      if (startElement == null)
+         throw new IllegalArgumentException(" startElement is null");
+      String elementName = StaxParserUtil.getStartElementName(startElement);
+
+      if (JBossSAMLConstants.ISSUER.get().equals(elementName))
       {
-         startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+         startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
          NameIDType issuer = new NameIDType();
-         issuer.setValue( StaxParserUtil.getElementText( xmlEventReader ));
-         request.setIssuer( issuer );
+         issuer.setValue(StaxParserUtil.getElementText(xmlEventReader));
+         request.setIssuer(issuer);
       }
-      else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
-      {  
-         request.setSignature( StaxParserUtil.getDOMElement(xmlEventReader) ); 
-      }  
+      else if (JBossSAMLConstants.SIGNATURE.get().equals(elementName))
+      {
+         request.setSignature(StaxParserUtil.getDOMElement(xmlEventReader));
+      }
    }
+
+   protected SubjectType getSubject(XMLEventReader xmlEventReader) throws ParsingException
+   {
+      SAMLSubjectParser subjectParser = new SAMLSubjectParser();
+      return (SubjectType) subjectParser.parse(xmlEventReader);
+   }
 }
\ No newline at end of file

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java	2011-07-01 20:57:08 UTC (rev 1056)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -40,6 +40,7 @@
    ASSERTION_CONSUMER_SERVICE_INDEX( "AssertionConsumerServiceIndex" ),
    ASSERTION_ID_REQUEST_SERVICE( "AssertionIDRequestService" ),
    ATTRIBUTE( "Attribute" ),
+   ATTRIBUTE_QUERY( "AttributeQuery" ),
    ATTRIBUTE_AUTHORITY_DESCRIPTOR( "AttributeAuthorityDescriptor" ),
    ATTRIBUTE_CONSUMING_SERVICE( "AttributeConsumingService" ),
    ATTRIBUTE_CONSUMING_SERVICE_INDEX( "AttributeConsumingServiceIndex" ),

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java	2011-07-01 20:57:08 UTC (rev 1056)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -29,6 +29,7 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -37,9 +38,21 @@
 import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
 import org.picketlink.identity.federation.core.util.StaxUtil;
 import org.picketlink.identity.federation.core.util.StringUtil;
+import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
 import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
+import org.picketlink.identity.federation.saml.v2.assertion.BaseIDAbstractType;
+import org.picketlink.identity.federation.saml.v2.assertion.EncryptedElementType;
+import org.picketlink.identity.federation.saml.v2.assertion.KeyInfoConfirmationDataType;
 import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationDataType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType.STSubType;
 import org.picketlink.identity.federation.saml.v2.metadata.LocalizedNameType;
+import org.picketlink.identity.xmlsec.w3.xmldsig.KeyInfoType;
+import org.picketlink.identity.xmlsec.w3.xmldsig.X509CertificateType;
+import org.picketlink.identity.xmlsec.w3.xmldsig.X509DataType;
+import org.w3c.dom.Element;
 
 /**
  * Base Class for the Stax writers for SAML
@@ -207,4 +220,161 @@
       StaxUtil.writeCharacters(writer, localizedNameType.getValue());
       StaxUtil.writeEndElement(writer);
    }
+
+   /**
+    * write an {@code SubjectType} to stream
+    * 
+    * @param subject
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write(SubjectType subject) throws ProcessingException
+   {
+      StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT.get(), ASSERTION_NSURI.get());
+
+      STSubType subType = subject.getSubType();
+      if (subType != null)
+      {
+         BaseIDAbstractType baseID = subType.getBaseID();
+         if (baseID instanceof NameIDType)
+         {
+            NameIDType nameIDType = (NameIDType) baseID;
+            write(nameIDType, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX));
+         }
+         EncryptedElementType enc = subType.getEncryptedID();
+         if (enc != null)
+            throw new RuntimeException("NYI");
+         List<SubjectConfirmationType> confirmations = subType.getConfirmation();
+         if (confirmations != null)
+         {
+            for (SubjectConfirmationType confirmation : confirmations)
+            {
+               write(confirmation);
+            }
+         }
+      }
+      List<SubjectConfirmationType> subjectConfirmations = subject.getConfirmation();
+      if (subjectConfirmations != null)
+      {
+         for (SubjectConfirmationType subjectConfirmationType : subjectConfirmations)
+         {
+            write(subjectConfirmationType);
+         }
+      }
+
+      StaxUtil.writeEndElement(writer);
+      StaxUtil.flush(writer);
+   }
+
+   private void write(SubjectConfirmationType subjectConfirmationType) throws ProcessingException
+   {
+      StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION.get(),
+            ASSERTION_NSURI.get());
+
+      StaxUtil.writeAttribute(writer, JBossSAMLConstants.METHOD.get(), subjectConfirmationType.getMethod());
+
+      BaseIDAbstractType baseID = subjectConfirmationType.getBaseID();
+      if (baseID != null)
+      {
+         write(baseID);
+      }
+      NameIDType nameIDType = subjectConfirmationType.getNameID();
+      if (nameIDType != null)
+      {
+         write(nameIDType, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX));
+      }
+      SubjectConfirmationDataType subjectConfirmationData = subjectConfirmationType.getSubjectConfirmationData();
+      if (subjectConfirmationData != null)
+      {
+         write(subjectConfirmationData);
+      }
+      StaxUtil.writeEndElement(writer);
+   }
+
+   private void write(SubjectConfirmationDataType subjectConfirmationData) throws ProcessingException
+   {
+      StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get(),
+            ASSERTION_NSURI.get());
+
+      // Let us look at attributes
+      String inResponseTo = subjectConfirmationData.getInResponseTo();
+      if (StringUtil.isNotNull(inResponseTo))
+      {
+         StaxUtil.writeAttribute(writer, JBossSAMLConstants.IN_RESPONSE_TO.get(), inResponseTo);
+      }
+
+      XMLGregorianCalendar notBefore = subjectConfirmationData.getNotBefore();
+      if (notBefore != null)
+      {
+         StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_BEFORE.get(), notBefore.toString());
+      }
+
+      XMLGregorianCalendar notOnOrAfter = subjectConfirmationData.getNotOnOrAfter();
+      if (notOnOrAfter != null)
+      {
+         StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_ON_OR_AFTER.get(), notOnOrAfter.toString());
+      }
+
+      String recipient = subjectConfirmationData.getRecipient();
+      if (StringUtil.isNotNull(recipient))
+      {
+         StaxUtil.writeAttribute(writer, JBossSAMLConstants.RECIPIENT.get(), recipient);
+      }
+
+      String address = subjectConfirmationData.getAddress();
+      if (StringUtil.isNotNull(address))
+      {
+         StaxUtil.writeAttribute(writer, JBossSAMLConstants.ADDRESS.get(), address);
+      }
+
+      if (subjectConfirmationData instanceof KeyInfoConfirmationDataType)
+      {
+         KeyInfoConfirmationDataType kicd = (KeyInfoConfirmationDataType) subjectConfirmationData;
+         KeyInfoType keyInfo = (KeyInfoType) kicd.getAnyType();
+         if (keyInfo.getContent() == null || keyInfo.getContent().size() == 0)
+            throw new ProcessingException("Invalid KeyInfo object: content cannot be empty");
+         StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
+               WSTrustConstants.XMLDSig.KEYINFO, WSTrustConstants.XMLDSig.DSIG_NS);
+         StaxUtil.writeNameSpace(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.DSIG_NS);
+         // write the keyInfo content.
+         Object content = keyInfo.getContent().get(0);
+         if (content instanceof Element)
+         {
+            Element element = (Element) keyInfo.getContent().get(0);
+            StaxUtil.writeDOMNode(this.writer, element);
+         }
+         else if (content instanceof X509DataType)
+         {
+            X509DataType type = (X509DataType) content;
+            if (type.getDataObjects().size() == 0)
+               throw new ProcessingException("X509Data cannot be empy");
+            StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
+                  WSTrustConstants.XMLDSig.X509DATA, WSTrustConstants.XMLDSig.DSIG_NS);
+            Object obj = type.getDataObjects().get(0);
+            if (obj instanceof Element)
+            {
+               Element element = (Element) obj;
+               StaxUtil.writeDOMElement(this.writer, element);
+            }
+            else if (obj instanceof X509CertificateType)
+            {
+               X509CertificateType cert = (X509CertificateType) obj;
+               StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
+                     WSTrustConstants.XMLDSig.X509CERT, WSTrustConstants.XMLDSig.DSIG_NS);
+               StaxUtil.writeCharacters(this.writer, new String(cert.getEncodedCertificate()));
+               StaxUtil.writeEndElement(this.writer);
+            }
+            StaxUtil.writeEndElement(this.writer);
+         }
+         StaxUtil.writeEndElement(this.writer);
+      }
+
+      StaxUtil.writeEndElement(writer);
+      StaxUtil.flush(writer);
+   }
+
+   private void write(BaseIDAbstractType baseId) throws ProcessingException
+   {
+      throw new RuntimeException("NYI");
+   }
 }
\ No newline at end of file

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java	2011-07-01 20:57:08 UTC (rev 1056)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -34,8 +34,6 @@
 import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
 import org.picketlink.identity.federation.core.saml.v2.util.SAMLXACMLUtil;
 import org.picketlink.identity.federation.core.util.StaxUtil;
-import org.picketlink.identity.federation.core.util.StringUtil;
-import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
 import org.picketlink.identity.federation.saml.v2.assertion.AdviceType;
 import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
 import org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType;
@@ -48,22 +46,14 @@
 import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType;
 import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType.AuthnContextTypeSequence;
 import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
-import org.picketlink.identity.federation.saml.v2.assertion.BaseIDAbstractType;
 import org.picketlink.identity.federation.saml.v2.assertion.ConditionAbstractType;
 import org.picketlink.identity.federation.saml.v2.assertion.ConditionsType;
 import org.picketlink.identity.federation.saml.v2.assertion.EncryptedElementType;
-import org.picketlink.identity.federation.saml.v2.assertion.KeyInfoConfirmationDataType;
 import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
 import org.picketlink.identity.federation.saml.v2.assertion.StatementAbstractType;
-import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationDataType;
-import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationType;
 import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
-import org.picketlink.identity.federation.saml.v2.assertion.SubjectType.STSubType;
 import org.picketlink.identity.federation.saml.v2.assertion.URIType;
 import org.picketlink.identity.federation.saml.v2.profiles.xacml.assertion.XACMLAuthzDecisionStatementType;
-import org.picketlink.identity.xmlsec.w3.xmldsig.KeyInfoType;
-import org.picketlink.identity.xmlsec.w3.xmldsig.X509CertificateType;
-import org.picketlink.identity.xmlsec.w3.xmldsig.X509DataType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -398,161 +388,4 @@
       StaxUtil.writeEndElement(writer);
       StaxUtil.flush(writer);
    }
-
-   /**
-    * write an {@code SubjectType} to stream
-    * 
-    * @param subject
-    * @param out
-    * @throws ProcessingException
-    */
-   public void write(SubjectType subject) throws ProcessingException
-   {
-      StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT.get(), ASSERTION_NSURI.get());
-
-      STSubType subType = subject.getSubType();
-      if (subType != null)
-      {
-         BaseIDAbstractType baseID = subType.getBaseID();
-         if (baseID instanceof NameIDType)
-         {
-            NameIDType nameIDType = (NameIDType) baseID;
-            write(nameIDType, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX));
-         }
-         EncryptedElementType enc = subType.getEncryptedID();
-         if (enc != null)
-            throw new RuntimeException("NYI");
-         List<SubjectConfirmationType> confirmations = subType.getConfirmation();
-         if (confirmations != null)
-         {
-            for (SubjectConfirmationType confirmation : confirmations)
-            {
-               write(confirmation);
-            }
-         }
-      }
-      List<SubjectConfirmationType> subjectConfirmations = subject.getConfirmation();
-      if (subjectConfirmations != null)
-      {
-         for (SubjectConfirmationType subjectConfirmationType : subjectConfirmations)
-         {
-            write(subjectConfirmationType);
-         }
-      }
-
-      StaxUtil.writeEndElement(writer);
-      StaxUtil.flush(writer);
-   }
-
-   private void write(BaseIDAbstractType baseId) throws ProcessingException
-   {
-      throw new RuntimeException("NYI");
-   }
-
-   private void write(SubjectConfirmationType subjectConfirmationType) throws ProcessingException
-   {
-      StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION.get(),
-            ASSERTION_NSURI.get());
-
-      StaxUtil.writeAttribute(writer, JBossSAMLConstants.METHOD.get(), subjectConfirmationType.getMethod());
-
-      BaseIDAbstractType baseID = subjectConfirmationType.getBaseID();
-      if (baseID != null)
-      {
-         write(baseID);
-      }
-      NameIDType nameIDType = subjectConfirmationType.getNameID();
-      if (nameIDType != null)
-      {
-         write(nameIDType, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX));
-      }
-      SubjectConfirmationDataType subjectConfirmationData = subjectConfirmationType.getSubjectConfirmationData();
-      if (subjectConfirmationData != null)
-      {
-         write(subjectConfirmationData);
-      }
-      StaxUtil.writeEndElement(writer);
-   }
-
-   private void write(SubjectConfirmationDataType subjectConfirmationData) throws ProcessingException
-   {
-      StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get(),
-            ASSERTION_NSURI.get());
-
-      // Let us look at attributes
-      String inResponseTo = subjectConfirmationData.getInResponseTo();
-      if (StringUtil.isNotNull(inResponseTo))
-      {
-         StaxUtil.writeAttribute(writer, JBossSAMLConstants.IN_RESPONSE_TO.get(), inResponseTo);
-      }
-
-      XMLGregorianCalendar notBefore = subjectConfirmationData.getNotBefore();
-      if (notBefore != null)
-      {
-         StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_BEFORE.get(), notBefore.toString());
-      }
-
-      XMLGregorianCalendar notOnOrAfter = subjectConfirmationData.getNotOnOrAfter();
-      if (notOnOrAfter != null)
-      {
-         StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_ON_OR_AFTER.get(), notOnOrAfter.toString());
-      }
-
-      String recipient = subjectConfirmationData.getRecipient();
-      if (StringUtil.isNotNull(recipient))
-      {
-         StaxUtil.writeAttribute(writer, JBossSAMLConstants.RECIPIENT.get(), recipient);
-      }
-
-      String address = subjectConfirmationData.getAddress();
-      if (StringUtil.isNotNull(address))
-      {
-         StaxUtil.writeAttribute(writer, JBossSAMLConstants.ADDRESS.get(), address);
-      }
-
-      if (subjectConfirmationData instanceof KeyInfoConfirmationDataType)
-      {
-         KeyInfoConfirmationDataType kicd = (KeyInfoConfirmationDataType) subjectConfirmationData;
-         KeyInfoType keyInfo = (KeyInfoType) kicd.getAnyType();
-         if (keyInfo.getContent() == null || keyInfo.getContent().size() == 0)
-            throw new ProcessingException("Invalid KeyInfo object: content cannot be empty");
-         StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
-               WSTrustConstants.XMLDSig.KEYINFO, WSTrustConstants.XMLDSig.DSIG_NS);
-         StaxUtil.writeNameSpace(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.DSIG_NS);
-         // write the keyInfo content.
-         Object content = keyInfo.getContent().get(0);
-         if (content instanceof Element)
-         {
-            Element element = (Element) keyInfo.getContent().get(0);
-            StaxUtil.writeDOMNode(this.writer, element);
-         }
-         else if (content instanceof X509DataType)
-         {
-            X509DataType type = (X509DataType) content;
-            if (type.getDataObjects().size() == 0)
-               throw new ProcessingException("X509Data cannot be empy");
-            StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
-                  WSTrustConstants.XMLDSig.X509DATA, WSTrustConstants.XMLDSig.DSIG_NS);
-            Object obj = type.getDataObjects().get(0);
-            if (obj instanceof Element)
-            {
-               Element element = (Element) obj;
-               StaxUtil.writeDOMElement(this.writer, element);
-            }
-            else if (obj instanceof X509CertificateType)
-            {
-               X509CertificateType cert = (X509CertificateType) obj;
-               StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
-                     WSTrustConstants.XMLDSig.X509CERT, WSTrustConstants.XMLDSig.DSIG_NS);
-               StaxUtil.writeCharacters(this.writer, new String(cert.getEncodedCertificate()));
-               StaxUtil.writeEndElement(this.writer);
-            }
-            StaxUtil.writeEndElement(this.writer);
-         }
-         StaxUtil.writeEndElement(this.writer);
-      }
-
-      StaxUtil.writeEndElement(writer);
-      StaxUtil.flush(writer);
-   }
 }
\ No newline at end of file

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java	2011-07-01 20:57:08 UTC (rev 1056)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -26,6 +26,7 @@
 
 import java.io.StringWriter;
 import java.net.URI;
+import java.util.List;
 
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
@@ -43,8 +44,11 @@
 import org.picketlink.identity.federation.core.util.JAXBUtil;
 import org.picketlink.identity.federation.core.util.StaxUtil;
 import org.picketlink.identity.federation.core.util.StringUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
 import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
 import org.picketlink.identity.federation.saml.v2.protocol.ArtifactResolveType;
+import org.picketlink.identity.federation.saml.v2.protocol.AttributeQueryType;
 import org.picketlink.identity.federation.saml.v2.protocol.AuthnRequestType;
 import org.picketlink.identity.federation.saml.v2.protocol.LogoutRequestType;
 import org.picketlink.identity.federation.saml.v2.protocol.NameIDPolicyType;
@@ -231,6 +235,7 @@
       StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.ARTIFACT_RESOLVE.get(),
             PROTOCOL_NSURI.get());
       StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
+      StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
       StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
 
       //Attributes 
@@ -267,11 +272,58 @@
       StaxUtil.flush(writer);
    }
 
+   public void write(AttributeQueryType request) throws ProcessingException
+   {
+      StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.ATTRIBUTE_QUERY.get(),
+            PROTOCOL_NSURI.get());
+      StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
+      StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
+      StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
+
+      //Attributes 
+      StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), request.getID());
+      StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), request.getVersion());
+      StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
+
+      URI destination = request.getDestination();
+      if (destination != null)
+         StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
+
+      String consent = request.getConsent();
+      if (StringUtil.isNotNull(consent))
+         StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
+
+      NameIDType issuer = request.getIssuer();
+      if (issuer != null)
+      {
+         write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get()));
+      }
+      Element sig = request.getSignature();
+      if (sig != null)
+      {
+         StaxUtil.writeDOMElement(writer, sig);
+      }
+      SubjectType subject = request.getSubject();
+      if (subject != null)
+      {
+         write(subject);
+      }
+      List<AttributeType> attributes = request.getAttribute();
+      for (AttributeType attr : attributes)
+      {
+         write(attr);
+      }
+      StaxUtil.writeEndElement(writer);
+      StaxUtil.flush(writer);
+   }
+
    public void write(XACMLAuthzDecisionQueryType xacmlQuery) throws ProcessingException
    {
       StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.REQUEST_ABSTRACT.get(),
             PROTOCOL_NSURI.get());
       StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
+      StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
+
       StaxUtil.writeNameSpace(writer, XACML_SAML_PROTO_PREFIX, JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get());
       StaxUtil.writeDefaultNameSpace(writer, JBossSAMLURIConstants.XACML_NSURI.get());
 

Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAttributeQueryParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAttributeQueryParserTestCase.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAttributeQueryParserTestCase.java	2011-07-01 21:44:58 UTC (rev 1057)
@@ -0,0 +1,86 @@
+/*
+ * 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.saml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
+import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLRequestWriter;
+import org.picketlink.identity.federation.core.util.JAXPValidationUtil;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
+import org.picketlink.identity.federation.saml.v2.protocol.ArtifactResolveType;
+import org.picketlink.identity.federation.saml.v2.protocol.AttributeQueryType;
+import org.w3c.dom.Document;
+
+/**
+ * Unit test the parsing of {@link ArtifactResolveType}
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 1, 2011
+ */
+public class SAMLAttributeQueryParserTestCase
+{
+   @Test
+   public void testSAMLAttributeQueryParse() throws Exception
+   {
+      String file = "parser/saml2/saml2-attributequery.xml";
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      InputStream configStream = tcl.getResourceAsStream(file);
+
+      JAXPValidationUtil.validate(configStream);
+      configStream = tcl.getResourceAsStream(file);
+
+      SAMLParser parser = new SAMLParser();
+      AttributeQueryType attributeQuery = (AttributeQueryType) parser.parse(configStream);
+      assertNotNull("ArtifactResolveType is not null", attributeQuery);
+
+      assertEquals("ID_aaf23196-1773-2113-474a-fe114412ab72", attributeQuery.getID());
+      assertEquals(XMLTimeUtil.parse("2006-07-17T20:31:40Z"), attributeQuery.getIssueInstant());
+      assertEquals("CN=anil,OU=User,O=TEST,C=US", attributeQuery.getIssuer().getValue());
+
+      SubjectType subject = attributeQuery.getSubject();
+      NameIDType nameID = (NameIDType) subject.getSubType().getBaseID();
+      assertEquals("CN=anil,OU=User,O=TEST,C=US", nameID.getValue());
+      List<AttributeType> attributes = attributeQuery.getAttribute();
+      assertEquals(2, attributes.size());
+
+      //Try out writing
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      SAMLRequestWriter writer = new SAMLRequestWriter(StaxUtil.getXMLStreamWriter(baos));
+      writer.write(attributeQuery);
+
+      ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+      Document doc = DocumentUtil.getDocument(bis); //throws exceptions
+      JAXPValidationUtil.validate(DocumentUtil.getNodeAsStream(doc));
+   }
+}
\ No newline at end of file

Added: federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-attributequery.xml
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-attributequery.xml	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/resources/parser/saml2/saml2-attributequery.xml	2011-07-01 21:44:58 UTC (rev 1057)
@@ -0,0 +1,27 @@
+<samlp:AttributeQuery
+   xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
+   xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
+   ID="ID_aaf23196-1773-2113-474a-fe114412ab72"
+   Version="2.0"
+   IssueInstant="2006-07-17T20:31:40Z">
+   <saml:Issuer
+     Format="urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName">
+     CN=anil,OU=User,O=TEST,C=US
+   </saml:Issuer>
+   <saml:Subject>
+     <saml:NameID
+       Format="urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName">
+       CN=anil,OU=User,O=TEST,C=US
+     </saml:NameID>
+   </saml:Subject>
+   <saml:Attribute
+     NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
+     Name="urn:oid:2.5.4.42"
+     FriendlyName="givenName">
+   </saml:Attribute>
+   <saml:Attribute
+     NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
+     Name="urn:oid:1.3.6.1.4.1.1466.115.121.1.26"
+     FriendlyName="mail">
+   </saml:Attribute>
+ </samlp:AttributeQuery>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list