[jboss-cvs] JBossAS SVN: r71706 - in projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml: interop and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 3 14:00:37 EDT 2008


Author: anil.saldhana at jboss.com
Date: 2008-04-03 14:00:36 -0400 (Thu, 03 Apr 2008)
New Revision: 71706

Added:
   projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/DynamicSAMLResponseUnitTestCase.java
   projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java
   projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/interop/
   projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/interop/RedHatEndpointTestCase.java
Modified:
   projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLResponseUnitTestCase.java
   projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLUnitTestCase.java
Log:
add tests

Added: projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/DynamicSAMLResponseUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/DynamicSAMLResponseUnitTestCase.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/DynamicSAMLResponseUnitTestCase.java	2008-04-03 18:00:36 UTC (rev 71706)
@@ -0,0 +1,113 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.jboss.test.security.xacml.saml;
+
+import junit.framework.TestCase;
+
+import org.jboss.security.xacml.factories.RequestResponseContextFactory;
+import org.jboss.security.xacml.interfaces.RequestContext;
+import org.jboss.security.xacml.interfaces.ResponseContext;
+import org.jboss.security.xacml.saml.integration.opensaml.core.JBossXACMLSAMLConfiguration;
+import org.jboss.security.xacml.saml.integration.opensaml.core.OpenSAMLUtil;
+import org.jboss.security.xacml.saml.integration.opensaml.types.XACMLAuthzDecisionStatementType;
+import org.joda.time.DateTime;
+import org.joda.time.chrono.ISOChronology;
+import org.opensaml.Configuration;
+import org.opensaml.saml2.core.Assertion;
+import org.opensaml.saml2.core.Issuer;
+import org.opensaml.saml2.core.Response;
+import org.opensaml.saml2.core.Status;
+import org.opensaml.saml2.core.StatusCode;
+import org.opensaml.saml2.core.impl.AssertionImpl;
+import org.opensaml.xml.io.Marshaller;
+import org.opensaml.xml.io.MarshallerFactory;
+import org.opensaml.xml.util.XMLHelper;
+
+/**
+ *  Construct SAML Response and test
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Apr 2, 2008 
+ *  @version $Revision$
+ */
+public class DynamicSAMLResponseUnitTestCase extends TestCase
+{
+
+   protected void setUp() throws Exception
+   {
+      JBossXACMLSAMLConfiguration.initialize(); 
+   }
+   
+   public void testSAMLResponse() throws Exception
+   {
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      RequestContext requestContext = RequestResponseContextFactory.createRequestCtx();
+      requestContext.readRequest(tcl.getResourceAsStream("xacml/xacmlrequest.xml"));
+      
+      ResponseContext responseContext = RequestResponseContextFactory.createResponseContext();
+      responseContext.readResponse(tcl.getResourceAsStream("xacml/xacmlresponse.xml"));
+      
+      
+      String responseId = "response-1";
+      String issuerId = "issuer-1";
+      
+      DateTime issueInstant = new DateTime(ISOChronology.getInstanceUTC());
+      Response samlResponse = getSAMLResponse(issueInstant, responseId, issuerId);
+      
+      //Create samlp:Assertion
+      Assertion assertion = (Assertion) OpenSAMLUtil.buildXMLObject(Assertion.DEFAULT_ELEMENT_NAME);
+      assertion.setID(responseId);
+      assertion.setIssueInstant(issueInstant);
+      
+      Issuer issuer = (Issuer) OpenSAMLUtil.buildXMLObject(Issuer.DEFAULT_ELEMENT_NAME);
+      issuer.setValue(issuerId);
+      assertion.setIssuer(issuer);
+      
+      XACMLAuthzDecisionStatementType decision = (XACMLAuthzDecisionStatementType) 
+         OpenSAMLUtil.buildXMLObject(XACMLAuthzDecisionStatementType.DEFAULT_ELEMENT_NAME_XACML20);
+
+      decision.setResponse(responseContext);
+      decision.setRequest(requestContext);
+      
+      //Some mismatch in the Statements for XACML
+      AssertionImpl assertionImpl = (AssertionImpl) assertion;
+      assertionImpl.getStatements().add(decision);
+      
+      samlResponse.getAssertions().add(assertionImpl);                   
+   }
+   
+   private Response getSAMLResponse(DateTime issueInstant, String responseId,
+         String issuerId)
+   {   
+      Response samlResponse = (Response) OpenSAMLUtil.buildXMLObject(Response.DEFAULT_ELEMENT_NAME); 
+      samlResponse.setID(responseId);
+      samlResponse.setIssueInstant(issueInstant);
+      
+      //Set samlp:Status
+      Status status = (Status) OpenSAMLUtil.buildXMLObject(Status.DEFAULT_ELEMENT_NAME);
+      StatusCode statusCode = (StatusCode) OpenSAMLUtil.buildXMLObject(StatusCode.DEFAULT_ELEMENT_NAME);
+      statusCode.setValue(StatusCode.SUCCESS_URI);
+      status.setStatusCode(statusCode);
+      samlResponse.setStatus(status);
+       
+      return samlResponse;
+   }
+}

