[jboss-cvs] JBossAS SVN: r71405 - in projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core: ext and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 28 18:36:35 EDT 2008


Author: anil.saldhana at jboss.com
Date: 2008-03-28 18:36:35 -0400 (Fri, 28 Mar 2008)
New Revision: 71405

Added:
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/PDPConfiguration.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactory.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactoryProxy.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttribute.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttributeProxy.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttribute.java
   projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttributeProxy.java
Log:
SECURITY-158: custom attributes

Added: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/PDPConfiguration.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/PDPConfiguration.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/PDPConfiguration.java	2008-03-28 22:36:35 UTC (rev 71405)
@@ -0,0 +1,59 @@
+/*
+  * 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.security.xacml.core;
+
+import org.jboss.security.xacml.core.ext.ExtendedAttributeFactoryProxy;
+import org.jboss.security.xacml.core.ext.MultiValueAttributeProxy;
+import org.jboss.security.xacml.core.ext.SingleValueAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.AttributeFactory;
+
+/**
+ *  Installs some custom PDP Configuration
+ *  such as custom attributes
+ *  
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 28, 2008 
+ *  @version $Revision$
+ */
+public class PDPConfiguration
+{
+   static
+   {
+      AttributeFactory.setDefaultFactory(new ExtendedAttributeFactoryProxy());
+   }
+   
+   public static void installSingleValueAttribute(String type)
+   {
+      AttributeFactory factory = AttributeFactory.getInstance();
+      factory.addDatatype(type, 
+            new SingleValueAttributeProxy(type));
+      
+   }
+   
+   public static void installMultiValueAttribute(String type)
+   {
+      AttributeFactory factory = AttributeFactory.getInstance();
+      factory.addDatatype(type, 
+            new MultiValueAttributeProxy(type));
+      
+   } 
+}
\ No newline at end of file

