[jboss-cvs] JBossAS SVN: r64161 - in projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core: model and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 20 08:48:36 EDT 2007


Author: anil.saldhana at jboss.com
Date: 2007-07-20 08:48:36 -0400 (Fri, 20 Jul 2007)
New Revision: 64161

Added:
   projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/model/
   projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/model/ContextUnitTestCase.java
Modified:
   projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/JBossPDPUnitTestCase.java
Log:
test changes with JAXB2

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/JBossPDPUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/JBossPDPUnitTestCase.java	2007-07-20 12:47:49 UTC (rev 64160)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/JBossPDPUnitTestCase.java	2007-07-20 12:48:36 UTC (rev 64161)
@@ -23,15 +23,22 @@
 
 import java.io.InputStream;
 
+import junit.framework.TestCase;
+
 import org.jboss.security.xacml.core.JBossPDP;
+import org.jboss.security.xacml.core.model.context.ActionType;
+import org.jboss.security.xacml.core.model.context.AttributeType;
+import org.jboss.security.xacml.core.model.context.EnvironmentType;
+import org.jboss.security.xacml.core.model.context.RequestType;
+import org.jboss.security.xacml.core.model.context.ResourceType;
+import org.jboss.security.xacml.core.model.context.SubjectType;
+import org.jboss.security.xacml.factories.RequestAttributeFactory;
 import org.jboss.security.xacml.factories.RequestResponseContextFactory;
 import org.jboss.security.xacml.interfaces.PolicyDecisionPoint;
 import org.jboss.security.xacml.interfaces.RequestContext;
 import org.jboss.security.xacml.interfaces.ResponseContext;
 import org.jboss.security.xacml.interfaces.XACMLConstants;
 
-import junit.framework.TestCase;
-
 //$Id$
 
 /**
@@ -42,7 +49,10 @@
  */
 public class JBossPDPUnitTestCase extends TestCase
 { 
-   public void testInteropTest() throws Exception
+   /**Enable to see the xacml request in system out for the objects case**/
+   private boolean sysout = false;
+   
+   public void testInteropTestWithXMLRequests() throws Exception
    {
       ClassLoader tcl = Thread.currentThread().getContextClassLoader();
       InputStream is = tcl.getResourceAsStream("test/config/interopPolicySetConfig.xml");
@@ -77,6 +87,48 @@
             getDecision(pdp,"test/requests/interop/scenario2-testcase7-request.xml"));
    } 
    
+   public void testInteropTestWithObjects() throws Exception
+   {
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      InputStream is = tcl.getResourceAsStream("test/config/interopPolicySetConfig.xml");
+      assertNotNull("InputStream != null", is);
+      PolicyDecisionPoint pdp = new JBossPDP(is);
+      assertNotNull("JBossPDP is != null", pdp);
+      
+      assertEquals("Case 1 should be deny", XACMLConstants.DECISION_DENY,
+            getDecision(pdp,getRequestContext("false","false",10)));
+      assertEquals("Case 2 should be deny", XACMLConstants.DECISION_PERMIT,
+            getDecision(pdp,getRequestContext("false","false",1)));
+      assertEquals("Case 3 should be deny", XACMLConstants.DECISION_PERMIT,
+            getDecision(pdp,getRequestContext("true","false",5)));
+      assertEquals("Case 4 should be deny", XACMLConstants.DECISION_DENY,
+            getDecision(pdp,getRequestContext("false","false",9)));
+      assertEquals("Case 5 should be deny", XACMLConstants.DECISION_DENY,
+            getDecision(pdp,getRequestContext("true","false",10)));
+      assertEquals("Case 6 should be deny", XACMLConstants.DECISION_DENY,
+            getDecision(pdp,getRequestContext("true","false",15)));
+      assertEquals("Case 7 should be deny", XACMLConstants.DECISION_PERMIT,
+            getDecision(pdp,getRequestContext("true","true",10)));
+          
+   }
+   
+   private RequestContext getRequestContext(String reqTradeAppr, String reqCreditAppr,
+         int buyPrice) throws Exception
+   {
+      RequestType request = new RequestType();
+      request.getSubject().add(createSubject(reqTradeAppr,reqCreditAppr,buyPrice));
+      request.getResource().add(createResource());
+      request.setAction(createAction());
+      request.setEnvironment( new EnvironmentType());
+      
+      RequestContext requestCtx = RequestResponseContextFactory.createRequestCtx();
+      requestCtx.setRequest(request);
+      if(sysout)
+        requestCtx.marshall(System.out);
+      
+      return requestCtx;
+   }
+   
    private int getDecision(PolicyDecisionPoint pdp, String loc) throws Exception
    {
       ClassLoader tcl = Thread.currentThread().getContextClassLoader();
@@ -87,4 +139,106 @@
       assertNotNull("Response is not null", response);
       return response.getDecision(); 
    }
