[hornetq-commits] JBoss hornetq SVN: r8929 - in trunk: src/main/org/hornetq/api/jms/management and 7 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Mar 16 17:50:14 EDT 2010


Author: ataylor
Date: 2010-03-16 17:50:12 -0400 (Tue, 16 Mar 2010)
New Revision: 8929

Added:
   trunk/src/main/org/hornetq/utils/SecurityFormatter.java
Modified:
   trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java
   trunk/src/main/org/hornetq/api/jms/management/JMSQueueControl.java
   trunk/src/main/org/hornetq/api/jms/management/JMSServerControl.java
   trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java
   trunk/src/main/org/hornetq/jms/management/impl/JMSQueueControlImpl.java
   trunk/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java
   trunk/src/main/org/hornetq/jms/server/JMSServerManager.java
   trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
   trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java
   trunk/tests/src/org/hornetq/tests/unit/core/deployers/impl/QueueDeployerTest.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-288 - added address settings stuff to management api + some tweaks

Modified: trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java
===================================================================
--- trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -17,7 +17,12 @@
 
 import org.hornetq.api.core.HornetQException;
 import org.hornetq.api.core.Interceptor;
+import org.hornetq.core.settings.impl.AddressFullMessagePolicy;
+import org.hornetq.core.settings.impl.AddressSettings;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * A HornetQServerControl is used to manage HornetQ servers.
  */
@@ -487,10 +492,17 @@
                             @Parameter(desc="a comma-separated list of roles allowed to create temporary queues", name="createTempQueueRoles") String createTempQueueRoles,
                             @Parameter(desc="a comma-separated list of roles allowed to delete temporary queues", name="deleteTempQueueRoles") String deleteTempQueueRoles,
                             @Parameter(desc="a comma-separated list of roles allowed to send management messages messages", name="manage") String manageRoles) throws Exception;
-   
-   void removeSecuritySettings(String addressMatch) throws Exception;
 