Added: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactory.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactory.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactory.java	2008-03-28 22:36:35 UTC (rev 71405)
@@ -0,0 +1,175 @@
+/*
+  * 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.security.xacml.core.ext;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.security.xacml.sunxacml.ParsingException;
+import org.jboss.security.xacml.sunxacml.UnknownIdentifierException;
+import org.jboss.security.xacml.sunxacml.attr.AnyURIAttribute;
+import org.jboss.security.xacml.sunxacml.attr.AttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.AttributeValue;
+import org.jboss.security.xacml.sunxacml.attr.Base64BinaryAttribute;
+import org.jboss.security.xacml.sunxacml.attr.BaseAttributeFactory;
+import org.jboss.security.xacml.sunxacml.attr.BooleanAttribute;
+import org.jboss.security.xacml.sunxacml.attr.DNSNameAttribute;
+import org.jboss.security.xacml.sunxacml.attr.DateAttribute;
+import org.jboss.security.xacml.sunxacml.attr.DateTimeAttribute;
+import org.jboss.security.xacml.sunxacml.attr.DayTimeDurationAttribute;
+import org.jboss.security.xacml.sunxacml.attr.DoubleAttribute;
+import org.jboss.security.xacml.sunxacml.attr.HexBinaryAttribute;
+import org.jboss.security.xacml.sunxacml.attr.IPAddressAttribute;
+import org.jboss.security.xacml.sunxacml.attr.IntegerAttribute;
+import org.jboss.security.xacml.sunxacml.attr.RFC822NameAttribute;
+import org.jboss.security.xacml.sunxacml.attr.StringAttribute;
+import org.jboss.security.xacml.sunxacml.attr.TimeAttribute;
+import org.jboss.security.xacml.sunxacml.attr.X500NameAttribute;
+import org.jboss.security.xacml.sunxacml.attr.YearMonthDurationAttribute;
+import org.jboss.security.xacml.sunxacml.attr.proxy.AnyURIAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.Base64BinaryAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.BooleanAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.DNSNameAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.DateAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.DateTimeAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.DayTimeDurationAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.DoubleAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.HexBinaryAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.IPAddressAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.IntegerAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.RFC822NameAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.StringAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.TimeAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.X500NameAttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.proxy.YearMonthDurationAttributeProxy;
+import org.w3c.dom.Node;
+ 
+/**
+ *  Extendible Attribute factory
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 28, 2008 
+ *  @version $Revision$
+ */
+public class ExtendedAttributeFactory extends BaseAttributeFactory
+{ 
+  
+   private static ExtendedAttributeFactory instance = null;
+   private static  Map supportedDatatypes = new HashMap();
+    
+   private ExtendedAttributeFactory()
+   {
+      super(supportedDatatypes); 
+
+      // the 1.x datatypes
+      supportedDatatypes.put(BooleanAttribute.identifier,
+                             new BooleanAttributeProxy());
+      supportedDatatypes.put(StringAttribute.identifier,
+                             new StringAttributeProxy());
+      supportedDatatypes.put(DateAttribute.identifier,
+                             new DateAttributeProxy());
+      supportedDatatypes.put(TimeAttribute.identifier,
+                             new TimeAttributeProxy());
+      supportedDatatypes.put(DateTimeAttribute.identifier,
+                             new DateTimeAttributeProxy());
+      supportedDatatypes.put(DayTimeDurationAttribute.identifier,
+                             new DayTimeDurationAttributeProxy());
+      supportedDatatypes.put(YearMonthDurationAttribute.identifier,
+                             new YearMonthDurationAttributeProxy());
+      supportedDatatypes.put(DoubleAttribute.identifier,
+                             new DoubleAttributeProxy());
+      supportedDatatypes.put(IntegerAttribute.identifier,
+                             new IntegerAttributeProxy());
+      supportedDatatypes.put(AnyURIAttribute.identifier,
+                             new AnyURIAttributeProxy());
+      supportedDatatypes.put(HexBinaryAttribute.identifier,
+                             new HexBinaryAttributeProxy());
+      supportedDatatypes.put(Base64BinaryAttribute.identifier,
+                             new Base64BinaryAttributeProxy());
+      supportedDatatypes.put(X500NameAttribute.identifier,
+                             new X500NameAttributeProxy());
+      supportedDatatypes.put(RFC822NameAttribute.identifier,
+                             new RFC822NameAttributeProxy());
+ 
+      
+      // the 2.0 datatypes
+      supportedDatatypes.put(DNSNameAttribute.identifier,
+                             new DNSNameAttributeProxy());
+      supportedDatatypes.put(IPAddressAttribute.identifier,
+                             new IPAddressAttributeProxy());
+ 
+   }
+
+   public void addDatatype(String id, AttributeProxy proxy) 
+   {
+      supportedDatatypes.put(id, proxy); 
+  }
+
+   @Override
+   public AttributeValue createValue(URI dataType, String value) 
+   throws UnknownIdentifierException, ParsingException
+   {
+      try
+      {
+         return getProxy(dataType.toString()).getInstance(value);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      } 
+   }  
+   
+   @Override
+   public AttributeValue createValue(Node root, String type) throws UnknownIdentifierException, ParsingException
+   {
+      try
+      {
+         return getProxy(type).getInstance(root);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   @Override
+   public AttributeValue createValue(Node root, URI dataType) throws UnknownIdentifierException, ParsingException
+   {
+      return createValue(root, dataType.toString());
+   }
+ 
+
+   public static ExtendedAttributeFactory getFactory()
+   {
+      if(instance == null)
+         instance = new ExtendedAttributeFactory();
+      return instance;
+   }
+   
+   private AttributeProxy getProxy(String type)
+   {
+      AttributeProxy proxy =  (AttributeProxy) supportedDatatypes.get(type.toString()); 
+      if(proxy == null)
+         throw new RuntimeException("proxy null for "+type);
+      return proxy;
+   }
+}

Added: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactoryProxy.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactoryProxy.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/ExtendedAttributeFactoryProxy.java	2008-03-28 22:36:35 UTC (rev 71405)
@@ -0,0 +1,39 @@
+/*
+  * 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.security.xacml.core.ext;
+
+import org.jboss.security.xacml.sunxacml.attr.AttributeFactory;
+import org.jboss.security.xacml.sunxacml.attr.AttributeFactoryProxy;
+ 
+/**
+ *  
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 28, 2008 
+ *  @version $Revision$
+ */
+public class ExtendedAttributeFactoryProxy implements AttributeFactoryProxy
+{ 
+   public AttributeFactory getFactory()
+   { 
+      return ExtendedAttributeFactory.getFactory();
+   } 
+}

Added: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttribute.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttribute.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttribute.java	2008-03-28 22:36:35 UTC (rev 71405)
@@ -0,0 +1,53 @@
+/*
+  * 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.security.xacml.core.ext;
+
+import java.net.URI;
+
+import org.jboss.security.xacml.sunxacml.attr.AttributeValue;
+
+/**
+ *  Represents a custom attribute of single value
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 28, 2008 
+ *  @version $Revision$
+ */
+public class MultiValueAttribute extends AttributeValue
+{ 
+   private String value;
+
+   public MultiValueAttribute(URI type, String value)
+   {
+      super(type);
+      this.value = value;
+   }
+   protected MultiValueAttribute(URI type)
+   {
+      super(type); 
+   }
+
+   @Override
+   public String encode()
+   { 
+      return value;
+   } 
+}
\ No newline at end of file

Added: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttributeProxy.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttributeProxy.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/MultiValueAttributeProxy.java	2008-03-28 22:36:35 UTC (rev 71405)
@@ -0,0 +1,68 @@
+/*
+  * 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.security.xacml.core.ext;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.security.xacml.sunxacml.attr.AttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.AttributeValue;
+import org.w3c.dom.Node;
+ 
+
+/**
+ *  Represents a multi value attribute proxy
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 28, 2008 
+ *  @version $Revision$
+ */
+public class MultiValueAttributeProxy implements AttributeProxy
+{ 
+   private URI type;
+
+   public MultiValueAttributeProxy(String type)
+   {
+      try
+      {
+         this.type = new URI(type);
+      }
+      catch (URISyntaxException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public MultiValueAttributeProxy(URI type)
+   {
+      this.type = type;
+   }
+   
+   public AttributeValue getInstance(Node root) throws Exception
+   { 
+      return null;
+   }
+
+   public AttributeValue getInstance(String value) throws Exception
+   { 
+      return new SingleValueAttribute(type, value);
+   } 
+}

Added: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttribute.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttribute.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttribute.java	2008-03-28 22:36:35 UTC (rev 71405)
@@ -0,0 +1,53 @@
+/*
+  * 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.security.xacml.core.ext;
+
+import java.net.URI;
+
+import org.jboss.security.xacml.sunxacml.attr.AttributeValue;
+
+/**
+ *  Represents a custom attribute of single value
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 28, 2008 
+ *  @version $Revision$
+ */
+public class SingleValueAttribute extends AttributeValue
+{ 
+   private String value;
+
+   public SingleValueAttribute(URI type, String value)
+   {
+      super(type);
+      this.value = value;
+   }
+   protected SingleValueAttribute(URI type)
+   {
+      super(type); 
+   }
+
+   @Override
+   public String encode()
+   { 
+      return value;
+   } 
+}
\ No newline at end of file

Added: projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttributeProxy.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttributeProxy.java	                        (rev 0)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/org/jboss/security/xacml/core/ext/SingleValueAttributeProxy.java	2008-03-28 22:36:35 UTC (rev 71405)
@@ -0,0 +1,107 @@
+/*
+  * 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.security.xacml.core.ext;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.security.xacml.sunxacml.ParsingException;
+import org.jboss.security.xacml.sunxacml.UnknownIdentifierException;
+import org.jboss.security.xacml.sunxacml.attr.AttributeFactory;
+import org.jboss.security.xacml.sunxacml.attr.AttributeProxy;
+import org.jboss.security.xacml.sunxacml.attr.AttributeValue;
+import org.jboss.security.xacml.sunxacml.attr.StringAttribute;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+ 
+
+/**
+ *  Represents a single value attribute proxy
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 28, 2008 
+ *  @version $Revision$
+ */
+public class SingleValueAttributeProxy implements AttributeProxy
+{ 
+   private URI type;
+
+   public SingleValueAttributeProxy(String type)
+   {
+      try
+      {
+         this.type = new URI(type);
+      }
+      catch (URISyntaxException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public SingleValueAttributeProxy(URI type)
+   {
+      this.type = type;
+   }
+   
+   public AttributeValue getInstance(Node root) throws Exception
+   { 
+      // now we get the attribute value
+      if (getNodeName(root).equals("AttributeValue")) 
+      { 
+         // now get the value
+         try 
+         {
+            Node child = root.getFirstChild();
+            if(child == null)
+               return new StringAttribute("");
+           //get the type of the node
+            short nodetype = child.getNodeType();
+
+            // now see if we have (effectively) a simple string value
+            if ((nodetype == Node.TEXT_NODE) || (nodetype == Node.CDATA_SECTION_NODE) ||
+                (nodetype == Node.COMMENT_NODE)) 
+            {
+                return new StringAttribute(child.getNodeValue());
+            }
+            
+            return AttributeFactory.getInstance().createValue(child, type);
+         } 
+         catch (UnknownIdentifierException uie) 
+         {
+            throw new ParsingException("Unknown AttributeId", uie);
+         } 
+      }
+      return null;
+   }
+
+   public AttributeValue getInstance(String value) throws Exception
+   { 
+      return new SingleValueAttribute(type, value);
+   } 
+   
+   private static String getNodeName(Node node)
+   {
+      String name = node.getLocalName();
+      if(name == null)
+         name = node.getNodeName();
+      return name; 
+   } 
+}




More information about the jboss-cvs-commits mailing list