Added: projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java	2008-04-03 18:00:36 UTC (rev 71706)
@@ -0,0 +1,55 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.jboss.test.security.xacml.saml;
+
+import junit.framework.TestCase;
+
+import org.jboss.security.xacml.interfaces.RequestContext;
+import org.jboss.security.xacml.saml.integration.opensaml.core.JBossXACMLSAMLConfiguration;
+import org.jboss.security.xacml.saml.integration.opensaml.request.JBossSAMLRequest;
+import org.jboss.security.xacml.saml.integration.opensaml.types.XACMLAuthzDecisionQueryType;
+import org.opensaml.common.SAMLObject;
+
+/**
+ *  Tests for SAMLRequest read
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Apr 2, 2008 
+ *  @version $Revision$
+ */
+public class SAMLRequestUnitTestCase extends TestCase
+{
+   protected void setUp() throws Exception
+   {
+      JBossXACMLSAMLConfiguration.initialize(); 
+   }
+   
+   public void testSAMLRequest01_01() throws Exception
+   {
+      JBossSAMLRequest samlRequest = new JBossSAMLRequest();
+      String loc = "src/tests/resources/test/requests/interop/rsaconf08/XacmlRequest-01-01.xml";
+      SAMLObject samlObject = samlRequest.getSAMLRequest(loc);
+      XACMLAuthzDecisionQueryType xacmlRequest = (XACMLAuthzDecisionQueryType)samlObject;
+      RequestContext requestContext = xacmlRequest.getRequest();
+      assertNotNull("XACML Request Context is not null", requestContext);
+   }
+
+}

Modified: projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLResponseUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLResponseUnitTestCase.java	2008-04-03 17:49:16 UTC (rev 71705)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLResponseUnitTestCase.java	2008-04-03 18:00:36 UTC (rev 71706)
@@ -23,22 +23,14 @@
 
 import java.util.List;
 
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionQueryTypeImplBuilder;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionQueryTypeMarshaller;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionQueryTypeUnMarshaller;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionStatementTypeImplBuilder;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionStatementTypeMarshaller;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionStatementTypeUnMarshaller;
+import junit.framework.TestCase;
+
+import org.jboss.security.xacml.saml.integration.opensaml.core.JBossXACMLSAMLConfiguration;
 import org.jboss.security.xacml.saml.integration.opensaml.request.JBossSAMLResponse;
-import org.jboss.security.xacml.saml.integration.opensaml.types.XACMLAuthzDecisionQueryType;
-import org.jboss.security.xacml.saml.integration.opensaml.types.XACMLAuthzDecisionStatementType;
-import org.opensaml.Configuration;
 import org.opensaml.common.SAMLObject;
 import org.opensaml.saml2.core.Assertion;
 import org.opensaml.saml2.core.Response;
 import org.opensaml.saml2.core.Statement;