-   Object[] getRoles(String addressMatch) throws Exception;
+   @Operation(desc = "Remove security settings for an address", impact = MBeanOperationInfo.ACTION)
+   void removeSecuritySettings(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;
 
-   String getRolesAsJSON(String addressMatch) throws Exception;
+   @Operation(desc = "get roles for a specific address match", impact = MBeanOperationInfo.INFO)
+   Object[] getRoles(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;
+
+   @Operation(desc = "get roles (as a JSON string) for a specific address match", impact = MBeanOperationInfo.INFO)
+   String getRolesAsJSON(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;
+
+   @Operation(desc = "get address settings (as a JSON string) for a specific address match", impact = MBeanOperationInfo.INFO)
+   String getAddressSettingsAsJSON(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;
+
 }

Modified: trunk/src/main/org/hornetq/api/jms/management/JMSQueueControl.java
===================================================================
--- trunk/src/main/org/hornetq/api/jms/management/JMSQueueControl.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/api/jms/management/JMSQueueControl.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -69,6 +69,11 @@
     */
    int getDeliveringCount();
 
+   /**
+    * returns the selector for the queue
+    */
+   String getSelector();
+
    // Operations ----------------------------------------------------
 
    /**

Modified: trunk/src/main/org/hornetq/api/jms/management/JMSServerControl.java
===================================================================
--- trunk/src/main/org/hornetq/api/jms/management/JMSServerControl.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/api/jms/management/JMSServerControl.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -21,6 +21,7 @@
 import org.hornetq.api.core.client.ClientSessionFactory;
 import org.hornetq.api.core.management.Operation;
 import org.hornetq.api.core.management.Parameter;
+import org.hornetq.core.settings.impl.AddressSettings;
 import org.hornetq.spi.core.remoting.ConnectorFactory;
 
 /**
@@ -200,4 +201,45 @@
     */
    @Operation(desc = "List the sessions for the given connectionID", impact = MBeanOperationInfo.INFO)
    String[] listSessions(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception;
+
+   /**
+    * adds a new address setting for a specific address
+    */
+   @Operation(desc= "Add address settings for addresses matching the addressMatch", impact = MBeanOperationInfo.ACTION)
+   void addAddressSettings(@Parameter(desc="an address match", name="addressMatch") String addressMatch,
+                           @Parameter(desc="the dead letter address setting", name="DLA") String DLA,
+                           @Parameter(desc="the expiry address setting", name="expiryAddress") String expiryAddress,
+                           @Parameter(desc="are any queues created for this address a last value queue", name="lastValueQueue") boolean lastValueQueue,
+                           @Parameter(desc="the delivery attempts", name="deliveryAttempts") int deliveryAttempts,
+                           @Parameter(desc="the max size in bytes", name="maxSizeBytes") long maxSizeBytes,
+                           @Parameter(desc="the page size in bytes", name="pageSizeBytes") int pageSizeBytes,
+                           @Parameter(desc="the redelivery delay", name="redeliveryDelay") long redeliveryDelay,
+                           @Parameter(desc="the redistribution delay", name="redistributionDelay") long redistributionDelay,
+                           @Parameter(desc="do we send to the DLA when there is no where to route the message", name="sendToDLAOnNoRoute") boolean sendToDLAOnNoRoute,
+                           @Parameter(desc="the ploicy to use when the address is full", name="addressFullMessagePolicy") String addressFullMessagePolicy) throws Exception;
+
+   AddressSettings getAddressSettings(String address);
+
+   /**
+    * returns the address settings as a JSON string
+    */
+   @Operation(desc = "returns the address settings as a JSON string for an address match", impact = MBeanOperationInfo.INFO)
+   String getAddressSettingsAsJSON(@Parameter(desc="an address match", name="addressMatch") String addressMatch) throws Exception;
+
+   @Operation(desc= "Add security settings for addresses matching the addressMatch", impact = MBeanOperationInfo.ACTION)
+   void addSecuritySettings(
+                            @Parameter(desc="an address match", name="addressMatch") String addressMatch,
+                            @Parameter(desc="a comma-separated list of roles allowed to send messages", name="send") String sendRoles,
+                            @Parameter(desc="a comma-separated list of roles allowed to consume messages", name="consume") String consumeRoles,
+                            @Parameter(desc="a comma-separated list of roles allowed to create durable queues", name="createDurableQueueRoles") String createDurableQueueRoles,
+                            @Parameter(desc="a comma-separated list of roles allowed to delete durable queues", name="deleteDurableQueueRoles") String deleteDurableQueueRoles,
+                            @Parameter(desc="a comma-separated list of roles allowed to create temporary queues", name="createTempQueueRoles") String createTempQueueRoles,
+                            @Parameter(desc="a comma-separated list of roles allowed to delete temporary queues", name="deleteTempQueueRoles") String deleteTempQueueRoles,
+                            @Parameter(desc="a comma-separated list of roles allowed to send management messages messages", name="manage") String manageRoles) throws Exception;
+
+   /**
+    * removes the address settings as a JSON string
+    */
+   @Operation(desc = "removes the address settings for an address match", impact = MBeanOperationInfo.INFO)
+   void removeSecuritySettings(@Parameter(desc="an address match", name="addressMatch") String addressMatch) throws Exception;
 }

Modified: trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -14,15 +14,7 @@
 package org.hornetq.core.management.impl;
 
 import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.Map.Entry;
 
 import javax.management.ListenerNotFoundException;
@@ -53,10 +45,13 @@
 import org.hornetq.core.server.HornetQServer;
 import org.hornetq.core.server.JournalType;
 import org.hornetq.core.server.ServerSession;
+import org.hornetq.core.settings.impl.AddressFullMessagePolicy;
+import org.hornetq.core.settings.impl.AddressSettings;
 import org.hornetq.core.transaction.ResourceManager;
 import org.hornetq.core.transaction.Transaction;
 import org.hornetq.core.transaction.impl.XidImpl;
 import org.hornetq.spi.core.protocol.RemotingConnection;
+import org.hornetq.utils.SecurityFormatter;
 import org.hornetq.utils.json.JSONArray;
 import org.hornetq.utils.json.JSONObject;
 
@@ -90,20 +85,6 @@
 
    // Static --------------------------------------------------------
 
-   private static List<String> toList(final String commaSeparatedString)
-   {
-      List<String> list = new ArrayList<String>();
-      if (commaSeparatedString == null || commaSeparatedString.trim().length() == 0)
-      {
-         return list;
-      }
-      String[] values = commaSeparatedString.split(",");
-      for (int i = 0; i < values.length; i++)
-      {
-         list.add(values[i].trim());
-      }
-      return list;
-   }
    
    // Constructors --------------------------------------------------
 
@@ -1084,36 +1065,8 @@
       clearIO();
       try
       {
-         List<String> createDurableQueue = toList(createDurableQueueRoles);
-         List<String> deleteDurableQueue = toList(deleteDurableQueueRoles);
-         List<String> createTempQueue = toList(createTempQueueRoles);
-         List<String> deleteTempQueue = toList(deleteTempQueueRoles);
-         List<String> send = toList(sendRoles);
-         List<String> consume = toList(consumeRoles);
-         List<String> manage = toList(manageRoles); 
+         Set<Role> roles = SecurityFormatter.createSecurity(sendRoles, consumeRoles, createDurableQueueRoles, deleteDurableQueueRoles, createTempQueueRoles, deleteTempQueueRoles, manageRoles);
 
-         Set<String> allRoles = new HashSet<String>();
-         allRoles.addAll(createDurableQueue);
-         allRoles.addAll(deleteDurableQueue);
-         allRoles.addAll(createTempQueue);
-         allRoles.addAll(deleteTempQueue);
-         allRoles.addAll(send);
-         allRoles.addAll(consume);
-         allRoles.addAll(manage);
-
-         Set<Role> roles = new HashSet<Role>();
-         for (String role : allRoles)
-         {
-            roles.add(new Role(role,
-                               send.contains(role),
-                               consume.contains(role),
-                               createDurableQueue.contains(role),
-                               deleteDurableQueue.contains(role),
-                               createTempQueue.contains(role),
-                               deleteTempQueue.contains(role),
-                               manageRoles.contains(role)));
-         }
-
          server.getSecurityRepository().addMatch(addressMatch, roles );
       }
       finally
@@ -1122,6 +1075,7 @@
       }
    }
 
+
    public void removeSecuritySettings(String addressMatch)
    {
       clearIO();
@@ -1184,6 +1138,32 @@
       }
    }
 
