[jboss-cvs] JBossAS SVN: r86794 - in trunk: system-jmx/src/main/org/jboss/system/deployers/managed and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Apr 4 15:51:38 EDT 2009


Author: emuckenhuber
Date: 2009-04-04 15:51:38 -0400 (Sat, 04 Apr 2009)
New Revision: 86794

Modified:
   trunk/messaging/src/main/org/jboss/jms/server/destination/SecurityConfigMapper.java
   trunk/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java
Log:
[JBAS-6716] jms destination security config

Modified: trunk/messaging/src/main/org/jboss/jms/server/destination/SecurityConfigMapper.java
===================================================================
--- trunk/messaging/src/main/org/jboss/jms/server/destination/SecurityConfigMapper.java	2009-04-04 18:53:18 UTC (rev 86793)
+++ trunk/messaging/src/main/org/jboss/jms/server/destination/SecurityConfigMapper.java	2009-04-04 19:51:38 UTC (rev 86794)
@@ -86,7 +86,7 @@
       if(object == null)
          return null;
       
-      Map<String, CompositeValue> entries = new HashMap<String, CompositeValue>();
+      Map<String, MetaValue> entries = new HashMap<String, MetaValue>();
       // Parse
       NodeList list = object.getElementsByTagName("role");
       int l = list.getLength();
@@ -103,7 +103,7 @@
          // Put
          entries.put(name, new CompositeValueSupport(composite, values));
       }
-      return new MapCompositeValueSupport(metaType);
+      return new MapCompositeValueSupport(entries, metaType);
    }
 
    @Override
@@ -163,20 +163,19 @@
       Map<String, MetaValue> map = new HashMap<String, MetaValue>();
       for(String attribute : attributeNames)
       {
-         SimpleValue v = parseAttribute(attribute, element);
-         if(v != null) map.put(attribute, v);
+         map.put(attribute, parseAttribute(attribute, element));
       }
       return map;
    }
    
    protected static SimpleValue parseAttribute(String attributeName, Element element)
    {
+      Boolean value = null;
       if(element.getAttributeNode(attributeName) != null)
       {
-         Boolean value = Boolean.valueOf(element.getAttribute(attributeName));
-         return new SimpleValueSupport(SimpleMetaType.BOOLEAN, value);         
+         value = Boolean.valueOf(element.getAttribute(attributeName));
       }
-      return null;
+      return new SimpleValueSupport(SimpleMetaType.BOOLEAN, value);
    }
    
 }

Modified: trunk/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java	2009-04-04 18:53:18 UTC (rev 86793)
+++ trunk/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java	2009-04-04 19:51:38 UTC (rev 86794)
@@ -35,14 +35,18 @@
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.spi.factory.InstanceClassFactory;
 import org.jboss.metadata.spi.MetaData;
+import org.jboss.metatype.api.types.MetaType;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.spi.values.MetaMapper;
 import org.jboss.system.metadata.ServiceAnnotationMetaData;
 import org.jboss.system.metadata.ServiceAttributeMetaData;
 import org.jboss.system.metadata.ServiceDependencyValueMetaData;
+import org.jboss.system.metadata.ServiceElementValueMetaData;
 import org.jboss.system.metadata.ServiceMetaData;
 import org.jboss.system.metadata.ServiceTextValueMetaData;
 import org.jboss.system.metadata.ServiceValueMetaData;