+   
+   
+   private int getDecision(PolicyDecisionPoint pdp, RequestContext request) 
+   throws Exception
+   {
+      ResponseContext response = pdp.evaluate(request);
+      assertNotNull("Response is not null", response);
+      return response.getDecision(); 
+   }
+   
+   private SubjectType createSubject(String reqTradeAppr, String reqCreditAppr,
+         int buyPrice)
+   {
+      //Create a subject type
+      SubjectType subject = new SubjectType();
+      subject.setSubjectCategory("urn:oasis:names:tc:xacml:1.0:subject-category:access-subject");
+      //create the subject attributes
+      AttributeType attSubjectID = RequestAttributeFactory.createStringAttributeType(
+                                            "urn:oasis:names:tc:xacml:1.0:subject:subject-id",
+                                            "xacml20.interop.com", "123456"); 
+      subject.getAttribute().add(attSubjectID);
+      
+      AttributeType attUserName = RequestAttributeFactory.createStringAttributeType(
+                                             "urn:xacml:2.0:interop:example:subject:user-name",
+                                             "xacml20.interop.com", "John Smith");
+      subject.getAttribute().add(attUserName);
+      
+      AttributeType attBuyNumShares = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:xacml:2.0:interop:example:subject:buy-num-shares",
+            "xacml20.interop.com", 1000);
+      subject.getAttribute().add(attBuyNumShares); 
+      
+      AttributeType attBuyOfferShare = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:xacml:2.0:interop:example:subject:buy-offer-price",
+            "xacml20.interop.com", buyPrice);
+      subject.getAttribute().add(attBuyOfferShare);
+       
+      
+      AttributeType attRequestExtCred = RequestAttributeFactory.createStringAttributeType(
+            "urn:xacml:2.0:interop:example:subject:req-credit-ext-approval",
+            "xacml20.interop.com", reqCreditAppr);
+      subject.getAttribute().add(attRequestExtCred); 
+      
+      AttributeType attRequestTradeApproval = RequestAttributeFactory.createStringAttributeType(
+            "urn:xacml:2.0:interop:example:subject:req-trade-approval",
+            "xacml20.interop.com", reqTradeAppr);
+      subject.getAttribute().add(attRequestTradeApproval);
+
+     return subject;
+   }
+   
+   public ResourceType createResource()
+   {
+      ResourceType resourceType = new ResourceType();
+      
+      AttributeType attResourceID = RequestAttributeFactory.createStringAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
+            "xacml20.interop.com", "CustomerAccount");
+      resourceType.getAttribute().add(attResourceID);
+      
+      
+      AttributeType attOwnerID = RequestAttributeFactory.createStringAttributeType(
+            "urn:xacml:2.0:interop:example:resource:owner-id",
+            "xacml20.interop.com", "123456");
+      resourceType.getAttribute().add(attOwnerID);
+
+      AttributeType attOwnerName = RequestAttributeFactory.createStringAttributeType(
+            "urn:xacml:2.0:interop:example:resource:owner-name",
+            "xacml20.interop.com", "John Smith");
+      resourceType.getAttribute().add(attOwnerName);
+      
+      AttributeType attAccountStatus = RequestAttributeFactory.createStringAttributeType(
+            "urn:xacml:2.0:interop:example:resource:account-status",
+            "xacml20.interop.com", "Active");
+      resourceType.getAttribute().add(attAccountStatus); 
+      
+      AttributeType attCreditLine = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:xacml:2.0:interop:example:resource:credit-line",
+            "xacml20.interop.com", 15000);
+      resourceType.getAttribute().add(attCreditLine); 
+      
+      AttributeType attCurrentCredit = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:xacml:2.0:interop:example:resource:current-credit",
+            "xacml20.interop.com", 10000);
+      resourceType.getAttribute().add(attCurrentCredit); 
+      
+      AttributeType attTradeLimit = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:xacml:2.0:interop:example:resource:trade-limit",
+            "xacml20.interop.com", 10000);
+      resourceType.getAttribute().add(attTradeLimit); 
+      return resourceType;
+   }
+   
+   private ActionType createAction()
+   {
+      ActionType actionType = new ActionType();
+      AttributeType attActionID = RequestAttributeFactory.createStringAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:action:action-id",
+            "xacml20.interop.com", "Buy");
+      actionType.getAttribute().add(attActionID);
+      return actionType;
+   }
 }

