[hornetq-commits] JBoss hornetq SVN: r8879 - in trunk: src/main/org/hornetq/core/management/impl and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Feb 16 08:49:27 EST 2010
Author: jmesnil
Date: 2010-02-16 08:49:25 -0500 (Tue, 16 Feb 2010)
New Revision: 8879
Modified:
trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java
trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java
trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlTest.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-300: SecuritySettings should be manageable via the management API
* added management methods to HornetQServerControl to add/remove/get security settings corresponding to an address match
Modified: trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java
===================================================================
--- trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java 2010-02-16 09:50:10 UTC (rev 8878)
+++ trunk/src/main/org/hornetq/api/core/management/HornetQServerControl.java 2010-02-16 13:49:25 UTC (rev 8879)
@@ -477,4 +477,20 @@
*/
void sendQueueInfoToQueue(String queueName, String address) 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 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 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 send management messages messages", name="manage") String manageRoles) throws Exception;
+
+ void removeSecuritySettings(String addressMatch) throws Exception;
+
+ Object[] getRoles(String addressMatch) throws Exception;
+
+ String getRolesAsJSON(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-02-16 09:50:10 UTC (rev 8878)
+++ trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java 2010-02-16 13:49:25 UTC (rev 8879)
@@ -19,6 +19,7 @@
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;
@@ -47,6 +48,8 @@
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.PostOffice;
import org.hornetq.core.remoting.server.RemotingService;
+import org.hornetq.core.security.CheckType;
+import org.hornetq.core.security.Role;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.JournalType;
import org.hornetq.core.server.ServerSession;
@@ -87,6 +90,21 @@
// 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 --------------------------------------------------
public HornetQServerControlImpl(final PostOffice postOffice,
@@ -1053,7 +1071,119 @@
blockOnIO();
}
}
+
+ public void addSecuritySettings(String addressMatch,
+ String createDurableQueueRoles,
+ String deleteDurableQueueRoles,
+ String createTempQueueRoles,
+ String deleteTempQueueRoles,
+ String sendRoles,
+ String consumeRoles,
+ String manageRoles)
+ {
+ 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<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
+ {
+ blockOnIO();
+ }
+ }
+
+ public void removeSecuritySettings(String addressMatch)
+ {
+ clearIO();
+ try
+ {
+ server.getSecurityRepository().removeMatch(addressMatch);
+ }
+ finally
+ {
+ blockOnIO();
+ }
+ }
+
+ public Object[] getRoles(String addressMatch) throws Exception
+ {
+ clearIO();
+ try
+ {
+ Set<Role> roles = server.getSecurityRepository().getMatch(addressMatch);
+
+ Object[] objRoles = new Object[roles.size()];
+
+ int i = 0;
+ for (Role role : roles)
+ {
+ objRoles[i++] = new Object[] { role.getName(),
+ CheckType.SEND.hasRole(role),
+ CheckType.CONSUME.hasRole(role),
+ CheckType.CREATE_DURABLE_QUEUE.hasRole(role),
+ CheckType.DELETE_DURABLE_QUEUE.hasRole(role),
+ CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role),
+ CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role),
+ CheckType.MANAGE.hasRole(role) };
+ }
+ return objRoles;
+ }
+ finally
+ {
+ blockOnIO();
+ }
+ }
+
+ public String getRolesAsJSON(String addressMatch) throws Exception
+ {
+ clearIO();
+ try
+ {
+ JSONArray json = new JSONArray();
+ Set<Role> roles = server.getSecurityRepository().getMatch(addressMatch);
+
+ for (Role role : roles)
+ {
+ json.put(new JSONObject(role));
+ }
+ return json.toString();
+ }
+ finally
+ {
+ blockOnIO();
+ }
+ }
+
public void sendQueueInfoToQueue(final String queueName, final String address) throws Exception
{
clearIO();
Modified: trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlTest.java 2010-02-16 09:50:10 UTC (rev 8878)
+++ trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlTest.java 2010-02-16 13:49:25 UTC (rev 8879)
@@ -23,6 +23,7 @@
import org.hornetq.api.core.management.HornetQServerControl;
import org.hornetq.api.core.management.ObjectNameBuilder;
import org.hornetq.api.core.management.QueueControl;
+import org.hornetq.api.core.management.RoleInfo;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.messagecounter.impl.MessageCounterManagerImpl;
@@ -390,6 +391,50 @@
Assert.assertEquals(newSample, serverControl.getMessageCounterSamplePeriod());
}
+
+ public void testSecuritySettings() throws Exception
+ {
+ HornetQServerControl serverControl = createManagementControl();
+ String addressMatch = "test.#";
+ String exactAddress = "test.whatever";
+
+ assertEquals(0, serverControl.getRoles(addressMatch).length);
+ serverControl.addSecuritySettings(addressMatch, "foo", "bar", "foo, bar", "", "foo", "foo, bar", "");
+
+ String rolesAsJSON = serverControl.getRolesAsJSON(exactAddress);
+ RoleInfo[] roleInfos = RoleInfo.from(rolesAsJSON);
+ assertEquals(2, roleInfos.length);
+ RoleInfo fooRole = null;
+ RoleInfo barRole = null;
+ if (roleInfos[0].getName().equals("foo"))
+ {
+ fooRole = roleInfos[0];
+ barRole = roleInfos[1];
+ }
+ else
+ {
+ fooRole = roleInfos[1];
+ barRole = roleInfos[0];
+ }
+ assertTrue(fooRole.isCreateDurableQueue());
+ assertFalse(fooRole.isDeleteDurableQueue());
+ assertTrue(fooRole.isCreateNonDurableQueue());
+ assertFalse(fooRole.isDeleteNonDurableQueue());
+ assertTrue(fooRole.isSend());
+ assertTrue(fooRole.isConsume());
+ assertFalse(fooRole.isManage());
+
+ assertFalse(barRole.isCreateDurableQueue());
+ assertTrue(barRole.isDeleteDurableQueue());
+ assertTrue(barRole.isCreateNonDurableQueue());
+ assertFalse(barRole.isDeleteNonDurableQueue());
+ assertFalse(barRole.isSend());
+ assertTrue(barRole.isConsume());
+ assertFalse(barRole.isManage());
+
+ serverControl.removeSecuritySettings(addressMatch);
+ assertEquals(0, serverControl.getRoles(exactAddress).length);
+ }
// Package protected ---------------------------------------------
Modified: trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java 2010-02-16 09:50:10 UTC (rev 8878)
+++ trunk/tests/src/org/hornetq/tests/integration/management/HornetQServerControlUsingCoreTest.java 2010-02-16 13:49:25 UTC (rev 8879)
@@ -19,7 +19,6 @@
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.management.HornetQServerControl;
import org.hornetq.api.core.management.ResourceNames;
-import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
@@ -447,7 +446,36 @@
{
return (Boolean)proxy.retrieveAttributeValue("PersistenceEnabled");
}
-
+
+ public void addSecuritySettings(String addressMatch,
+ String createDurableQueueRoles,
+ String deleteDurableQueueRoles,
+ String createTempQueueRoles,
+ String deleteTempQueueRoles,
+ String sendRoles,
+ String consumeRoles,
+ String manageRoles) throws Exception
+ {
+ proxy.invokeOperation("addSecuritySettings", addressMatch,
+ createDurableQueueRoles, deleteDurableQueueRoles,
+ createTempQueueRoles, deleteTempQueueRoles,
+ sendRoles, consumeRoles,
+ manageRoles);
+ }
+
+ public void removeSecuritySettings(String addressMatch) throws Exception {
+ proxy.invokeOperation("removeSecuritySettings", addressMatch);
+ };
+
+ public Object[] getRoles(String addressMatch) throws Exception
+ {
+ return (Object[])proxy.invokeOperation("getRoles", addressMatch);
+ }
+
+ public String getRolesAsJSON(String addressMatch) throws Exception
+ {
+ return (String)proxy.invokeOperation("getRolesAsJSON", 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-02-16 09:50:10 UTC (rev 8878)
+++ trunk/tests/src/org/hornetq/tests/unit/core/deployers/impl/QueueDeployerTest.java 2010-02-16 13:49:25 UTC (rev 8879)
@@ -560,6 +560,31 @@
{
return false;
}
+
+ public void addSecuritySettings(String addressMatch,
+ String createDurableQueueRoles,
+ String deleteDurableQueueRoles,
+ String createTempQueueRoles,
+ String deleteTempQueueRoles,
+ String sendRoles,
+ String consumeRoles,
+ String manageRoles) throws Exception
+ {
+ }
+
+ public void removeSecuritySettings(String addressMatch) throws Exception
+ {
+ }
+
+ public Object[] getRoles(String addressMatch) throws Exception
+ {
+ return null;
+ }
+
+ public String getRolesAsJSON(String addressMatch) throws Exception
+ {
+ return null;
+ }
}
More information about the hornetq-commits
mailing list