[jboss-cvs] JBoss Messaging SVN: r6143 - in trunk: .settings and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 23 12:10:07 EDT 2009
Author: jmesnil
Date: 2009-03-23 12:10:07 -0400 (Mon, 23 Mar 2009)
New Revision: 6143
Added:
trunk/src/main/org/jboss/messaging/core/management/NotificationService.java
trunk/tests/src/org/jboss/messaging/tests/integration/management/SecurityNotificationTest.java
Modified:
trunk/.settings/org.eclipse.jdt.ui.prefs
trunk/build-messaging.xml
trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java
trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java
trunk/src/main/org/jboss/messaging/core/management/ManagementService.java
trunk/src/main/org/jboss/messaging/core/management/NotificationType.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
trunk/src/main/org/jboss/messaging/core/security/SecurityStore.java
trunk/src/main/org/jboss/messaging/core/security/impl/SecurityStoreImpl.java
trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
trunk/tests/src/org/jboss/messaging/tests/integration/management/ManagementTestBase.java
trunk/tests/src/org/jboss/messaging/tests/integration/management/NotificationTest.java
Log:
notification integration tests
* extracted a NotificationService interface from ManagementService
* added security notifications
* rewrote integration tests for notifications
Modified: trunk/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- trunk/.settings/org.eclipse.jdt.ui.prefs 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/.settings/org.eclipse.jdt.ui.prefs 2009-03-23 16:10:07 UTC (rev 6143)
@@ -1,4 +1,4 @@
-#Fri Sep 19 16:42:03 BST 2008
+#Wed Feb 25 14:56:24 CET 2009
cleanup.add_default_serial_version_id=false
cleanup.add_generated_serial_version_id=true
cleanup.add_missing_annotations=true
@@ -60,7 +60,7 @@
org.eclipse.jdt.ui.ondemandthreshold=9999
org.eclipse.jdt.ui.overrideannotation=true
org.eclipse.jdt.ui.staticondemandthreshold=9999
-org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" delete!
d\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment"></template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * A ${type_name}\n *\n * @author ${user}\n * \n * Created ${date} ${time}\n *\n * ${tags}\n *\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoin!
sert\="true" context\="overridecomment_context" deleted\="false" descr
iption\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*\n * JBoss, Home of Professional Open Source\n * Copyright 2005-${year}, Red Hat Middleware LLC, and individual contributors\n * by the @authors tag. See the copyright.txt in the distribution for a\n * full listing of individual contributors.\n *\n * This is free software; you can redistribute it and/or modify it\n * !
under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site\: http\://www.fsf.org.\n */\n\n\n${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="false" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetem!
plates.classbody" name\="classbody">\n // Constants ----------------
-------------------------------------\n\n // Attributes ----------------------------------------------------\n\n // Static --------------------------------------------------------\n\n // Constructors --------------------------------------------------\n\n // Public --------------------------------------------------------\n\n // Package protected ---------------------------------------------\n\n // Protected -----------------------------------------------------\n\n // Private -------------------------------------------------------\n\n // Inner classes -------------------------------------------------\n\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies!
" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="fals!
e" description\="Code in created constructor stubs" enabled\="true" id
\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" delete!
d\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment"></template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * A ${type_name}\n *\n * @author ${user}\n *\n * ${tags}\n *\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overrideco!
mment_context" deleted\="false" description\="Comment for overriding m
ethods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*\n * JBoss, Home of Professional Open Source\n * Copyright 2005-${year}, Red Hat Middleware LLC, and individual contributors\n * by the @authors tag. See the copyright.txt in the distribution for a\n * full listing of individual contributors.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser!
General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site\: http\://www.fsf.org.\n */\n\n\n${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="false" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbod!
y">\n // Constants -------------------------------------------------
----\n\n // Attributes ----------------------------------------------------\n\n // Static --------------------------------------------------------\n\n // Constructors --------------------------------------------------\n\n // Public --------------------------------------------------------\n\n // Package protected ---------------------------------------------\n\n // Protected -----------------------------------------------------\n\n // Private -------------------------------------------------------\n\n // Inner classes -------------------------------------------------\n\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclips!
e.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created !
constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codete
mplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/build-messaging.xml 2009-03-23 16:10:07 UTC (rev 6143)
@@ -1145,7 +1145,7 @@
<antcall inheritall="true" inheritrefs="true" target="tests">
<param name="tests.param" value="**/org/jboss/messaging/tests/unit/**/*${test-mask}.class"/>
<!-- if tests.validate.error is defined, it will fail the build in case of any test failure -->
- <param name="tests.validate.error" value="Defined!"/>
+ <!-- <param name="tests.validate.error" value="Defined!"/> -->
</antcall>
</target>
@@ -1191,7 +1191,7 @@
<formatter type="plain" usefile="${junit.formatter.usefile}"/>
<fileset dir="${test.classes.dir}">
<include name="${tests.param}"/>
- <exclude name="**/LargeMessageMultiThreadFailoverTest.class" />
+ <exclude name="**/*Failover*.class" />
</fileset>
</batchtest>
</junit>
Modified: trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -32,8 +32,6 @@
import java.util.Set;
import javax.management.ObjectName;
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.TabularData;
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.utils.SimpleString;
@@ -80,6 +78,12 @@
private static final SimpleString NULL = new SimpleString("_JBM_NULL");
+ public static final SimpleString HDR_CONSUMER_COUNT = new SimpleString("_JBM_ConsumerCount");
+
+ public static final SimpleString HDR_USER = new SimpleString("_JBM_User");
+
+ public static final SimpleString HDR_CHECK_TYPE = new SimpleString("_JBM_CheckType");
+
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -61,7 +61,7 @@
public static final long DEFAULT_CONNECTION_SCAN_PERIOD = 1000;
- public static final long DEFAULT_CONNECTION_TTL_OVERRIDE = -1;
+ public static final long DEFAULT_CONNECTION_TTL_OVERRIDE = 100000;;
public static final String DEFAULT_BINDINGS_DIRECTORY = "data/bindings";
Modified: trunk/src/main/org/jboss/messaging/core/management/ManagementService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/ManagementService.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/management/ManagementService.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -26,7 +26,6 @@
import javax.management.ObjectName;
-import org.jboss.messaging.core.client.management.impl.ManagementHelper;
import org.jboss.messaging.core.cluster.DiscoveryGroup;
import org.jboss.messaging.core.config.Configuration;
import org.jboss.messaging.core.config.TransportConfiguration;
@@ -61,7 +60,7 @@
* @version <tt>$Revision$</tt>
*
*/
-public interface ManagementService extends MessagingComponent
+public interface ManagementService extends NotificationService, MessagingComponent
{
// Configuration
@@ -140,28 +139,4 @@
Object getResource(ObjectName objectName);
ServerMessage handleMessage(ServerMessage message);
-
- // Notfication
-
- /**
- * the message corresponding to a notification will always contain the properties:
- * <ul>
- * <li><code>ManagementHelper.HDR_NOTIFICATION_TYPE</code> - the type of notification (SimpleString)</li>
- * <li><code>ManagementHelper.HDR_NOTIFICATION_MESSAGE</code> - a message contextual to the notification (SimpleString)</li>
- * <li><code>ManagementHelper.HDR_NOTIFICATION_TIMESTAMP</code> - the timestamp when the notification occured (long)</li>
- * </ul>
- *
- * in addition to the properties defined in <code>props</code>
- *
- * @see ManagementHelper
- */
- void sendNotification(Notification notification) throws Exception;
-
- void enableNotifications(boolean enable);
-
- void addNotificationListener(NotificationListener listener);
-
- void removeNotificationListener(NotificationListener listener);
-
-
}
Added: trunk/src/main/org/jboss/messaging/core/management/NotificationService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/NotificationService.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/management/NotificationService.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.core.management;
+
+import org.jboss.messaging.core.client.management.impl.ManagementHelper;
+
+/**
+ * A NotificationService
+ *
+ * @author jmesnil
+ *
+ *
+ */
+public interface NotificationService
+{
+ /**
+ * the message corresponding to a notification will always contain the properties:
+ * <ul>
+ * <li><code>ManagementHelper.HDR_NOTIFICATION_TYPE</code> - the type of notification (SimpleString)</li>
+ * <li><code>ManagementHelper.HDR_NOTIFICATION_MESSAGE</code> - a message contextual to the notification (SimpleString)</li>
+ * <li><code>ManagementHelper.HDR_NOTIFICATION_TIMESTAMP</code> - the timestamp when the notification occured (long)</li>
+ * </ul>
+ *
+ * in addition to the properties defined in <code>props</code>
+ *
+ * @see ManagementHelper
+ */
+ void sendNotification(Notification notification) throws Exception;
+
+ void enableNotifications(boolean enable);
+
+ void addNotificationListener(NotificationListener listener);
+
+ void removeNotificationListener(NotificationListener listener);
+
+}
Modified: trunk/src/main/org/jboss/messaging/core/management/NotificationType.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/NotificationType.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/management/NotificationType.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -20,77 +20,30 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-
package org.jboss.messaging.core.management;
-
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:fox at redhat.com">Tim Fox</a>
*
- * @version <tt>$Revision$</tt>
- *
*/
public enum NotificationType
{
- BINDING_ADDED, BINDING_REMOVED, CONSUMER_CREATED, CONSUMER_CLOSED;
-
- public static final int BINDING_ADDED_INDEX = 0;
-
- public static final int BINDING_REMOVED_INDEX = 1;
-
- public static final int CONSUMER_CREATED_INDEX = 2;
-
- public static final int CONSUMER_CLOSED_INDEX = 3;
-
- public static NotificationType fromInt(final int index)
+ BINDING_ADDED(0),
+ BINDING_REMOVED(1),
+ CONSUMER_CREATED(2),
+ CONSUMER_CLOSED(3),
+ SECURITY_AUTHENTICATION_VIOLATION(6),
+ SECURITY_PERMISSION_VIOLATION(7);
+
+ private final int value;
+
+ private NotificationType(int value)
{
- switch (index)
- {
- case BINDING_ADDED_INDEX:
- {
- return NotificationType.BINDING_ADDED;
- }
- case BINDING_REMOVED_INDEX:
- {
- return NotificationType.BINDING_REMOVED;
- }
- case CONSUMER_CREATED_INDEX:
- {
- return NotificationType.CONSUMER_CREATED;
- }
- case CONSUMER_CLOSED_INDEX:
- {
- return NotificationType.CONSUMER_CLOSED;
- }
- default:
- {
- throw new IllegalArgumentException("Invalid index " + index);
- }
- }
+ this.value = value;
}
-
- public int toInt()
+
+ public int intValue()
{
- if (this.equals(NotificationType.BINDING_ADDED))
- {
- return BINDING_ADDED_INDEX;
- }
- else if (this.equals(NotificationType.BINDING_REMOVED))
- {
- return BINDING_REMOVED_INDEX;
- }
- else if (this.equals(NotificationType.CONSUMER_CREATED))
- {
- return CONSUMER_CREATED_INDEX;
- }
- else if (this.equals(NotificationType.CONSUMER_CLOSED))
- {
- return CONSUMER_CLOSED_INDEX;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert");
- }
+ return value;
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -22,6 +22,17 @@
package org.jboss.messaging.core.postoffice.impl;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
import org.jboss.messaging.core.buffers.ChannelBuffers;
import org.jboss.messaging.core.client.management.impl.ManagementHelper;
import org.jboss.messaging.core.exception.MessagingException;
@@ -50,25 +61,14 @@
import org.jboss.messaging.core.settings.HierarchicalRepository;
import org.jboss.messaging.core.settings.impl.AddressSettings;
import org.jboss.messaging.core.transaction.Transaction;
-import org.jboss.messaging.core.transaction.Transaction.State;
import org.jboss.messaging.core.transaction.TransactionOperation;
import org.jboss.messaging.core.transaction.TransactionPropertyIndexes;
+import org.jboss.messaging.core.transaction.Transaction.State;
import org.jboss.messaging.core.transaction.impl.TransactionImpl;
import org.jboss.messaging.utils.ExecutorFactory;
import org.jboss.messaging.utils.SimpleString;
import org.jboss.messaging.utils.TypedProperties;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
/**
* A PostOfficeImpl
*
@@ -246,9 +246,9 @@
{
NotificationType type = notification.getType();
- switch (type.toInt())
+ switch (type)
{
- case NotificationType.BINDING_ADDED_INDEX:
+ case BINDING_ADDED:
{
TypedProperties props = notification.getProperties();
@@ -283,7 +283,7 @@
break;
}
- case NotificationType.BINDING_REMOVED_INDEX:
+ case BINDING_REMOVED:
{
TypedProperties props = notification.getProperties();
@@ -303,7 +303,7 @@
break;
}
- case NotificationType.CONSUMER_CREATED_INDEX:
+ case CONSUMER_CREATED:
{
TypedProperties props = notification.getProperties();
@@ -376,7 +376,7 @@
break;
}
- case NotificationType.CONSUMER_CLOSED_INDEX:
+ case CONSUMER_CLOSED:
{
TypedProperties props = notification.getProperties();
@@ -446,9 +446,12 @@
break;
}
+ case SECURITY_AUTHENTICATION_VIOLATION:
+ case SECURITY_PERMISSION_VIOLATION:
+ break;
default:
{
- throw new IllegalArgumentException("Invalid type " + type.toInt());
+ throw new IllegalArgumentException("Invalid type " + type);
}
}
@@ -542,6 +545,8 @@
props.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
+ props.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
+
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
managementService.sendNotification(new Notification(NotificationType.BINDING_REMOVED, props));
Modified: trunk/src/main/org/jboss/messaging/core/security/SecurityStore.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/security/SecurityStore.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/security/SecurityStore.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -24,6 +24,7 @@
import java.util.Set;
+import org.jboss.messaging.core.management.NotificationService;
import org.jboss.messaging.core.server.ServerSession;
import org.jboss.messaging.core.settings.HierarchicalRepository;
import org.jboss.messaging.utils.SimpleString;
@@ -47,4 +48,6 @@
void setSecurityManager(JBMSecurityManager securityManager);
void setManagementClusterPassword(String clusterAdminPassword);
+
+ void setNotificationService(NotificationService notificationService);
}
Modified: trunk/src/main/org/jboss/messaging/core/security/impl/SecurityStoreImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/security/impl/SecurityStoreImpl.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/security/impl/SecurityStoreImpl.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -23,8 +23,18 @@
package org.jboss.messaging.core.security.impl;
import static org.jboss.messaging.core.config.impl.ConfigurationImpl.DEFAULT_MANAGEMENT_CLUSTER_PASSWORD;
+import static org.jboss.messaging.core.management.NotificationType.SECURITY_AUTHENTICATION_VIOLATION;
+
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.jboss.messaging.core.client.management.impl.ManagementHelper;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.management.Notification;
+import org.jboss.messaging.core.management.NotificationService;
+import org.jboss.messaging.core.management.NotificationType;
import org.jboss.messaging.core.security.CheckType;
import org.jboss.messaging.core.security.JBMSecurityManager;
import org.jboss.messaging.core.security.Role;
@@ -34,11 +44,8 @@
import org.jboss.messaging.core.settings.HierarchicalRepositoryChangeListener;
import org.jboss.messaging.utils.ConcurrentHashSet;
import org.jboss.messaging.utils.SimpleString;
+import org.jboss.messaging.utils.TypedProperties;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
/**
* The JBM SecurityStore implementation
*
@@ -82,6 +89,8 @@
private final boolean securityEnabled;
private String managementClusterPassword;
+
+ private NotificationService notificationService;
// Constructors --------------------------------------------------
@@ -114,6 +123,17 @@
{
if (!securityManager.validateUser(user, password))
{
+ if (notificationService != null)
+ {
+ TypedProperties props = new TypedProperties();
+
+ props.putStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(user));
+
+ Notification notification = new Notification(SECURITY_AUTHENTICATION_VIOLATION, props);
+
+ notificationService.sendNotification(notification);
+ }
+
throw new MessagingException(MessagingException.SECURITY_EXCEPTION, "Unable to validate user: " + user);
}
}
@@ -146,7 +166,20 @@
}
else if (!securityManager.validateUserAndRole(user, session.getPassword(), roles, checkType))
{
- throw new MessagingException(MessagingException.SECURITY_EXCEPTION, "Unable to validate user: " + session.getUsername());
+ if (notificationService != null)
+ {
+ TypedProperties props = new TypedProperties();
+
+ props.putStringProperty(ManagementHelper.HDR_ADDRESS, address);
+ props.putStringProperty(ManagementHelper.HDR_CHECK_TYPE, new SimpleString(checkType.toString()));
+ props.putStringProperty(ManagementHelper.HDR_USER, new SimpleString(user));
+
+ Notification notification = new Notification(NotificationType.SECURITY_PERMISSION_VIOLATION, props);
+
+ notificationService.sendNotification(notification);
+ }
+
+ throw new MessagingException(MessagingException.SECURITY_EXCEPTION, "Unable to validate user: " + session.getUsername());
}
// if we get here we're granted, add to the cache
ConcurrentHashSet<SimpleString> set = new ConcurrentHashSet<SimpleString>();
@@ -173,6 +206,11 @@
securityRepository.registerListener(this);
}
+ public void setNotificationService(NotificationService notificationService)
+ {
+ this.notificationService = notificationService;
+ }
+
public void setSecurityManager(JBMSecurityManager securityManager)
{
this.securityManager = securityManager;
Modified: trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -24,6 +24,8 @@
import static org.jboss.messaging.core.management.NotificationType.CONSUMER_CLOSED;
import static org.jboss.messaging.core.management.NotificationType.CONSUMER_CREATED;
+import static org.jboss.messaging.core.management.NotificationType.SECURITY_AUTHENTICATION_VIOLATION;
+import static org.jboss.messaging.core.management.NotificationType.SECURITY_PERMISSION_VIOLATION;
import static org.jboss.messaging.core.postoffice.impl.PostOfficeImpl.HDR_RESET_QUEUE_DATA;
import java.util.HashMap;
@@ -546,35 +548,38 @@
NotificationType ntype = NotificationType.valueOf(type.toString());
- switch (ntype.toInt())
+ switch (ntype)
{
- case NotificationType.BINDING_ADDED_INDEX:
+ case BINDING_ADDED:
{
doBindingAdded(message, replicatingChannel);
break;
}
- case NotificationType.BINDING_REMOVED_INDEX:
+ case BINDING_REMOVED:
{
doBindingRemoved(message, replicatingChannel);
break;
}
- case NotificationType.CONSUMER_CREATED_INDEX:
+ case CONSUMER_CREATED:
{
doConsumerCreated(message, replicatingChannel);
break;
}
- case NotificationType.CONSUMER_CLOSED_INDEX:
+ case CONSUMER_CLOSED:
{
doConsumerClosed(message, replicatingChannel);
break;
}
+ case SECURITY_AUTHENTICATION_VIOLATION:
+ case SECURITY_PERMISSION_VIOLATION:
+ break;
default:
{
- throw new IllegalArgumentException("Invalid type " + ntype.toInt());
+ throw new IllegalArgumentException("Invalid type " + ntype);
}
}
}
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -67,7 +67,6 @@
import org.jboss.messaging.core.server.Queue;
import org.jboss.messaging.core.server.QueueFactory;
import org.jboss.messaging.core.server.ServerSession;
-import org.jboss.messaging.core.server.cluster.ClusterConnection;
import org.jboss.messaging.core.server.cluster.ClusterManager;
import org.jboss.messaging.core.server.cluster.Transformer;
import org.jboss.messaging.core.server.cluster.impl.ClusterManagerImpl;
@@ -230,6 +229,8 @@
securityStore = new SecurityStoreImpl(configuration.getSecurityInvalidationInterval(),
configuration.isSecurityEnabled());
securityStore.setManagementClusterPassword(configuration.getManagementClusterPassword());
+ securityStore.setNotificationService(managementService);
+
addressSettingsRepository.setDefault(new AddressSettings());
scheduledExecutor = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize(),
new org.jboss.messaging.utils.JBMThreadFactory("JBM-scheduled-threads"));
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -251,6 +251,8 @@
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
+ props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, messageQueue.getConsumerCount());
+
Notification notification = new Notification(NotificationType.CONSUMER_CLOSED, props);
managementService.sendNotification(notification);
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -1252,6 +1252,8 @@
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
+ props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
+
if (filterString != null)
{
props.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/management/ManagementTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/management/ManagementTestBase.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/management/ManagementTestBase.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -61,7 +61,7 @@
for (int i = 0; i < expected; i++)
{
m = consumer.receive(500);
- assertNotNull("expected to received " + expected + " messages, got only " + (i + 1), m);
+ assertNotNull("expected to received " + expected + " messages, got only " + i, m);
m.acknowledge();
}
session.commit();
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/management/NotificationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/management/NotificationTest.java 2009-03-23 16:02:12 UTC (rev 6142)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/management/NotificationTest.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -23,21 +23,27 @@
package org.jboss.messaging.tests.integration.management;
+import static org.jboss.messaging.core.client.management.impl.ManagementHelper.HDR_ADDRESS;
+import static org.jboss.messaging.core.client.management.impl.ManagementHelper.HDR_CONSUMER_COUNT;
+import static org.jboss.messaging.core.client.management.impl.ManagementHelper.HDR_NOTIFICATION_TYPE;
+import static org.jboss.messaging.core.client.management.impl.ManagementHelper.HDR_ROUTING_NAME;
import static org.jboss.messaging.core.config.impl.ConfigurationImpl.DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS;
+import static org.jboss.messaging.core.management.NotificationType.BINDING_ADDED;
+import static org.jboss.messaging.core.management.NotificationType.BINDING_REMOVED;
+import static org.jboss.messaging.core.management.NotificationType.CONSUMER_CLOSED;
+import static org.jboss.messaging.core.management.NotificationType.CONSUMER_CREATED;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
-import java.util.Set;
-
import org.jboss.messaging.core.client.ClientConsumer;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.client.ClientSessionFactory;
import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.client.management.impl.ManagementHelper;
import org.jboss.messaging.core.config.Configuration;
import org.jboss.messaging.core.config.TransportConfiguration;
import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.management.NotificationType;
+import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
import org.jboss.messaging.core.server.Messaging;
@@ -59,134 +65,135 @@
// Attributes ----------------------------------------------------
private MessagingService service;
+ private ClientSession session;
+ private ClientConsumer notifConsumer;
+ private SimpleString notifQueue;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
-
- public void testNotification() throws Exception
+
+ public void testBINDING_ADDED() throws Exception
{
- ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ SimpleString queue = randomSimpleString();
+ SimpleString address = randomSimpleString();
+ boolean durable = randomBoolean();
- ClientSession session = sf.createSession(false, true, true);
-
- // create a queue to receive the management notifications
- SimpleString notifQueue = randomSimpleString();
- session.createQueue(DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS, notifQueue, null, false, true);
- ClientConsumer notifConsumer = session.createConsumer(notifQueue);
- session.start();
+ flush(notifConsumer);
- // we've generated at least 2 notifications
- // but there is more in the queue (e.g. the notification when the notifQueue was created)
- ClientMessage notifMessage = notifConsumer.receive(500);
- assertNotNull(notifMessage);
- Set<SimpleString> propertyNames = notifMessage.getPropertyNames();
+ session.createQueue(address, queue, durable);
- for (SimpleString key : propertyNames)
- {
- System.out.println(key + "=" + notifMessage.getProperty(key));
- }
+ ClientMessage[] notifications = consumeMessages(1, notifConsumer);
+ assertEquals(BINDING_ADDED.toString(), notifications[0].getProperty(HDR_NOTIFICATION_TYPE).toString());
+ assertEquals(queue.toString(), notifications[0].getProperty(HDR_ROUTING_NAME).toString());
+ assertEquals(address.toString(), notifications[0].getProperty(HDR_ADDRESS).toString());
- notifMessage.acknowledge();
-
+ session.deleteQueue(queue);
+ }
+
+ public void testBINDING_ADDEDWithMatchingFilter() throws Exception
+ {
+ SimpleString queue = randomSimpleString();
+ SimpleString address = randomSimpleString();
+ boolean durable = randomBoolean();
- notifMessage = notifConsumer.receive(500);
- assertNotNull(notifMessage);
- propertyNames = notifMessage.getPropertyNames();
- for (SimpleString key : propertyNames)
- {
- System.out.println(key + "=" + notifMessage.getProperty(key));
- }
- notifMessage.acknowledge();
+ System.out.println(queue);
+ notifConsumer.close();
+ notifConsumer = session.createConsumer(notifQueue.toString(), HDR_ROUTING_NAME + "= '" + queue + "'");
+ flush(notifConsumer);
- // generate more notifications
- session.createQueue(new SimpleString("testaddress"), new SimpleString("queue1"), false);
- session.deleteQueue(new SimpleString("queue1"));
+ session.createQueue(address, queue, durable);
- notifMessage = notifConsumer.receive(500);
- assertNotNull(notifMessage);
- propertyNames = notifMessage.getPropertyNames();
- for (SimpleString key : propertyNames)
- {
- System.out.println(key + "=" + notifMessage.getProperty(key));
- }
- notifMessage.acknowledge();
-
- notifMessage = notifConsumer.receive(500);
- assertNotNull(notifMessage);
- propertyNames = notifMessage.getPropertyNames();
- for (SimpleString key : propertyNames)
- {
- System.out.println(key + "=" + notifMessage.getProperty(key));
- }
- notifMessage.acknowledge();
-
-
- notifConsumer.close();
- session.deleteQueue(notifQueue);
- session.close();
+ ClientMessage[] notifications = consumeMessages(1, notifConsumer);
+ assertEquals(BINDING_ADDED.toString(), notifications[0].getProperty(HDR_NOTIFICATION_TYPE).toString());
+ assertEquals(queue.toString(), notifications[0].getProperty(HDR_ROUTING_NAME).toString());
+ assertEquals(address.toString(), notifications[0].getProperty(HDR_ADDRESS).toString());
+
+ session.deleteQueue(queue);
}
- public void testNotificationWithFilter() throws Exception
+ public void testBINDING_ADDEDWithNonMatchingFilter() throws Exception
{
- SimpleString destinationName = randomSimpleString();
- SimpleString unmatchedDestinationName = new SimpleString("this.destination.does.not.match.the.filter");
+ SimpleString queue = randomSimpleString();
+ SimpleString address = randomSimpleString();
+ boolean durable = randomBoolean();
- ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ System.out.println(queue);
+ notifConsumer.close();
+ notifConsumer = session.createConsumer(notifQueue.toString(), HDR_ROUTING_NAME + " <> '" + queue + "'");
+ flush(notifConsumer);
- ClientSession session = sf.createSession(false, true, true);
+ session.createQueue(address, queue, durable);
- // create a queue to receive the management notifications only concerning the destination
- SimpleString notifQueue = randomSimpleString();
- SimpleString filter = new SimpleString(ManagementHelper.HDR_ADDRESS + " LIKE '%" + destinationName + "%'" );
- System.out.println(filter);
- session.createQueue(DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS, notifQueue, filter, false, true);
- ClientConsumer notifConsumer = session.createConsumer(notifQueue);
- session.start();
+ consumeMessages(0, notifConsumer);
- // generate notifications that do NOT match the filter
- session.createQueue(unmatchedDestinationName, unmatchedDestinationName, true);
- session.deleteQueue(unmatchedDestinationName);
+ session.deleteQueue(queue);
+ }
+
+ public void testBINDING_REMOVED() throws Exception
+ {
+ SimpleString queue = randomSimpleString();
+ SimpleString address = randomSimpleString();
+ boolean durable = randomBoolean();
+
+ session.createQueue(address, queue, durable);
+
+ flush(notifConsumer);
+
+ session.deleteQueue(queue);
+
+ ClientMessage[] notifications = consumeMessages(1, notifConsumer);
+ assertEquals(BINDING_REMOVED.toString(), notifications[0].getProperty(HDR_NOTIFICATION_TYPE).toString());
+ assertEquals(queue.toString(), notifications[0].getProperty(HDR_ROUTING_NAME).toString());
+ assertEquals(address.toString(), notifications[0].getProperty(HDR_ADDRESS).toString());
+ }
+
+ public void testCONSUMER_CREATED() throws Exception
+ {
+ SimpleString queue = randomSimpleString();
+ SimpleString address = randomSimpleString();
+ boolean durable = randomBoolean();
+
+ session.createQueue(address, queue, durable);
+
+ flush(notifConsumer);
+
+ ClientConsumer consumer = session.createConsumer(queue);
- assertNull(notifConsumer.receive(500));
-
- // generate notifications that match the filter
- session.createQueue(destinationName, destinationName, true);
- session.deleteQueue(destinationName);
+ ClientMessage[] notifications = consumeMessages(1, notifConsumer);
+ assertEquals(CONSUMER_CREATED.toString(), notifications[0].getProperty(HDR_NOTIFICATION_TYPE).toString());
+ assertEquals(queue.toString(), notifications[0].getProperty(HDR_ROUTING_NAME).toString());
+ assertEquals(address.toString(), notifications[0].getProperty(HDR_ADDRESS).toString());
+ assertEquals(1, notifications[0].getProperty(HDR_CONSUMER_COUNT));
- ClientMessage notifMessage = notifConsumer.receive(500);
- assertNotNull(notifMessage);
- assertEquals(NotificationType.BINDING_ADDED.toString(), notifMessage.getProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
- Set<SimpleString> propertyNames = notifMessage.getPropertyNames();
+ consumer.close();
+ session.deleteQueue(queue);
+ }
- for (SimpleString key : propertyNames)
- {
- System.out.println(key + "=" + notifMessage.getProperty(key));
- }
+ public void testCONSUMER_CLOSED() throws Exception
+ {
+ SimpleString queue = randomSimpleString();
+ SimpleString address = randomSimpleString();
+ boolean durable = randomBoolean();
- notifMessage.acknowledge();
+ session.createQueue(address, queue, durable);
+ ClientConsumer consumer = session.createConsumer(queue);
+ flush(notifConsumer);
- notifMessage = notifConsumer.receive(500);
- assertNotNull(notifMessage);
- assertEquals(NotificationType.BINDING_REMOVED.toString(), notifMessage.getProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
- propertyNames = notifMessage.getPropertyNames();
- for (SimpleString key : propertyNames)
- {
- System.out.println(key + "=" + notifMessage.getProperty(key));
- }
- notifMessage.acknowledge();
+ consumer.close();
- // no other notifications matching the filter
- assertNull(notifConsumer.receive(500));
-
- notifConsumer.close();
- session.deleteQueue(notifQueue);
- session.close();
+ ClientMessage[] notifications = consumeMessages(1, notifConsumer);
+ assertEquals(CONSUMER_CLOSED.toString(), notifications[0].getProperty(HDR_NOTIFICATION_TYPE).toString());
+ assertEquals(queue.toString(), notifications[0].getProperty(HDR_ROUTING_NAME).toString());
+ assertEquals(address.toString(), notifications[0].getProperty(HDR_ADDRESS).toString());
+ assertEquals(0, notifications[0].getProperty(HDR_CONSUMER_COUNT));
+
+ session.deleteQueue(queue);
}
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@@ -204,11 +211,26 @@
.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
service = Messaging.newNullStorageMessagingService(conf);
service.start();
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ session = sf.createSession(false, true, true);
+ session.start();
+
+ notifQueue = randomSimpleString();
+
+ session.createQueue(DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS, notifQueue, null, false, true);
+
+ notifConsumer = session.createConsumer(notifQueue);
}
@Override
protected void tearDown() throws Exception
{
+ notifConsumer.close();
+
+ session.deleteQueue(notifQueue);
+ session.close();
+
service.stop();
super.tearDown();
@@ -216,6 +238,50 @@
// Private -------------------------------------------------------
+
+ private static void flush(ClientConsumer notifConsumer) throws MessagingException
+ {
+ ClientMessage message = null;
+ do
+ {
+ message = notifConsumer.receive(500);
+ } while (message != null);
+ }
+
+
+ protected static ClientMessage[] consumeMessages(int expected, ClientConsumer consumer) throws Exception
+ {
+ ClientMessage[] messages = new ClientMessage[expected];
+
+ ClientMessage m = null;
+ for (int i = 0; i < expected; i++)
+ {
+ m = consumer.receive(500);
+ if (m != null)
+ {
+ for (SimpleString key : m.getPropertyNames())
+ {
+ System.out.println(key + "=" + m.getProperty(key));
+ }
+ }
+ assertNotNull("expected to received " + expected + " messages, got only " + i, m);
+ messages[i] = m;
+ m.acknowledge();
+ }
+ m = consumer.receive(500);
+ if (m != null)
+ {
+ for (SimpleString key : m.getPropertyNames())
+
+ {
+ System.out.println(key + "=" + m.getProperty(key));
+ }
+ }
+ assertNull("received one more message than expected (" + expected + ")", m);
+
+ return messages;
+ }
+
// Inner classes -------------------------------------------------
}
Added: trunk/tests/src/org/jboss/messaging/tests/integration/management/SecurityNotificationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/management/SecurityNotificationTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/management/SecurityNotificationTest.java 2009-03-23 16:10:07 UTC (rev 6143)
@@ -0,0 +1,238 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.integration.management;
+
+import static org.jboss.messaging.core.client.management.impl.ManagementHelper.HDR_NOTIFICATION_TYPE;
+import static org.jboss.messaging.core.config.impl.ConfigurationImpl.DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS;
+import static org.jboss.messaging.core.management.NotificationType.SECURITY_AUTHENTICATION_VIOLATION;
+import static org.jboss.messaging.core.management.NotificationType.SECURITY_PERMISSION_VIOLATION;
+import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.client.management.impl.ManagementHelper;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.security.CheckType;
+import org.jboss.messaging.core.security.JBMUpdateableSecurityManager;
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.utils.SimpleString;
+
+/**
+ * A SecurityNotificationTest
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ */
+public class SecurityNotificationTest extends UnitTestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private MessagingService service;
+ private ClientSession adminSession;
+ private ClientConsumer notifConsumer;
+ private SimpleString notifQueue;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testSECURITY_AUTHENTICATION_VIOLATION() throws Exception
+ {
+ String unknownUser = randomString();
+
+ flush(notifConsumer);
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+
+ try
+ {
+ sf.createSession(unknownUser, randomString(), false, true, true, false, 1);
+ fail("authentication must fail and a notification of security violation must be sent");
+ }
+ catch (Exception e)
+ {
+ }
+
+ ClientMessage[] notifications = consumeMessages(1, notifConsumer);
+ assertEquals(SECURITY_AUTHENTICATION_VIOLATION.toString(), notifications[0].getProperty(HDR_NOTIFICATION_TYPE).toString());
+ assertEquals(unknownUser, notifications[0].getProperty(ManagementHelper.HDR_USER).toString());
+ }
+
+ public void testSECURITY_PERMISSION_VIOLATION() throws Exception
+ {
+ SimpleString queue = randomSimpleString();
+ SimpleString address = randomSimpleString();
+
+ // guest can not create queue
+ Role role = new Role("roleCanNotCreateQueue", true, true, false, true, false, true, true);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ service.getServer().getSecurityRepository().addMatch(address.toString(), roles);
+ JBMUpdateableSecurityManager securityManager = (JBMUpdateableSecurityManager) service.getServer().getSecurityManager();
+ securityManager.addRole("guest", "roleCanNotCreateQueue");
+
+ flush(notifConsumer);
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ ClientSession guestSession = sf.createSession("guest", "guest", false, true, true, false, 1);
+
+ try
+ {
+ guestSession.createQueue(address, queue, true, false);
+ fail("session creation must fail and a notification of security violation must be sent");
+ }
+ catch (Exception e)
+ {
+ }
+
+ ClientMessage[] notifications = consumeMessages(1, notifConsumer);
+ assertEquals(SECURITY_PERMISSION_VIOLATION.toString(), notifications[0].getProperty(HDR_NOTIFICATION_TYPE).toString());
+ assertEquals("guest", notifications[0].getProperty(ManagementHelper.HDR_USER).toString());
+ assertEquals(address.toString(), notifications[0].getProperty(ManagementHelper.HDR_ADDRESS).toString());
+ assertEquals(CheckType.CREATE_DURABLE_QUEUE.toString(), notifications[0].getProperty(ManagementHelper.HDR_CHECK_TYPE).toString());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ Configuration conf = new ConfigurationImpl();
+ conf.setSecurityEnabled(true);
+ // the notifications are independent of JMX
+ conf.setJMXManagementEnabled(false);
+ conf.getAcceptorConfigurations()
+ .add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
+ service = Messaging.newNullStorageMessagingService(conf);
+ service.start();
+
+ notifQueue = randomSimpleString();
+
+ JBMUpdateableSecurityManager securityManager = (JBMUpdateableSecurityManager) service.getServer().getSecurityManager();
+ securityManager.addUser("admin", "admin");
+ securityManager.addUser("guest", "guest");
+ securityManager.setDefaultUser("guest");
+
+ Role role = new Role("notif", true, true, true, true, true, true, true);
+ Set<Role> roles = new HashSet<Role>();
+ roles.add(role);
+ service.getServer().getSecurityRepository().addMatch(DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS.toString(), roles);
+
+ securityManager.addRole("admin", "notif");
+
+ ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ adminSession = sf.createSession("admin", "admin", false, true, true, false, 1);
+ adminSession.start();
+
+ adminSession.createQueue(DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS, notifQueue, null, false, true);
+
+ notifConsumer = adminSession.createConsumer(notifQueue);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ notifConsumer.close();
+
+ adminSession.deleteQueue(notifQueue);
+ adminSession.close();
+
+ service.stop();
+
+ super.tearDown();
+ }
+
+ // Private -------------------------------------------------------
+
+
+ private static void flush(ClientConsumer notifConsumer) throws MessagingException
+ {
+ ClientMessage message = null;
+ do
+ {
+ message = notifConsumer.receive(500);
+ } while (message != null);
+ }
+
+
+ protected static ClientMessage[] consumeMessages(int expected, ClientConsumer consumer) throws Exception
+ {
+ ClientMessage[] messages = new ClientMessage[expected];
+
+ ClientMessage m = null;
+ for (int i = 0; i < expected; i++)
+ {
+ m = consumer.receive(500);
+ if (m != null)
+ {
+ for (SimpleString key : m.getPropertyNames())
+ {
+ System.out.println(key + "=" + m.getProperty(key));
+ }
+ }
+ assertNotNull("expected to received " + expected + " messages, got only " + i, m);
+ messages[i] = m;
+ m.acknowledge();
+ }
+ m = consumer.receive(500);
+ if (m != null)
+ {
+ for (SimpleString key : m.getPropertyNames())
+
+ {
+ System.out.println(key + "=" + m.getProperty(key));
+ }
+ }
+ assertNull("received one more message than expected (" + expected + ")", m);
+
+ return messages;
+ }
+
+ // Inner classes -------------------------------------------------
+
+}
More information about the jboss-cvs-commits
mailing list