Added: projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/model/ContextUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/model/ContextUnitTestCase.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/core/model/ContextUnitTestCase.java	2007-07-20 12:48:36 UTC (rev 64161)
@@ -0,0 +1,181 @@
+/*
+  * 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.core.model;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.bind.JAXB;
+import javax.xml.bind.JAXBElement;
+
+import junit.framework.TestCase;
+
+import org.jboss.security.xacml.core.JBossPDP;
+import org.jboss.security.xacml.core.model.context.ActionType;
+import org.jboss.security.xacml.core.model.context.AttributeType;
+import org.jboss.security.xacml.core.model.context.EnvironmentType;
+import org.jboss.security.xacml.core.model.context.ObjectFactory;
+import org.jboss.security.xacml.core.model.context.RequestType;
+import org.jboss.security.xacml.core.model.context.ResourceType;
+import org.jboss.security.xacml.core.model.context.SubjectType;
+import org.jboss.security.xacml.factories.RequestAttributeFactory;
+import org.jboss.security.xacml.factories.RequestResponseContextFactory;
+import org.jboss.security.xacml.interfaces.PolicyDecisionPoint;
+import org.jboss.security.xacml.interfaces.RequestContext;
+import org.jboss.security.xacml.interfaces.ResponseContext;
+import org.jboss.security.xacml.interfaces.XACMLConstants;
+
+
+/**
+ *  Construction of request/response
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Jul 20, 2007 
+ *  @version $Revision$
+ */
+public class ContextUnitTestCase extends TestCase
+{ 
+   public void testConstructRequest() throws Exception
+   {
+      RequestType request = new RequestType();
+      request.getSubject().add(createSubject());
+      request.getResource().add(createResource());
+      request.setAction(createAction());
+      request.setEnvironment( new EnvironmentType());
+      
+      JAXBElement<RequestType> requestJAXB = new ObjectFactory().createRequest(request);
+      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
+      JAXB.marshal(requestJAXB, baos);
+      ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+      RequestContext requestCtx = RequestResponseContextFactory.createRequestCtx();
+      requestCtx.readRequest(bis); 
+      requestCtx.marshall(System.out);
+      
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      InputStream is = tcl.getResourceAsStream("test/config/interopPolicySetConfig.xml");
+      assertNotNull("InputStream != null", is);
+      PolicyDecisionPoint pdp = new JBossPDP(is);
+      assertNotNull("JBossPDP is != null", pdp);
+      
+      assertEquals("Case 1 should be deny", XACMLConstants.DECISION_DENY, getDecision(pdp,requestCtx));
+   }
+   
+   private SubjectType createSubject()
+   {
+      //Create a subject type
+      SubjectType subject = new SubjectType();
+      subject.setSubjectCategory("urn:oasis:names:tc:xacml:1.0:subject-category:access-subject");
+      //create the subject attributes
+      AttributeType attSubjectID = RequestAttributeFactory.createStringAttributeType(
+                                            "urn:oasis:names:tc:xacml:1.0:subject:subject-id",
+                                            "xacml20.interop.com", "123456"); 
+      subject.getAttribute().add(attSubjectID);
+      
+      AttributeType attUserName = RequestAttributeFactory.createStringAttributeType(
+                                             "urn:xacml:2.0:interop:example:subject:user-name",
+                                             "xacml20.interop.com", "John Smith");
+      subject.getAttribute().add(attUserName);
+      
+      AttributeType attBuyNumShares = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:xacml:2.0:interop:example:subject:buy-num-shares",
+            "xacml20.interop.com", 1000);
+      subject.getAttribute().add(attBuyNumShares); 
+      
+      AttributeType attBuyOfferShare = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:xacml:2.0:interop:example:subject:buy-offer-price",
+            "xacml20.interop.com", 100);
+      subject.getAttribute().add(attBuyOfferShare);
+       
+      
+      AttributeType attRequestExtCred = RequestAttributeFactory.createStringAttributeType(
+            "urn:xacml:2.0:interop:example:subject:req-credit-ext-approval",
+            "xacml20.interop.com", "false");
+      subject.getAttribute().add(attRequestExtCred); 
+      
+      AttributeType attRequestTradeApproval = RequestAttributeFactory.createStringAttributeType(
+            "urn:xacml:2.0:interop:example:subject:req-trade-approval",
+            "xacml20.interop.com", "false");
+      subject.getAttribute().add(attRequestTradeApproval);
+
+     return subject;
+   }
+   
+   public ResourceType createResource()
+   {
+      ResourceType resourceType = new ResourceType();
+      
+      AttributeType attResourceID = RequestAttributeFactory.createStringAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
+            "xacml20.interop.com", "CustomerAccount");
+      resourceType.getAttribute().add(attResourceID);
+      
+      
+      AttributeType attOwnerID = RequestAttributeFactory.createStringAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:owner-id",
+            "xacml20.interop.com", "123456");
+      resourceType.getAttribute().add(attOwnerID);
+
+      AttributeType attOwnerName = RequestAttributeFactory.createStringAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:owner-name",
+            "xacml20.interop.com", "John Smith");
+      resourceType.getAttribute().add(attOwnerName);
+      
+      AttributeType attAccountStatus = RequestAttributeFactory.createStringAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:account-status",
+            "xacml20.interop.com", "Active");
+      resourceType.getAttribute().add(attAccountStatus); 
+      
+      AttributeType attCreditLine = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:credit-line",
+            "xacml20.interop.com", 15000);
+      resourceType.getAttribute().add(attCreditLine); 
+      
+      AttributeType attCurrentCredit = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:current-credit",
+            "xacml20.interop.com", 10000);
+      resourceType.getAttribute().add(attCurrentCredit); 
+      
+      AttributeType attTradeLimit = RequestAttributeFactory.createIntegerAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:resource:trade-limit",
+            "xacml20.interop.com", 10000);
+      resourceType.getAttribute().add(attTradeLimit); 
+      return resourceType;
+   }
+   
+   private ActionType createAction()
+   {
+      ActionType actionType = new ActionType();
+      AttributeType attActionID = RequestAttributeFactory.createStringAttributeType(
+            "urn:oasis:names:tc:xacml:1.0:action:action-id",
+            "xacml20.interop.com", "Buy");
+      actionType.getAttribute().add(attActionID);
+      return actionType;
+   }
+   
+   private int getDecision(PolicyDecisionPoint pdp, RequestContext request) 
+   throws Exception
+   {
+      ResponseContext response = pdp.evaluate(request);
+      assertNotNull("Response is not null", response);
+      return response.getDecision(); 
+   }
+}




More information about the jboss-cvs-commits mailing list