[jboss-cvs] JBossAS SVN: r70976 - in projects/security/security-xacml/trunk/jboss-xacml/src: tests/org/jboss/test/security/xacml/bindings/web and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 18 22:45:24 EDT 2008


Author: mmoyses
Date: 2008-03-18 22:45:23 -0400 (Tue, 18 Mar 2008)
New Revision: 70976

Added:
   projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/factories/PolicyAttributeFactoryTestCase.java
Modified:
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/PolicyAttributeFactory.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/RequestAttributeFactory.java
   projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/bindings/web/WebLayerDynamicPolicyUnitTestCase.java
Log:
PolicyAttributeFactoryTestCase

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/PolicyAttributeFactory.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/PolicyAttributeFactory.java	2008-03-19 00:02:04 UTC (rev 70975)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/PolicyAttributeFactory.java	2008-03-19 02:45:23 UTC (rev 70976)
@@ -144,19 +144,29 @@
       return getBareAttributeValueType(value.toString(), XMLSchemaConstants.DATATYPE_YEARMONTHDURATION);
    }
 
-   public static AttributeDesignatorType createAttributeDesignatorType(String id, String dataType)
+   public static AttributeDesignatorType createAttributeDesignatorType(String id, String dataType, String issuer,
+         boolean mustBePresent)
    {
       AttributeDesignatorType adt = new AttributeDesignatorType();
       adt.setAttributeId(id);
       adt.setDataType(dataType);
+      if (issuer != null)
+         adt.setIssuer(issuer);
+      adt.setMustBePresent(mustBePresent);
       return adt;
    }
 
-   public static SubjectAttributeDesignatorType createSubjectAttributeDesignatorType(String id, String dataType)
+   public static SubjectAttributeDesignatorType createSubjectAttributeDesignatorType(String id, String dataType,
+         String issuer, boolean mustBePresent, String subjectCategory)
    {
       SubjectAttributeDesignatorType adt = new SubjectAttributeDesignatorType();
       adt.setAttributeId(id);
       adt.setDataType(dataType);
+      if (issuer != null)
+         adt.setIssuer(issuer);
+      adt.setMustBePresent(mustBePresent);
+      if (subjectCategory != null)
+         adt.setSubjectCategory(subjectCategory);
       return adt;
    }
 

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/RequestAttributeFactory.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/RequestAttributeFactory.java	2008-03-19 00:02:04 UTC (rev 70975)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/factories/RequestAttributeFactory.java	2008-03-19 02:45:23 UTC (rev 70976)
@@ -29,6 +29,7 @@
 import javax.security.auth.x500.X500Principal;
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
 import javax.xml.datatype.XMLGregorianCalendar;
 
 import org.jboss.security.xacml.core.model.context.AttributeType;
@@ -46,106 +47,115 @@
  */
 public class RequestAttributeFactory
 {
-   
-   public static AttributeType createAnyURIAttributeType(String attrID, String issuer,URI value)
+
+   public static AttributeType createAnyURIAttributeType(String attrID, String issuer, URI value)
    {
-      return getBareAttributeType(attrID, issuer, ""+value, XMLSchemaConstants.DATATYPE_ANYURI);
+      return getBareAttributeType(attrID, issuer, "" + value, XMLSchemaConstants.DATATYPE_ANYURI);
    }
-   
-   public static AttributeType createBase64BinaryAttributeType(String attrID, String issuer,byte[] value)
+
+   public static AttributeType createBase64BinaryAttributeType(String attrID, String issuer, byte[] value)
    {
       return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_BASE64BINARY);
    }
-   
-   public static AttributeType createBooleanAttributeType(String attrID, String issuer,boolean value)
+
+   public static AttributeType createBooleanAttributeType(String attrID, String issuer, boolean value)
    {
       return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_BOOLEAN);
    }
-   
+
    public static AttributeType createDateAttributeType(String attrID, String issuer)
    {
       return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_DATE);
    }
-   
-   public static AttributeType createDateAttributeType(String attrID, String issuer,XMLGregorianCalendar value)
+
+   public static AttributeType createDateAttributeType(String attrID, String issuer, XMLGregorianCalendar value)
    {
       return getBareAttributeType(attrID, issuer, value.toXMLFormat(), XMLSchemaConstants.DATATYPE_DATE);
    }