+   public String getAddressSettingsAsJSON(final String address) throws Exception
+   {
+      AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(address);
+      Map<String, Object> settings = new HashMap<String, Object>();
+      if(addressSettings.getDeadLetterAddress() != null)
+      {
+         settings.put("DLA", addressSettings.getDeadLetterAddress());
+      }
+      if(addressSettings.getExpiryAddress() != null)
+      {
+         settings.put("expiryAddress", addressSettings.getExpiryAddress());
+      }
+      settings.put("maxDeliveryAttempts", addressSettings.getMaxDeliveryAttempts());
+      settings.put("maxSizeBytes", addressSettings.getMaxSizeBytes());
+      settings.put("pageSizeBytes", addressSettings.getPageSizeBytes());
+      settings.put("redeliveryDelay", addressSettings.getRedeliveryDelay());
+      settings.put("redistributionDelay", addressSettings.getRedistributionDelay());
+      settings.put("lastValueQueue", addressSettings.isLastValueQueue());
+      settings.put("sendToDLAOnNoRoute", addressSettings.isSendToDLAOnNoRoute());
+      String policy = addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.PAGE?"PAGE":addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.BLOCK?"BLOCK":"DROP";
+      settings.put("addressFullMessagePolicy", policy);
+
+      JSONObject jsonObject = new JSONObject(settings);
+      return jsonObject.toString();
+   }
+
    public void sendQueueInfoToQueue(final String queueName, final String address) throws Exception
    {
       clearIO();

Modified: trunk/src/main/org/hornetq/jms/management/impl/JMSQueueControlImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/management/impl/JMSQueueControlImpl.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/jms/management/impl/JMSQueueControlImpl.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -339,6 +339,11 @@
       coreQueueControl.resume();
    }
 
