[jboss-cvs] JBossAS SVN: r112457 - in projects/security/security-xacml/trunk/jboss-xacml/src: test/java/org/jboss/test/security/xacml/factories and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 17 22:36:03 EST 2011


Author: dgradl
Date: 2011-11-17 22:36:03 -0500 (Thu, 17 Nov 2011)
New Revision: 112457

Added:
   projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java
Modified:
   projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java
Log:
Bug fix for https://issues.jboss.org/browse/SECURITY-590.   Date and Time Attributes were being created as a full XMLSchema DateTime, instead of Date and Time respectively.  This would later case a ParseException when the attributes were assigned to the RequestContext.

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	2011-11-17 01:53:11 UTC (rev 112456)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java	2011-11-18 03:36:03 UTC (rev 112457)
@@ -115,7 +115,7 @@
     */
    public static AttributeType createDateTimeAttributeType(String attrID, String issuer)
    {
-      return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_DATE_TIME);
+      return getBareAttributeType(attrID, issuer, getXMLDateTime(), XMLSchemaConstants.DATATYPE_DATE_TIME);
    }
    /**
     * Create Date Time attribute with the passed {@link XMLGregorianCalendar}
@@ -221,7 +221,7 @@
     */
    public static AttributeType createTimeAttributeType(String attrID, String issuer)
    {
-      return getBareAttributeType(attrID, issuer, getXMLDate(), XMLSchemaConstants.DATATYPE_TIME);
+      return getBareAttributeType(attrID, issuer, getXMLTime(), XMLSchemaConstants.DATATYPE_TIME);
    }
 
    /**
@@ -309,7 +309,7 @@
       return attributeType;
    }
 
-   private static String getXMLDate()
+   private static String getXMLDateTime()
    {
       DatatypeFactory dtf;
       try
@@ -323,4 +323,34 @@
       XMLGregorianCalendar value = dtf.newXMLGregorianCalendar((GregorianCalendar) Calendar.getInstance());
       return value.toXMLFormat();
    }
+   private static String getXMLDate()
+   {
+      DatatypeFactory dtf;
+      try
+      {
+         dtf = DatatypeFactory.newInstance();
+      }
+      catch (DatatypeConfigurationException e)
+      {
+         throw new RuntimeException(e);
+      }
+      GregorianCalendar cal=(GregorianCalendar) Calendar.getInstance();
+      XMLGregorianCalendar value = dtf.newXMLGregorianCalendarDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.getTimeZone().getRawOffset()/60000);
+      return value.toXMLFormat();
+   }
+   private static String getXMLTime()
+   {
+      DatatypeFactory dtf;
+      try
+      {
+         dtf = DatatypeFactory.newInstance();
+      }
+      catch (DatatypeConfigurationException e)
+      {
+         throw new RuntimeException(e);
+      }
+      GregorianCalendar cal=(GregorianCalendar) Calendar.getInstance();
+      XMLGregorianCalendar value = dtf.newXMLGregorianCalendarTime(cal.get(Calendar.HOUR),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND),cal.get(Calendar.MILLISECOND), cal.getTimeZone().getRawOffset()/60000);
+      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/factories/RequestAttributeFactoryTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java	2011-11-18 03:36:03 UTC (rev 112457)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.factories;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import junit.framework.Assert;
+
+import org.jboss.security.xacml.core.model.context.AttributeType;
+import org.jboss.security.xacml.factories.RequestAttributeFactory;
+import org.junit.Test;
+
+
+/**
+ * Unit tests for the RequestAttributeFactory Attribute
+ * @author dangradl at gmail.com
+ * @since Nov 16, 2011
+ */
+public class RequestAttributeFactoryTestCase
+{
+
+	
+	@Test
+	public void shouldCreateDefaultTimeAttributeValue() throws Exception{
+		AttributeType type=
+				RequestAttributeFactory.createTimeAttributeType("x", null);
+		String time=(String)type.getAttributeValue().get(0).getContent().get(0);
+		XMLGregorianCalendar cal=DatatypeFactory.newInstance().newXMLGregorianCalendar(time);
+		Assert.assertEquals("{http://www.w3.org/2001/XMLSchema}time", cal.getXMLSchemaType().toString());
+	}
+	@Test
+	public void shouldCreateDefaultDateTimeAttributeValue() throws Exception{
+		AttributeType type=
+				RequestAttributeFactory.createDateTimeAttributeType("x", null);
+		String datetime=(String)type.getAttributeValue().get(0).getContent().get(0);
+		XMLGregorianCalendar cal=DatatypeFactory.newInstance().newXMLGregorianCalendar(datetime);
+		Assert.assertEquals("{http://www.w3.org/2001/XMLSchema}dateTime", cal.getXMLSchemaType().toString());
+	}
+	@Test
+	public void shouldCreateDefaultDateAttributeValue() throws Exception{
+		AttributeType type=
+				RequestAttributeFactory.createDateAttributeType("x", null);
+		String datetime=(String)type.getAttributeValue().get(0).getContent().get(0);
+		XMLGregorianCalendar cal=DatatypeFactory.newInstance().newXMLGregorianCalendar(datetime);
+		Assert.assertEquals("{http://www.w3.org/2001/XMLSchema}date", cal.getXMLSchemaType().toString());
+	}
+}



More information about the jboss-cvs-commits mailing list