[jboss-cvs] JBossAS SVN: r91887 - in projects/security/security-xacml/trunk/jboss-xacml/src: test/java/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 31 13:36:27 EDT 2009
Author: anil.saldhana at jboss.com
Date: 2009-07-31 13:36:27 -0400 (Fri, 31 Jul 2009)
New Revision: 91887
Added:
projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/model/RequestContextAttributeFactoryUnitTestCase.java
Modified:
projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java
Log:
SECURITY-423: create multi valued attribute
Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java 2009-07-31 17:24:49 UTC (rev 91886)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java 2009-07-31 17:36:27 UTC (rev 91887)
@@ -23,8 +23,10 @@
import java.net.InetAddress;
import java.net.URI;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.List;
import javax.security.auth.x500.X500Principal;
import javax.xml.datatype.DatatypeConfigurationException;
@@ -45,102 +47,254 @@
* @version $Revision$
*/
public class RequestAttributeFactory
-{
-
+{
+ /**
+ * Create an attribute that is of URI type
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createAnyURIAttributeType(String attrID, String issuer, URI value)
{
return getBareAttributeType(attrID, issuer, "" + value, XMLSchemaConstants.DATATYPE_ANYURI);
}
+ /**
+ * Create Base64 attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createBase64BinaryAttributeType(String attrID, String issuer, byte[] value)
{
return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_BASE64BINARY);
}
+ /**
+ * Create Boolean attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createBooleanAttributeType(String attrID, String issuer, boolean value)
{
return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_BOOLEAN);
}
+ /**
+ * Create Date attribute
+ * @param attrID
+ * @param issuer
+ * @return
+ */
public static AttributeType createDateAttributeType(String attrID, String issuer)
{
return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_DATE);
}
+ /**
+ * Create Date attribute with the passed {@link XMLGregorianCalendar}
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createDateAttributeType(String attrID, String issuer, XMLGregorianCalendar value)
{
return getBareAttributeType(attrID, issuer, value.toXMLFormat(), XMLSchemaConstants.DATATYPE_DATE);
}
+ /**
+ * Create Date Time Attribute
+ * @param attrID
+ * @param issuer
+ * @return
+ */
public static AttributeType createDateTimeAttributeType(String attrID, String issuer)
{
return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_DATE_TIME);
}
-
+ /**
+ * Create Date Time attribute with the passed {@link XMLGregorianCalendar}
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createDateTimeAttributeType(String attrID, String issuer, XMLGregorianCalendar value)
{
return getBareAttributeType(attrID, issuer, value.toXMLFormat(), XMLSchemaConstants.DATATYPE_DATE_TIME);
}
+ /**
+ * Create DNS Name Attribute
+ * @param attrID
+ * @param issuer
+ * @param hostname
+ * @return
+ */
public static AttributeType createDNSNameAttributeType(String attrID, String issuer, String hostname)
{
return getBareAttributeType(attrID, issuer, hostname, XMLSchemaConstants.DATATYPE_DNSNAME);
}
+ /**
+ * Create Double Attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createDoubleAttributeType(String attrID, String issuer, double value)
{
return getBareAttributeType(attrID, issuer, "" + value, XMLSchemaConstants.DATATYPE_DOUBLE);
}
+ /**
+ * Create Email Attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createEmailAttributeType(String attrID, String issuer, String value)
{
return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_RFC822NAME);
}
+ /**
+ * Create Hex Binary attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createHexBinaryAttributeType(String attrID, String issuer, byte[] value)
{
return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_HEXBINARY);
}
+ /**
+ * Create Integer Attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createIntegerAttributeType(String attrID, String issuer, int value)
{
return getBareAttributeType(attrID, issuer, "" + value, XMLSchemaConstants.DATATYPE_INTEGER);
}
+ /**
+ * Create IP Address attribute
+ * @param attrID
+ * @param issuer
+ * @param address
+ * @return
+ */
public static AttributeType createIPAddressAttributeType(String attrID, String issuer, InetAddress address)
{
return getBareAttributeType(attrID, issuer, address, XMLSchemaConstants.DATATYPE_IPADDRESS);
}
+ /**
+ * Create String attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createStringAttributeType(String attrID, String issuer, String value)
{
return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_STRING);
}
+ /**
+ * Create Time attribute
+ * @param attrID
+ * @param issuer
+ * @return
+ */
public static AttributeType createTimeAttributeType(String attrID, String issuer)
{
return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_TIME);
}
+ /**
+ * Create Time Attribute with the passed {@link XMLGregorianCalendar}
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createTimeAttributeType(String attrID, String issuer, XMLGregorianCalendar value)
{
return getBareAttributeType(attrID, issuer, value.toXMLFormat(), XMLSchemaConstants.DATATYPE_TIME);
}
+ /**
+ * Create X509 attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createX509NameAttributeType(String attrID, String issuer, X500Principal value)
{
return getBareAttributeType(attrID, issuer, value, XMLSchemaConstants.DATATYPE_X500NAME);
}
+ /**
+ * Create DayTimeDuration attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createDayTimeDurationAttributeType(String attrID, String issuer, Duration value)
{
return getBareAttributeType(attrID, issuer, value.toString(), XMLSchemaConstants.DATATYPE_DAYTIMEDURATION);
}
+ /**
+ * Create year month duration attribute
+ * @param attrID
+ * @param issuer
+ * @param value
+ * @return
+ */
public static AttributeType createYearMonthDurationAttributeType(String attrID, String issuer, Duration value)
{
return getBareAttributeType(attrID, issuer, value.toString(), XMLSchemaConstants.DATATYPE_YEARMONTHDURATION);
}
+
+ /**
+ * Create multi valued attribute
+ * @param attrID
+ * @param issuer
+ * @param dataType
+ * @param values
+ * @return
+ */
+ public static AttributeType createMultiValuedAttributeType(String attrID, String issuer, String dataType, String[] values)
+ {
+ AttributeType attributeType = new AttributeType();
+ attributeType.setAttributeId(attrID);
+ attributeType.setDataType(dataType);
+ if (issuer != null)
+ attributeType.setIssuer(issuer);
+
+ List<String> valueList = Arrays.asList(values);
+
+ AttributeValueType avt = new AttributeValueType();
+ avt.getContent().addAll(valueList);
+ attributeType.getAttributeValue().add(avt);
+ return attributeType;
+ }
private static AttributeType getBareAttributeType(String attrID, String issuer, Object value, String dataType)
{
@@ -169,4 +323,4 @@
XMLGregorianCalendar value = dtf.newXMLGregorianCalendar((GregorianCalendar) Calendar.getInstance());
return value.toXMLFormat();
}
-}
+}
\ No newline at end of file
Added: projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/model/RequestContextAttributeFactoryUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/model/RequestContextAttributeFactoryUnitTestCase.java (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/model/RequestContextAttributeFactoryUnitTestCase.java 2009-07-31 17:36:27 UTC (rev 91887)
@@ -0,0 +1,58 @@
+/*
+ * 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.jboss.test.security.xacml.core.model;
+
+import org.jboss.security.xacml.core.model.context.AttributeType;
+import org.jboss.security.xacml.core.model.context.AttributeValueType;
+import org.jboss.security.xacml.factories.RequestAttributeFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Anil.Saldhana at redhat.com
+ * @since Jul 31, 2009
+ */
+public class RequestContextAttributeFactoryUnitTestCase extends TestCase
+{
+ public void testMultiValuedAttribute()
+ {
+ String attributeId = "urn:va:xacml:2.0:interop:rsa8:subject:hl7:permission";
+ String dataType = "http://www.w3.org/2001/XMLSchema#string";
+ String issuer = "testissuer";
+
+ //Create a multi-valued attribute - hl7 permissions
+ String[] values = new String[] {"urn:va:xacml:2.0:interop:rsa8:hl7:prd-010",
+ "urn:va:xacml:2.0:interop:rsa8:hl7:prd-012",
+ "urn:va:xacml:2.0:interop:rsa8:hl7:prd-017",
+ "urn:va:xacml:2.0:interop:rsa8:hl7:prd-005",
+ "urn:va:xacml:2.0:interop:rsa8:hl7:prd-003",
+ "urn:va:xacml:2.0:interop:rsa8:hl7:prd-009",
+ "urn:va:xacml:2.0:interop:rsa8:hl7:prd-006"};
+
+ AttributeType multi = RequestAttributeFactory.createMultiValuedAttributeType(attributeId,
+ issuer, dataType, values);
+ assertNotNull("Attribute is not null", multi);
+ AttributeValueType avt = multi.getAttributeValue().get(0);
+ assertEquals(7 ,avt.getContent().size());
+ }
+
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list