+   public String getSelector()
+   {
+      return coreQueueControl.getFilter();
+   }
+
    @Override
    public MBeanInfo getMBeanInfo()
    {

Modified: trunk/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -13,9 +13,7 @@
 
 package org.hornetq.jms.management.impl;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicLong;
 
 import javax.management.ListenerNotFoundException;
@@ -29,14 +27,21 @@
 import javax.management.StandardMBean;
 
 import org.hornetq.api.core.Pair;
+import org.hornetq.api.core.SimpleString;
 import org.hornetq.api.core.TransportConfiguration;
 import org.hornetq.api.core.management.ManagementHelper;
+import org.hornetq.api.core.management.Parameter;
 import org.hornetq.api.jms.management.ConnectionFactoryControl;
 import org.hornetq.api.jms.management.JMSQueueControl;
 import org.hornetq.api.jms.management.JMSServerControl;
 import org.hornetq.api.jms.management.TopicControl;
 import org.hornetq.core.management.impl.MBeanInfoHelper;
+import org.hornetq.core.security.Role;
+import org.hornetq.core.settings.impl.AddressFullMessagePolicy;
+import org.hornetq.core.settings.impl.AddressSettings;
 import org.hornetq.jms.server.JMSServerManager;
+import org.hornetq.jms.server.config.JMSQueueConfiguration;
+import org.hornetq.utils.SecurityFormatter;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -367,6 +372,76 @@
       return server.listSessions(connectionID);
    }
 
+
+   public void addAddressSettings(final String address,
+                                  final String DLA,
+                                  final String expiryAddress,
+                                  final boolean lastValueQueue,
+                                  final int deliveryAttempts,
+                                  final long maxSizeBytes,
+                                  final int pageSizeBytes,
+                                  final long redeliveryDelay,
+                                  final long redistributionDelay,
+                                  final boolean sendToDLAOnNoRoute,
+                                  final String addressFullMessagePolicy) throws Exception
+   {
+      AddressSettings addressSettings = new AddressSettings();
+      addressSettings.setDeadLetterAddress(DLA == null?null:new SimpleString(DLA));
+      addressSettings.setExpiryAddress(expiryAddress == null?null:new SimpleString(expiryAddress));
+      addressSettings.setLastValueQueue(lastValueQueue);
+      addressSettings.setMaxDeliveryAttempts(deliveryAttempts);
+      addressSettings.setMaxSizeBytes(maxSizeBytes);
+      addressSettings.setPageSizeBytes(pageSizeBytes);
+      addressSettings.setRedeliveryDelay(redeliveryDelay);
+      addressSettings.setRedistributionDelay(redistributionDelay);
+      addressSettings.setSendToDLAOnNoRoute(sendToDLAOnNoRoute);
+      if(addressFullMessagePolicy == null)
+      {
+         addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
+      }
+      else if(addressFullMessagePolicy.equalsIgnoreCase("PAGE"))
+      {
+         addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
+      }
+      else if(addressFullMessagePolicy.equalsIgnoreCase("DROP"))
+      {
+         addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.DROP);
+      }
+      else if(addressFullMessagePolicy.equalsIgnoreCase("BLOCK"))
+      {
+         addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
+      }
+      server.addAddressSettings(address, addressSettings);
+   }
+
+   public AddressSettings getAddressSettings(final String address)
+   {
+      return server.getAddressSettings(address);
+   }
+
+   public String getAddressSettingsAsJSON(final String address) throws Exception
+   {
+      return server.getHornetQServer().getHornetQServerControl().getAddressSettingsAsJSON(address);
+   }
+
+   public void addSecuritySettings(final String addressMatch,
+                                   final String sendRoles,
+                                   final String consumeRoles,
+                                   final String createDurableQueueRoles,
+                                   final String deleteDurableQueueRoles,
+                                   final String createTempQueueRoles,
+                                   final String deleteTempQueueRoles,
+                                   final String manageRoles) throws Exception
+   {
+         Set<Role> roles = SecurityFormatter.createSecurity(sendRoles, consumeRoles, createDurableQueueRoles, deleteDurableQueueRoles, createTempQueueRoles, deleteTempQueueRoles, manageRoles);
+         server.addSecurity(addressMatch, roles);
+   }
+
+   public void removeSecuritySettings(String addressMatch) throws Exception
+   {
+      //To change body of implemented methods use File | Settings | File Templates.
+   }
+
    @Override
    public MBeanInfo getMBeanInfo()
    {
@@ -403,4 +478,18 @@
       CONNECTION_FACTORY_DESTROYED;
    }
 