-
-import junit.framework.TestCase;
  
 /**
  *  Test reading of a saml response containing
@@ -51,17 +43,7 @@
 {
    protected void setUp() throws Exception
    {
-     org.opensaml.DefaultBootstrap.bootstrap(); 
-     Configuration.registerObjectProvider(XACMLAuthzDecisionQueryType.DEFAULT_ELEMENT_NAME_XACML20, 
-           new XACMLAuthzDecisionQueryTypeImplBuilder(), 
-           new XACMLAuthzDecisionQueryTypeMarshaller(), 
-           new XACMLAuthzDecisionQueryTypeUnMarshaller(), 
-           null);
-     Configuration.registerObjectProvider(XACMLAuthzDecisionStatementType.DEFAULT_ELEMENT_NAME_XACML20, 
-           new XACMLAuthzDecisionStatementTypeImplBuilder(), 
-           new XACMLAuthzDecisionStatementTypeMarshaller(), 
-           new XACMLAuthzDecisionStatementTypeUnMarshaller(), 
-           null);
+      JBossXACMLSAMLConfiguration.initialize(); 
    }
    
    public void testSAMLXACMLResponseRead() throws Exception
@@ -78,4 +60,19 @@
       Statement statement = statements.get(0);
       assertNotNull("Statement != null", statement);
    } 
+   
+   public void testRHPDPResponseRead() throws Exception
+   {
+      JBossSAMLResponse response = new JBossSAMLResponse();
+      SAMLObject samlObject = response.getSAMLResponse("src/tests/resources/saml/rhpdpsamlresponse.xml");
+      assertNotNull(samlObject); 
+      
+      //Verify that the xacml response does exist
+      Response samlResponse = (Response) samlObject;
+      Assertion assertion = samlResponse.getAssertions().get(0);
+      List<Statement> statements = assertion.getStatements();
+      assertTrue("statements > 0 ", statements.size() > 0);
+      Statement statement = statements.get(0);
+      assertNotNull("Statement != null", statement);
+   } 
 }
\ No newline at end of file

Modified: projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLUnitTestCase.java	2008-04-03 17:49:16 UTC (rev 71705)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLXACMLUnitTestCase.java	2008-04-03 18:00:36 UTC (rev 71706)
@@ -25,16 +25,10 @@
 
 import org.jboss.security.xacml.core.PDPConfiguration;
 import org.jboss.security.xacml.interfaces.RequestContext;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionQueryTypeImplBuilder;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionQueryTypeMarshaller;
-import org.jboss.security.xacml.saml.integration.opensaml.impl.XACMLAuthzDecisionQueryTypeUnMarshaller;
+import org.jboss.security.xacml.saml.integration.opensaml.core.JBossXACMLSAMLConfiguration;
 import org.jboss.security.xacml.saml.integration.opensaml.request.JBossSAMLRequest;
 import org.jboss.security.xacml.saml.integration.opensaml.types.XACMLAuthzDecisionQueryType;
-import org.opensaml.Configuration;
 import org.opensaml.common.SAMLObject;
-import org.opensaml.xml.XMLObject;
-import org.opensaml.xml.io.Marshaller;
-import org.opensaml.xml.util.XMLHelper;
  
 /**
  *  Unit Test for the Opensaml saml/xacml
@@ -46,12 +40,7 @@
 {
    protected void setUp() throws Exception
    {
-     org.opensaml.DefaultBootstrap.bootstrap(); 
-     Configuration.registerObjectProvider(XACMLAuthzDecisionQueryType.DEFAULT_ELEMENT_NAME_XACML20, 
-           new XACMLAuthzDecisionQueryTypeImplBuilder(), 
-           new XACMLAuthzDecisionQueryTypeMarshaller(), 
-           new XACMLAuthzDecisionQueryTypeUnMarshaller(), 
-           null);
+      JBossXACMLSAMLConfiguration.initialize(); 
    }
    
    public void testSAMLXACMLRequestRead() throws Exception
@@ -66,18 +55,6 @@
       XACMLAuthzDecisionQueryType xacmlRequest = (XACMLAuthzDecisionQueryType)samlObject;
       RequestContext requestType = xacmlRequest.getRequest();
       assertNotNull("XACML Request is not null", requestType);
-      
-      XMLObject xmlObject = xacmlRequest;
-      Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
-      //surefire plugin issue
-      try
-      {
-         System.out.println(XMLHelper.prettyPrintXML(marshaller.marshall(xmlObject))); 
-      }
-      catch(Exception e)
-      {
-         e.printStackTrace();
-      }
    }
   
    public void testSAMLRequestRead() throws Exception

Added: projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/interop/RedHatEndpointTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/interop/RedHatEndpointTestCase.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/interop/RedHatEndpointTestCase.java	2008-04-03 18:00:36 UTC (rev 71706)
@@ -0,0 +1,95 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.jboss.test.security.xacml.saml.interop;
+
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.net.URLConnection;
+
+import junit.framework.TestCase;
+
+import org.jboss.security.xacml.interfaces.ResponseContext;
+import org.jboss.security.xacml.interfaces.XACMLConstants;
+import org.jboss.security.xacml.saml.integration.opensaml.core.JBossXACMLSAMLConfiguration;
+import org.jboss.security.xacml.saml.integration.opensaml.request.JBossSAMLRequest;
+import org.jboss.security.xacml.saml.integration.opensaml.request.JBossSAMLResponse;
+import org.jboss.security.xacml.saml.integration.opensaml.types.XACMLAuthzDecisionStatementType;
+import org.opensaml.common.SAMLObject;
+import org.opensaml.saml2.core.Assertion;
+import org.opensaml.saml2.core.Response;
+import org.opensaml.saml2.core.impl.AssertionImpl;
+import org.opensaml.xml.util.XMLHelper;
+ 
+/**
+ *  Test the JBoss endpoint
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Apr 2, 2008 
+ *  @version $Revision$
+ */
+public class RedHatEndpointTestCase extends TestCase
+{
+   String loc = "http://localhost:8080/jboss/SOAPServlet";
+   
+   boolean shouldTest = false;
+   
+   protected void setUp() throws Exception
+   {
+      JBossXACMLSAMLConfiguration.initialize(); 
+   }
+   
+   public void testRequest01_01() throws Exception
+   {
+
+      /**
+      <!-- **************************************************************** -->
+      <!-- Test case 1-01: Should be Perm: Dr A has all reqd perms          -->
+      <!-- **************************************************************** -->
+      **/
+      if(shouldTest)
+      { 
+         System.setProperty("debug","true");
+         JBossSAMLRequest samlRequest = new JBossSAMLRequest();
+         ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+         InputStream is = tcl.getResourceAsStream("test/requests/interop/rsaconf08/XacmlRequest-01-01.xml");
+         assertNotNull(is);
+         SAMLObject samlObject = samlRequest.getSAMLRequest(is);
+         
+         URL url = new URL(loc);
+         URLConnection conn = url.openConnection();
+         conn.setDoOutput(true);
+         OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
+         wr.write(XMLHelper.nodeToString(samlObject.getDOM()));
+         wr.flush();
+         
+         JBossSAMLResponse samlResponse = new JBossSAMLResponse();
+         Response response = (Response) samlResponse.getSAMLResponse(conn.getInputStream());
+         System.out.println(XMLHelper.prettyPrintXML(response.getDOM()));       
+         
+         Assertion assertion = response.getAssertions().get(0);
+         AssertionImpl aimpl = (AssertionImpl) assertion;
+         XACMLAuthzDecisionStatementType xtype = (XACMLAuthzDecisionStatementType) aimpl.getStatements().get(0);
+         ResponseContext rc = xtype.getResponse();
+         assertEquals(XACMLConstants.DECISION_PERMIT,rc.getDecision());
+      } 
+   } 
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list