+import org.w3c.dom.Element;
 
 /**
  * The InstanceClassFactory implementation for ServiceMetaData.
@@ -188,12 +192,24 @@
             ServiceDependencyValueMetaData depends = (ServiceDependencyValueMetaData) value;
             value = depends.getDependency();
          }
+         else if (value instanceof ServiceElementValueMetaData)
+         {
+            value = ((ServiceElementValueMetaData)value).getElement();
+         }
          // TODO: unwrap other ServiceValueMetaData types
    
          PropertyInfo propertyInfo = beanInfo.getProperty(name);
+         MetaMapper metaMapper = property.getTransientAttachment(MetaMapper.class);
          try
          {
-            mvalue = metaValueFactory.create(value, propertyInfo.getType());
+            if(metaMapper != null)
+            {
+               mvalue = metaMapper.createMetaValue(property.getMetaType(), value);
+            }
+            else
+            {
+               mvalue = metaValueFactory.create(value, propertyInfo.getType());
+            }
          }
          catch(Exception e)
          {
@@ -239,17 +255,10 @@
                break;
             }
          }
-
-         // Unwrap
-         PropertyInfo propertyInfo = beanInfo.getProperty(name);
-         Object plainValue = metaValueFactory.unwrap(value, propertyInfo.getType());
+         // There may not be an attribute value, see if there is a matching property
          
-         // There may not be an attribute value, see if there is a matching property
          if (attributeValue == null)
          {
-            // FIXME ignore null values
-            if(plainValue == null) return;
-            
             String aname = mapAttributeName(md, name);
             if(aname != null)
             {
@@ -262,16 +271,36 @@
          }
          if (attributeValue != null)
          {
+            Object plainValue = null;
+            // Look for a MetaMapper
+            MetaType propertyType = property.getMetaType();
+            MetaMapper metaMapper = property.getTransientAttachment(MetaMapper.class);
+            if(metaMapper != null)
+            {
+               plainValue = metaMapper.unwrapMetaValue(value);
+            }
+            else
+            {
+               PropertyInfo propertyInfo = beanInfo.getProperty(name);
+               plainValue = metaValueFactory.unwrap(value, propertyInfo.getType());
+            }
             // Unwrap the ServiceValueMetaData types
             if (attributeValue instanceof ServiceTextValueMetaData)
             {
                ServiceTextValueMetaData text = (ServiceTextValueMetaData) attributeValue;
                text.setText(String.valueOf(plainValue));
             }
-            else if (value instanceof ServiceDependencyValueMetaData)
+            else if (attributeValue instanceof ServiceElementValueMetaData)
             {
+               ((ServiceElementValueMetaData) attributeValue).setElement((Element) plainValue);
+            }
+            else if (attributeValue instanceof ServiceDependencyValueMetaData)
+            {
                ServiceDependencyValueMetaData depends = (ServiceDependencyValueMetaData) attributeValue;
-               depends.setDependency(String.valueOf(plainValue));
+               if (plainValue instanceof ObjectName)
+                  depends.setObjectName((ObjectName) plainValue);
+               else
+                  depends.setDependency(String.valueOf(plainValue));
             }
             // TODO: unwrap other ServiceValueMetaData types
             else
@@ -292,6 +321,10 @@
       }
    }
 
+   /**
+    * The service context uses the canonical object name string
+    * @return the service metadata canonical object name string
+    */
    public Object getComponentName(BeanInfo beanInfo, ManagedProperty property, ServiceMetaData md, MetaValue value)
    {
       ObjectName objectName = md.getObjectName();

Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java	2009-04-04 18:53:18 UTC (rev 86793)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java	2009-04-04 19:51:38 UTC (rev 86794)
@@ -35,10 +35,15 @@
 import org.jboss.managed.api.DeploymentTemplateInfo;
 import org.jboss.managed.api.ManagedComponent;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
 import org.jboss.metatype.api.types.MetaType;
 import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
 import org.jboss.metatype.api.values.MetaValue;
 import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.plugins.types.MutableCompositeMetaType;
 
 /**
  * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
@@ -47,6 +52,24 @@
  */
 public class JmsDestinationUnitTestCase extends AbstractProfileServiceTest
 {
+   
+   /** The meta type. */
+   protected static final MapCompositeMetaType securityConfType;
+   
+   /** The composite meta type. */
+   public static MutableCompositeMetaType composite;
+   
+   static
+   {
+      // Create the meta type
+      composite = new MutableCompositeMetaType("SecurityConfig", "The security config");
+      composite.addItem("read", "read permission", SimpleMetaType.BOOLEAN);
+      composite.addItem("write", "write permission", SimpleMetaType.BOOLEAN);
+      composite.addItem("create", "create permission", SimpleMetaType.BOOLEAN);
+      composite.freeze();
+      securityConfType = new MapCompositeMetaType(composite);
+   }
+   
    public JmsDestinationUnitTestCase(String s)
    {
       super(s);
@@ -61,6 +84,8 @@
       suite.addTest(new JmsDestinationUnitTestCase("testDLQ"));
       suite.addTest(new JmsDestinationUnitTestCase("testCreateQueue"));
       suite.addTest(new JmsDestinationUnitTestCase("testRemoveQueue"));
+      suite.addTest(new JmsDestinationUnitTestCase("testCreateSecureQueue"));
+      suite.addTest(new JmsDestinationUnitTestCase("testRemoveSecureQueue"));
       suite.addTest(new JmsDestinationUnitTestCase("testCreateTopic"));
       suite.addTest(new JmsDestinationUnitTestCase("testRemoveTopic"));
 
@@ -238,4 +263,48 @@
       ManagedComponent topic = getManagementView().getComponent("testCreateTopic", type);
       assertNull("topic should be removed " + topic, topic);
    }
+   
+   public void testCreateSecureQueue() throws Exception
+   {
+      Map<String, MetaValue> propValues = new HashMap<String, MetaValue>();
+      String jndiName = getName();
+      propValues.put("name", SimpleValueSupport.wrap(jndiName));
+      propValues.put("JNDIName", SimpleValueSupport.wrap(jndiName));
+      // Security config
+      Map<String, MetaValue> values = new HashMap<String, MetaValue>();
+      values.put("admin", createCompositeValue(true, true, true));
+      values.put("publisher", createCompositeValue(true, true, false));
+      values.put("user", createCompositeValue(true, null, null));
+      CompositeValue map = new MapCompositeValueSupport(values, securityConfType);
+      propValues.put("securityConfig", map);
+      
+      ComponentType type = KnownComponentTypes.JMSDestination.Queue.getType();
+      createComponentTest("QueueTemplate", propValues, getName(), type, jndiName);
+      ManagedComponent queue = activeView.getComponent("testCreateSecureQueue", type);
+      assertNotNull(queue);
+      assertEquals("testCreateSecureQueue", queue.getName());
+      log.info(queue.getProperties().keySet());
+      assertNotNull(queue.getProperty("securityConfig").getValue());
+      
+   }
+   
+   public void testRemoveSecureQueue() throws Exception
+   {
+      removeDeployment("testCreateSecureQueue-service.xml");
+      ComponentType type = KnownComponentTypes.JMSDestination.Queue.getType();
+       ManagedComponent queue = getManagementView().getComponent("testCreateSecureQueue", type);
+      assertNull("queue should be removed" + queue, queue);
+   }
+   
+   
+   protected CompositeValue createCompositeValue(Boolean read, Boolean write, Boolean create)
+   {
+      Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+      
+      map.put("read", new SimpleValueSupport(SimpleMetaType.BOOLEAN, read));
+      map.put("write", new SimpleValueSupport(SimpleMetaType.BOOLEAN, write));
+      map.put("create", new SimpleValueSupport(SimpleMetaType.BOOLEAN, create));
+      
+      return new CompositeValueSupport(composite, map);
+   }
 }




More information about the jboss-cvs-commits mailing list