+    private static List<String> toList(final String commaSeparatedString)
+   {
+      List<String> list = new ArrayList<String>();
+      if (commaSeparatedString == null || commaSeparatedString.trim().length() == 0)
+      {
+         return list;
+      }
+      String[] values = commaSeparatedString.split(",");
+      for (int i = 0; i < values.length; i++)
+      {
+         list.add(values[i].trim());
+      }
+      return list;
+   }
 }

Modified: trunk/src/main/org/hornetq/jms/server/JMSServerManager.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/JMSServerManager.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/jms/server/JMSServerManager.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -14,13 +14,16 @@
 package org.hornetq.jms.server;
 
 import java.util.List;
+import java.util.Set;
 
 import javax.naming.Context;
 
 import org.hornetq.api.core.Pair;
 import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.core.security.Role;
 import org.hornetq.core.server.HornetQComponent;
 import org.hornetq.core.server.HornetQServer;
+import org.hornetq.core.settings.impl.AddressSettings;
 import org.hornetq.jms.server.config.ConnectionFactoryConfiguration;
 
 /**
@@ -230,4 +233,10 @@
    void setContext(final Context context);
 
    HornetQServer getHornetQServer();
+
+   void addAddressSettings(String address, AddressSettings addressSettings);
+
+   AddressSettings getAddressSettings(String address);
+
+   void addSecurity(String addressMatch, Set<Role> roles);
 }

Modified: trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -13,12 +13,7 @@
 
 package org.hornetq.jms.server.impl;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -40,8 +35,10 @@
 import org.hornetq.core.logging.Logger;
 import org.hornetq.core.postoffice.Binding;
 import org.hornetq.core.postoffice.BindingType;
+import org.hornetq.core.security.Role;
 import org.hornetq.core.server.ActivateCallback;
 import org.hornetq.core.server.HornetQServer;
+import org.hornetq.core.settings.impl.AddressSettings;
 import org.hornetq.jms.client.HornetQConnectionFactory;
 import org.hornetq.jms.client.HornetQDestination;
 import org.hornetq.jms.client.SelectorTranslator;
@@ -244,6 +241,21 @@
       return server;
    }
 
+   public void addAddressSettings(final String address, final AddressSettings addressSettings)
+   {
+      server.getAddressSettingsRepository().addMatch(address, addressSettings);
+   }
+
+   public AddressSettings getAddressSettings(final String address)
+   {
+      return server.getAddressSettingsRepository().getMatch(address);
+   }
+
+   public void addSecurity(final String addressMatch, final Set<Role> roles)
+   {
+      server.getSecurityRepository().addMatch(addressMatch, roles);
+   }
+
    public synchronized void setContext(final Context context)
    {
       this.context = context;
@@ -786,7 +798,6 @@
       checkInitialised();
       return server.getHornetQServerControl().listSessions(connectionID);
    }
-
    // Public --------------------------------------------------------
 
    // Private -------------------------------------------------------

Added: trunk/src/main/org/hornetq/utils/SecurityFormatter.java
===================================================================
--- trunk/src/main/org/hornetq/utils/SecurityFormatter.java	                        (rev 0)
+++ trunk/src/main/org/hornetq/utils/SecurityFormatter.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.utils;
+
+import org.hornetq.core.security.Role;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class SecurityFormatter
+{
+   public static Set<Role> createSecurity(String sendRoles, String consumeRoles, String createDurableQueueRoles, String deleteDurableQueueRoles, String createTempQueueRoles, String deleteTempQueueRoles, String manageRoles)
+   {
+      List<String> createDurableQueue = toList(createDurableQueueRoles);
+      List<String> deleteDurableQueue = toList(deleteDurableQueueRoles);
+      List<String> createTempQueue = toList(createTempQueueRoles);
+      List<String> deleteTempQueue = toList(deleteTempQueueRoles);
+      List<String> send = toList(sendRoles);
+      List<String> consume = toList(consumeRoles);
+      List<String> manage = toList(manageRoles);
+
+      Set<String> allRoles = new HashSet<String>();
+      allRoles.addAll(createDurableQueue);
+      allRoles.addAll(deleteDurableQueue);
+      allRoles.addAll(createTempQueue);
+      allRoles.addAll(deleteTempQueue);
+      allRoles.addAll(send);
+      allRoles.addAll(consume);
+      allRoles.addAll(manage);
+
+      Set<Role> roles = new HashSet<Role>();
+      for (String role : allRoles)
+      {
+         roles.add(new Role(role,
+             send.contains(role),
+             consume.contains(role),
+             createDurableQueue.contains(role),
+             deleteDurableQueue.contains(role),
+             createTempQueue.contains(role),
+             deleteTempQueue.contains(role),
+             manageRoles.contains(role)));
+      }
+      return roles;
+   }
+
+
+   private static List<String> toList(final String commaSeparatedString)
+   {
+      List<String> list = new ArrayList<String>();
+      if (commaSeparatedString == null || commaSeparatedString.trim().length() == 0)
+      {
+         return list;
+      }
+      String[] values = commaSeparatedString.split(",");
+      for (int i = 0; i < values.length; i++)
+      {
+         list.add(values[i].trim());
+      }
+      return list;
+   }
+}

Modified: trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -18,6 +18,7 @@
 import org.hornetq.api.core.client.ClientSessionFactory;
 import org.hornetq.api.core.client.HornetQClient;
 import org.hornetq.api.core.management.HornetQServerControl;
+import org.hornetq.api.core.management.Parameter;
 import org.hornetq.api.core.management.ResourceNames;
 import org.hornetq.core.config.Configuration;
 import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
@@ -476,6 +477,11 @@
          {
             return (String)proxy.invokeOperation("getRolesAsJSON", addressMatch);
          }
+
+         public String getAddressSettingsAsJSON(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception
+         {
+            return (String)proxy.invokeOperation("getAddressSettingsAsJSON", addressMatch);
+         }
       };
    }
    // Package protected ---------------------------------------------

Modified: trunk/tests/src/org/hornetq/tests/unit/core/deployers/impl/QueueDeployerTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/deployers/impl/QueueDeployerTest.java	2010-03-16 18:24:13 UTC (rev 8928)
+++ trunk/tests/src/org/hornetq/tests/unit/core/deployers/impl/QueueDeployerTest.java	2010-03-16 21:50:12 UTC (rev 8929)
@@ -19,6 +19,7 @@
 import junit.framework.Assert;
 
 import org.hornetq.api.core.management.HornetQServerControl;
+import org.hornetq.api.core.management.Parameter;
 import org.hornetq.core.config.Configuration;
 import org.hornetq.core.config.CoreQueueConfiguration;
 import org.hornetq.core.deployers.DeploymentManager;
@@ -586,6 +587,10 @@
          return null;
       }
 
+      public String getAddressSettingsAsJSON(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception
+      {
+         return null;  //To change body of implemented methods use File | Settings | File Templates.
+      }
    }
 
 }



More information about the hornetq-commits mailing list