### Eclipse Workspace Patch 1.0 #P jboss-xacml Index: src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java =================================================================== --- src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java (revision 0) +++ src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java (working copy) @@ -0,0 +1,67 @@ + /* + * JBoss, Home of Professional Open Source + * Copyright 2005, 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 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@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()); + } +} Index: SECURITY-590.patch =================================================================== --- SECURITY-590.patch (revision 0) +++ SECURITY-590.patch (working copy) @@ -0,0 +1,124 @@ +Index: src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java +=================================================================== +--- src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java (revision 112453) ++++ src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java (working copy) +@@ -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 +Index: src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java +=================================================================== +--- src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java (revision 0) ++++ src/test/java/org/jboss/test/security/xacml/factories/RequestAttributeFactoryTestCase.java (working copy) +@@ -0,0 +1,52 @@ ++package org.jboss.test.security.xacml.factories; ++ ++import java.util.GregorianCalendar; ++ ++import javax.xml.XMLConstants; ++import javax.xml.datatype.DatatypeFactory; ++import javax.xml.datatype.XMLGregorianCalendar; ++ ++import junit.framework.Assert; ++ ++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.RequestContext; ++import org.junit.Test; ++ ++public class RequestAttributeFactoryTestCase { ++ ++ ++ @Test ++ public void shouldCreateDefaultTimeAttributeValue() throws Exception{ ++ AttributeType type= ++ RequestAttributeFactory.createTimeAttributeType("x", null); ++ //get the ++ 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); ++ //get the ++ 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); ++ //get the ++ 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()); ++ } ++} Index: src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java =================================================================== --- src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java (revision 112453) +++ src/main/java/org/jboss/security/xacml/factories/RequestAttributeFactory.java (working copy) @@ -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