-   
+
    public static AttributeType createDateTimeAttributeType(String attrID, String issuer)
    {
       return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_DATE_TIME);
    }
-   
-   public static AttributeType createDateTimeAttributeType(String attrID, String issuer,XMLGregorianCalendar value)
+
+   public static AttributeType createDateTimeAttributeType(String attrID, String issuer, XMLGregorianCalendar value)
    {
       return getBareAttributeType(attrID, issuer, value.toXMLFormat(), XMLSchemaConstants.DATATYPE_DATE_TIME);
    }
-   
-   public static AttributeType createDNSNameAttributeType(String attrID, String issuer,String hostname)
+
+   public static AttributeType createDNSNameAttributeType(String attrID, String issuer, String hostname)
    {
-      return getBareAttributeType(attrID, issuer, hostname, "urn:oasis:names:tc:xacml:2.0:data-type:dnsName");
+      return getBareAttributeType(attrID, issuer, hostname, XMLSchemaConstants.DATATYPE_DNSNAME);
    }
-   
-   public static AttributeType createDoubleAttributeType(String attrID, String issuer,double value)
+
+   public static AttributeType createDoubleAttributeType(String attrID, String issuer, double value)
    {
       return getBareAttributeType(attrID, issuer, "" + value, XMLSchemaConstants.DATATYPE_DOUBLE);
    }
-   
-   public static AttributeType createEmailAttributeType(String attrID, String issuer,String value)
+
+   public static AttributeType createEmailAttributeType(String attrID, String issuer, String value)
    {
-      return getBareAttributeType(attrID, issuer, value, "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name");
+      return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_RFC822NAME);
    }
-   
-   public static AttributeType createHexBinaryAttributeType(String attrID, String issuer,byte[] value)
+
+   public static AttributeType createHexBinaryAttributeType(String attrID, String issuer, byte[] value)
    {
       return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_HEXBINARY);
    }
-   
+
    public static AttributeType createIntegerAttributeType(String attrID, String issuer, int value)
    {
-     return getBareAttributeType(attrID, issuer, ""+value, XMLSchemaConstants.DATATYPE_INTEGER); 
+      return getBareAttributeType(attrID, issuer, "" + value, XMLSchemaConstants.DATATYPE_INTEGER);
    }
-   
-   public static AttributeType createIPAddressAttributeType(String attrID, String issuer,InetAddress address)
+
+   public static AttributeType createIPAddressAttributeType(String attrID, String issuer, InetAddress address)
    {
-      return getBareAttributeType(attrID, issuer, address, "urn:oasis:names:tc:xacml:2.0:data-type:ipAddress"); 
+      return getBareAttributeType(attrID, issuer, address, XMLSchemaConstants.DATATYPE_IPADDRESS);
    }
-   
+
    public static AttributeType createStringAttributeType(String attrID, String issuer, String value)
    {
-      return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_STRING); 
+      return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_STRING);
    }
-   
+
    public static AttributeType createTimeAttributeType(String attrID, String issuer)
-   { 
-      return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_TIME); 
+   {
+      return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_TIME);
    }
-   
+
    public static AttributeType createTimeAttributeType(String attrID, String issuer, XMLGregorianCalendar value)
    {
-      return getBareAttributeType(attrID, issuer, value.toXMLFormat(), XMLSchemaConstants.DATATYPE_TIME); 
+      return getBareAttributeType(attrID, issuer, value.toXMLFormat(), XMLSchemaConstants.DATATYPE_TIME);
    }
-   
+
    public static AttributeType createX509NameAttributeType(String attrID, String issuer, X500Principal value)
    {
-      return getBareAttributeType(attrID, issuer, value, "urn:oasis:names:tc:xacml:1.0:data-type:x500Name"); 
+      return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_X500NAME);
    }
-   
-   private static AttributeType getBareAttributeType(String attrID, String issuer, Object value,
-         String dataType)
+
+   public static AttributeType createDayTimeDurationAttributeType(String attrID, String issuer, Duration value)
    {
+      return getBareAttributeType(attrID, issuer, value.toString(), XMLSchemaConstants.DATATYPE_DAYTIMEDURATION);
+   }
+
+   public static AttributeType createYearMonthDurationAttributeType(String attrID, String issuer, Duration value)
+   {
+      return getBareAttributeType(attrID, issuer, value.toString(), XMLSchemaConstants.DATATYPE_YEARMONTHDURATION);
+   }
+
+   private static AttributeType getBareAttributeType(String attrID, String issuer, Object value, String dataType)
+   {
       AttributeType attributeType = new AttributeType();
       attributeType.setAttributeId(attrID);
-      attributeType.setDataType(dataType);  
-      if(issuer != null)
+      attributeType.setDataType(dataType);
+      if (issuer != null)
          attributeType.setIssuer(issuer);
       AttributeValueType avt = new AttributeValueType();
       avt.getContent().add(value);
       attributeType.getAttributeValue().add(avt);
-      return attributeType; 
+      return attributeType;
    }
-   
+
    private static String getXMLDate()
    {
       DatatypeFactory dtf;
@@ -156,7 +166,7 @@
       catch (DatatypeConfigurationException e)
       {
          throw new RuntimeException(e);
-      } 
+      }
       XMLGregorianCalendar value = dtf.newXMLGregorianCalendar((GregorianCalendar) Calendar.getInstance());
       return value.toXMLFormat();
    }

Modified: projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/bindings/web/WebLayerDynamicPolicyUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/bindings/web/WebLayerDynamicPolicyUnitTestCase.java	2008-03-19 00:02:04 UTC (rev 70975)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/bindings/web/WebLayerDynamicPolicyUnitTestCase.java	2008-03-19 02:45:23 UTC (rev 70976)
@@ -179,7 +179,7 @@
       ResourceMatchType rmt = new ResourceMatchType();
       rmt.setMatchId(XACMLConstants.FUNCTION_ANYURI_EQUAL);
       rmt.setResourceAttributeDesignator(PolicyAttributeFactory.createAttributeDesignatorType(
-            XACMLConstants.ATTRIBUTEID_RESOURCE_ID, XMLSchemaConstants.DATATYPE_ANYURI));
+            XACMLConstants.ATTRIBUTEID_RESOURCE_ID, XMLSchemaConstants.DATATYPE_ANYURI, null, false));
       rmt.setAttributeValue(PolicyAttributeFactory
             .createAnyURIAttributeType(new URI("http://test/developer-guide.html")));
       resourceType.getResourceMatch().add(rmt);
@@ -201,7 +201,7 @@
       amct.setMatchId("urn:oasis:names:tc:xacml:1.0:function:string-equal");
       amct.setAttributeValue(PolicyAttributeFactory.createStringAttributeType("read"));
       amct.setActionAttributeDesignator(PolicyAttributeFactory.createAttributeDesignatorType(
-            XACMLConstants.ATTRIBUTEID_ACTION_ID, XMLSchemaConstants.DATATYPE_STRING));
+            XACMLConstants.ATTRIBUTEID_ACTION_ID, XMLSchemaConstants.DATATYPE_STRING, null, false));
       permitRuleActionType.getActionMatch().add(amct);
       TargetType permitRuleTargetType = new TargetType();
       permitRuleActionsType.getAction().add(permitRuleActionType);
@@ -218,7 +218,7 @@
       permitRuleApplyType.setFunctionId(XACMLConstants.FUNCTION_STRING_IS_IN);
 
       SubjectAttributeDesignatorType sadt = PolicyAttributeFactory.createSubjectAttributeDesignatorType(
-            XACMLConstants.ATTRIBUTEID_ROLE, XMLSchemaConstants.DATATYPE_STRING);
+            XACMLConstants.ATTRIBUTEID_ROLE, XMLSchemaConstants.DATATYPE_STRING, null, false, null);
       JAXBElement<SubjectAttributeDesignatorType> sadtElement = objectFactory.createSubjectAttributeDesignator(sadt);
       AttributeValueType avt = PolicyAttributeFactory.createStringAttributeType("developer");
       JAXBElement<AttributeValueType> jaxbAVT = objectFactory.createAttributeValue(avt);

Added: projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/factories/PolicyAttributeFactoryTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/factories/PolicyAttributeFactoryTestCase.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/tests/org/jboss/test/security/xacml/factories/PolicyAttributeFactoryTestCase.java	2008-03-19 02:45:23 UTC (rev 70976)
@@ -0,0 +1,83 @@
+/*
+  * 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.factories;
+
+import junit.framework.TestCase;
+
+import org.jboss.security.xacml.core.model.policy.AttributeDesignatorType;
+import org.jboss.security.xacml.core.model.policy.SubjectAttributeDesignatorType;
+import org.jboss.security.xacml.factories.PolicyAttributeFactory;
+import org.jboss.security.xacml.interfaces.XACMLConstants;
+import org.jboss.security.xacml.interfaces.XMLSchemaConstants;
+
+/**
+ * TestCase for <code>PolicyAttributeFactory</code>
+ * 
+ * @author Marcus Moyses
+ * @since Mar 18, 2008
+ */
+public class PolicyAttributeFactoryTestCase extends TestCase
+{
+
+   public void testCreateAttributeDesignatorType1() throws Exception
+   {
+      AttributeDesignatorType adt = PolicyAttributeFactory.createAttributeDesignatorType(
+            XACMLConstants.ATTRIBUTEID_ACTION_ID, XMLSchemaConstants.DATATYPE_STRING, null, false);
+      assertEquals("AttributeId?", XACMLConstants.ATTRIBUTEID_ACTION_ID, adt.getAttributeId());
+      assertEquals("DataType?", XMLSchemaConstants.DATATYPE_STRING, adt.getDataType());
+      assertEquals("MustBePresent?", false, adt.isMustBePresent());
+      assertNull("Issuer?", adt.getIssuer());
+   }
+
+   public void testCreateAttributeDesignatorType2() throws Exception
+   {
+      AttributeDesignatorType adt = PolicyAttributeFactory.createAttributeDesignatorType(
+            XACMLConstants.ATTRIBUTEID_CURRENT_DATE, XMLSchemaConstants.DATATYPE_DATE, "org.jboss", true);
+      assertEquals("AttributeId?", XACMLConstants.ATTRIBUTEID_CURRENT_DATE, adt.getAttributeId());
+      assertEquals("DataType?", XMLSchemaConstants.DATATYPE_DATE, adt.getDataType());
+      assertEquals("MustBePresent?", true, adt.isMustBePresent());
+      assertEquals("Issuer?", "org.jboss", adt.getIssuer());
+   }
+
+   public void testCreateSubjectAttributeDesignatorType1() throws Exception
+   {
+      SubjectAttributeDesignatorType adt = PolicyAttributeFactory.createSubjectAttributeDesignatorType(
+            XACMLConstants.ATTRIBUTEID_ACTION_ID, XMLSchemaConstants.DATATYPE_STRING, null, false, null);
+      assertEquals("AttributeId?", XACMLConstants.ATTRIBUTEID_ACTION_ID, adt.getAttributeId());
+      assertEquals("DataType?", XMLSchemaConstants.DATATYPE_STRING, adt.getDataType());
+      assertEquals("MustBePresent?", false, adt.isMustBePresent());
+      assertNull("Issuer?", adt.getIssuer());
+      assertEquals("SubjectCategory?", XACMLConstants.ATTRIBUTEID_ACCESS_SUBJECT, adt.getSubjectCategory());
+   }
+
+   public void testCreateSubjectAttributeDesignatorType2() throws Exception
+   {
+      SubjectAttributeDesignatorType adt = PolicyAttributeFactory.createSubjectAttributeDesignatorType(
+            XACMLConstants.ATTRIBUTEID_CURRENT_DATE, XMLSchemaConstants.DATATYPE_DATE, "org.jboss", true,
+            XACMLConstants.ATTRIBUTEID_CODEBASE);
+      assertEquals("AttributeId?", XACMLConstants.ATTRIBUTEID_CURRENT_DATE, adt.getAttributeId());
+      assertEquals("DataType?", XMLSchemaConstants.DATATYPE_DATE, adt.getDataType());
+      assertEquals("MustBePresent?", true, adt.isMustBePresent());
+      assertEquals("Issuer?", "org.jboss", adt.getIssuer());
+      assertEquals("SubjectCategory?", XACMLConstants.ATTRIBUTEID_CODEBASE, adt.getSubjectCategory());
+   }
+}




More information about the jboss-cvs-commits mailing list