Author: robbie
Date: Thu Jul 21 10:57:07 2011
New Revision: 1149109

URL: http://svn.apache.org/viewvc?rev=1149109&view=rev
Log:
QPID-3255: update management console to remove redundant user management 
functionality, move legacy methods from UserManagement to an extension interface

Added:
    
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/LegacySupportingUserManagement.java
Modified:
    
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java
    
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
    
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java
    
qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/UserManagement.java
    
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/UserManagementTabControl.java

Modified: 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java?rev=1149109&r1=1149108&r2=1149109&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java
 Thu Jul 21 10:57:07 2011
@@ -91,15 +91,10 @@ public class AMQUserManagementMBean exte
 
     public boolean setPassword(String username, String password)
     {
-        return setPassword(username, password.toCharArray());
-    }
-    
-    public boolean setPassword(String username, char[] password)
-    {
         try
         {
             //delegate password changes to the Principal Database
-            return _principalDatabase.updatePassword(new 
UsernamePrincipal(username), password);
+            return _principalDatabase.updatePassword(new 
UsernamePrincipal(username), password.toCharArray());
         }
         catch (AccountNotFoundException e)
         {
@@ -108,11 +103,6 @@ public class AMQUserManagementMBean exte
         }
     }
 
-    public boolean setRights(String username, boolean read, boolean write, 
boolean admin)
-    {
-        throw new UnsupportedOperationException("Support for setting access 
rights no longer supported.");
-    }
-    
     public boolean createUser(String username, String password)
     {
         if (_principalDatabase.createPrincipal(new 
UsernamePrincipal(username), password.toCharArray()))
@@ -122,20 +112,6 @@ public class AMQUserManagementMBean exte
 
         return false;
     }
-    
-    public boolean createUser(String username, String password, boolean read, 
boolean write, boolean admin)
-    {
-        if (read || write || admin)
-        {
-            throw new UnsupportedOperationException("Support for setting 
access rights to true no longer supported.");
-        }
-        return createUser(username, password);
-    }
-
-    public boolean createUser(String username, char[] password, boolean read, 
boolean write, boolean admin)
-    {
-        return createUser(username, new String(password), read, write, admin);
-    }
 
     public boolean deleteUser(String username)
     {
@@ -181,7 +157,6 @@ public class AMQUserManagementMBean exte
             for (Principal user : users)
             {
                 // Create header attributes list
-                
                 // Read,Write,Admin items are depcreated and we return always 
false.
                 Object[] itemData = {user.getName(), false, false, false};
                 CompositeData messageData = new 
CompositeDataSupport(_userDataType, COMPOSITE_ITEM_NAMES.toArray(new 
String[COMPOSITE_ITEM_NAMES.size()]), itemData);

Modified: 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java?rev=1149109&r1=1149108&r2=1149109&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
 Thu Jul 21 10:57:07 2011
@@ -207,6 +207,8 @@ public class PrincipalDatabaseAuthentica
         {
             _logger.warn("No additional SASL providers registered.");
         }
+
+        registerManagement();
     }
 
     private void initialiseAuthenticationMechanisms(Map<String, Class<? 
extends SaslServerFactory>> providerMap, PrincipalDatabase database) 
@@ -326,6 +328,8 @@ public class PrincipalDatabaseAuthentica
     {
         _mechanisms = null;
         Security.removeProvider(PROVIDER_NAME);
+
+        unregisterManagement();
     }
 
     private PrincipalDatabase createPrincipalDatabaseImpl(final String 
pdClazz) throws ConfigurationException

Modified: 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java?rev=1149109&r1=1149108&r2=1149109&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java
 (original)
+++ 
qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java
 Thu Jul 21 10:57:07 2011
@@ -102,13 +102,6 @@ public class AMQUserManagementMBeanTest 
         assertEquals("Unexpected number of users before test", 
1,_amqumMBean.viewUsers().size());
     }
 
-    public void testFiveArgCreateUserWithNegativeRightsRemainsSupported()
-    {
-        assertEquals("Unexpected number of users before test", 
1,_amqumMBean.viewUsers().size());
-        assertTrue("Create should return true to flag successful create", 
_amqumMBean.createUser("newuser", "mypass".toCharArray(), false, false, false));
-        assertEquals("Unexpected number of users before test", 
2,_amqumMBean.viewUsers().size());
-    }
-
     public void testSetPassword()
     {
         assertTrue("Set password should return true to flag successful 
change", _amqumMBean.setPassword(TEST_USERNAME, "newpassword"));
@@ -137,33 +130,6 @@ public class AMQUserManagementMBeanTest 
         assertEquals(false, userRec.get(UserManagement.RIGHTS_ADMIN));
     }
 
-    // TEST DEPRECATED METHODS
-    public void 
testFiveArgCreateUserWithPositiveRightsThrowsUnsupportedOperation()
-    {
-        try 
-        {
-            _amqumMBean.createUser(TEST_USERNAME, "mypass", true, false, 
false);
-            fail("Exception not thrown");
-        }
-        catch (UnsupportedOperationException uoe)
-        {
-            // PASS
-        }
-    }
-
-    public void testSetRightsThrowsUnsupportedOperation()
-    {
-        try 
-        {
-            _amqumMBean.setRights("", false, false, false);
-            fail("Exception not thrown");
-        }
-        catch(UnsupportedOperationException nie)
-        {
-            // PASS
-        }
-    }
-
     // ============================ Utility methods =========================
 
     private void loadFreshTestPasswordFile()

Modified: 
qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/UserManagement.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/UserManagement.java?rev=1149109&r1=1149108&r2=1149109&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/UserManagement.java
 (original)
+++ 
qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/UserManagement.java
 Thu Jul 21 10:57:07 2011
@@ -53,25 +53,6 @@ public interface UserManagement
 
     //********** Operations *****************//
     /**
-     * set password for user.
-     * 
-     * Since Qpid JMX API 1.2 this operation expects plain text passwords to 
be provided. Prior to this, MD5 hashed passwords were supplied.
-     * 
-     * @deprecated since Qpid JMX API 1.7
-     *
-     * @param username The username for which the password is to be set
-     * @param password The password for the user
-     *
-     * @return The result of the operation
-     */
-    @Deprecated
-    @MBeanOperation(name = "setPassword", description = "Set password for 
user.",
-                    impact = MBeanOperationInfo.ACTION)
-    boolean setPassword(@MBeanOperationParameter(name = "username", 
description = "Username")String username,
-                        //NOTE: parameter name was changed to 'passwd' in Qpid 
JMX API 1.7 to protect against older, incompatible management clients
-                        @MBeanOperationParameter(name = "passwd", description 
= "Password")char[] password);
-
-    /**
      * Set password for a given user.
      * 
      * @since Qpid JMX API 1.7
@@ -85,85 +66,11 @@ public interface UserManagement
                     impact = MBeanOperationInfo.ACTION)
     boolean setPassword(@MBeanOperationParameter(name = "username", 
description = "Username")String username,
                         @MBeanOperationParameter(name = "password", 
description = "Password")String password);
-    
-    /**
-     * Set rights for users with given details.
-     * Since Qpid JMX API 2.3 all invocations will cause an exception to be 
thrown
-     * as access rights can no longer be maintain via this interface.
-     * 
-     * @deprecated since Qpid JMX API 2.3
-     *
-     * @param username The username to create
-     * @param read     The set of permission to give the new user
-     * @param write    The set of permission to give the new user
-     * @param admin    The set of permission to give the new user
-     *
-     * @return The result of the operation
-     */
-    @Deprecated
-    @MBeanOperation(name = "setRights", description = "Set access rights for 
user.",
-                    impact = MBeanOperationInfo.ACTION)
-    boolean setRights(@MBeanOperationParameter(name = "username", description 
= "Username")String username,
-                      @MBeanOperationParameter(name = "read", description = 
"Administration read")boolean read,
-                      @MBeanOperationParameter(name = "readAndWrite", 
description = "Administration write")boolean write,
-                      @MBeanOperationParameter(name = "admin", description = 
"Administration rights")boolean admin);
-
-    /**
-     * Create users with given details.
-     * Since Qpid JMX API 2.3 if the user passes true for parameters read, 
write, or admin, a
-     * exception will be thrown as access rights can no longer be maintain via 
this interface.
-     *
-     * Since Qpid JMX API 1.2 this operation expects plain text passwords to 
be provided. Prior to this, MD5 hashed passwords were supplied.
-     * 
-     * @deprecated since Qpid JMX API 1.7
-     * 
-     * @param username The username to create
-     * @param password The password for the user
-     * @param read     The set of permission to give the new user
-     * @param write    The set of permission to give the new user
-     * @param admin    The set of permission to give the new user
-     *
-     * @return true if the user was created successfully, or false otherwise
-     */
-    @Deprecated
-    @MBeanOperation(name = "createUser", description = "Create new user from 
system.",
-                    impact = MBeanOperationInfo.ACTION)
-    boolean createUser(@MBeanOperationParameter(name = "username", description 
= "Username")String username,
-                       //NOTE: parameter name was changed to 'passwd' in Qpid 
JMX API 1.7 to protect against older, incompatible management clients
-                       @MBeanOperationParameter(name = "passwd", description = 
"Password")char[] password,
-                       @MBeanOperationParameter(name = "read", description = 
"Administration read")boolean read,
-                       @MBeanOperationParameter(name = "readAndWrite", 
description = "Administration write")boolean write,
-                       @MBeanOperationParameter(name = "admin", description = 
"Administration rights")boolean admin);
-
-    /**
-     * Create users with given details.
-     * Since Qpid JMX API 2.3 if the user passes true for parameters read, 
write, or admin, a
-     * exception will be thrown as access rights can no longer be maintain via 
this interface.
-     * 
-     * @deprecated since Qpid JMX API 2.3
-     * @since Qpid JMX API 1.7
-     * 
-     * @param username The username to create
-     * @param password The password for the user
-     * @param read     The set of permission to give the new user
-     * @param write    The set of permission to give the new user
-     * @param admin    The set of permission to give the new user
-     *
-     * @return true if the user was created successfully, or false otherwise
-     */
-    @Deprecated
-    @MBeanOperation(name = "createUser", description = "Create a new user.",
-                    impact = MBeanOperationInfo.ACTION)
-    boolean createUser(@MBeanOperationParameter(name = "username", description 
= "Username")String username,
-                       @MBeanOperationParameter(name = "password", description 
= "Password")String password,
-                       @MBeanOperationParameter(name = "read", description = 
"Administration read")boolean read,
-                       @MBeanOperationParameter(name = "readAndWrite", 
description = "Administration write")boolean write,
-                       @MBeanOperationParameter(name = "admin", description = 
"Administration rights")boolean admin);
 
     /**
      * Create users with given details.
      * 
-     * @since Qpid JMX API 2.3
+     * @since Qpid JMX API 2.3 / 1.12
      * 
      * @param username The username to create
      * @param password The password for the user
@@ -188,9 +95,11 @@ public interface UserManagement
 
 
     /**
-     * Reload the date from disk
+     * Reload the user data
      * 
-     * Since Qpid JMX API 1.2 this operation reloads the password and 
authorisation files. Prior to this, only the authorisation file was reloaded.
+     * Since Qpid JMX API 2.3 / 1.12 this operation reloads only the password 
data.
+     * Since Qpid JMX API 1.2 but prior to 2.3 / 1.12 this operation reloads 
the password and authorisation files.
+     * Prior to 1.2, only the authorisation file was reloaded.
      *
      * @return The result of the operation
      */
@@ -201,7 +110,7 @@ public interface UserManagement
     /**
      * View users returns all the users that are currently available to the 
system.
      * 
-     * Since Qpid JMX API 2.3 the items that corresponded to read, write and 
admin flags 
+     * Since Qpid JMX API 2.3 / 1.12 the items that corresponded to read, 
write and admin flags
      * are deprecated and always return false.
      *
      * @return a table of users data (Username, read, write, admin)

Added: 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/LegacySupportingUserManagement.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/LegacySupportingUserManagement.java?rev=1149109&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/LegacySupportingUserManagement.java
 (added)
+++ 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/LegacySupportingUserManagement.java
 Thu Jul 21 10:57:07 2011
@@ -0,0 +1,132 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.qpid.management.ui.views.users;
+
+import javax.management.MBeanOperationInfo;
+
+import org.apache.qpid.management.common.mbeans.UserManagement;
+import org.apache.qpid.management.common.mbeans.annotations.MBeanOperation;
+import 
org.apache.qpid.management.common.mbeans.annotations.MBeanOperationParameter;
+
+/**
+ * UserManagement interface extension to provide the method signatures
+ * for old UserManagement methods no longer supported by the broker.
+ *
+ * This interface is used only for the creation of MBean proxy objects
+ * within the management console, for backwards compatibility with
+ * functionality in older broker versions.
+ */
+public interface LegacySupportingUserManagement extends UserManagement
+{
+    /**
+     * set password for user.
+     *
+     * Since Qpid JMX API 1.2 this operation expects plain text passwords to 
be provided. Prior to this, MD5 hashed passwords were supplied.
+     *
+     * @deprecated since Qpid JMX API 1.7
+     *
+     * @param username The username for which the password is to be set
+     * @param password The password for the user
+     *
+     * @return The result of the operation
+     */
+    @Deprecated
+    @MBeanOperation(name = "setPassword", description = "Set password for 
user.",
+                    impact = MBeanOperationInfo.ACTION)
+    boolean setPassword(@MBeanOperationParameter(name = "username", 
description = "Username")String username,
+                        //NOTE: parameter name was changed to 'passwd' in Qpid 
JMX API 1.7 to protect against older, incompatible management clients
+                        @MBeanOperationParameter(name = "passwd", description 
= "Password")char[] password);
+
+    /**
+     * Set rights for users with given details.
+     * Since Qpid JMX API 2.3 all invocations will cause an exception to be 
thrown
+     * as access rights can no longer be maintain via this interface.
+     *
+     * @deprecated since Qpid JMX API 2.3 / 1.12
+     *
+     * @param username The username to create
+     * @param read     The set of permission to give the new user
+     * @param write    The set of permission to give the new user
+     * @param admin    The set of permission to give the new user
+     *
+     * @return The result of the operation
+     */
+    @Deprecated
+    @MBeanOperation(name = "setRights", description = "Set access rights for 
user.",
+                    impact = MBeanOperationInfo.ACTION)
+    boolean setRights(@MBeanOperationParameter(name = "username", description 
= "Username")String username,
+                      @MBeanOperationParameter(name = "read", description = 
"Administration read")boolean read,
+                      @MBeanOperationParameter(name = "readAndWrite", 
description = "Administration write")boolean write,
+                      @MBeanOperationParameter(name = "admin", description = 
"Administration rights")boolean admin);
+
+    /**
+     * Create users with given details.
+     * Since Qpid JMX API 2.3 if the user passes true for parameters read, 
write, or admin, a
+     * exception will be thrown as access rights can no longer be maintain via 
this interface.
+     *
+     * Since Qpid JMX API 1.2 this operation expects plain text passwords to 
be provided. Prior to this, MD5 hashed passwords were supplied.
+     *
+     * @deprecated since Qpid JMX API 1.7
+     *
+     * @param username The username to create
+     * @param password The password for the user
+     * @param read     The set of permission to give the new user
+     * @param write    The set of permission to give the new user
+     * @param admin    The set of permission to give the new user
+     *
+     * @return true if the user was created successfully, or false otherwise
+     */
+    @Deprecated
+    @MBeanOperation(name = "createUser", description = "Create new user from 
system.",
+                    impact = MBeanOperationInfo.ACTION)
+    boolean createUser(@MBeanOperationParameter(name = "username", description 
= "Username")String username,
+                       //NOTE: parameter name was changed to 'passwd' in Qpid 
JMX API 1.7 to protect against older, incompatible management clients
+                       @MBeanOperationParameter(name = "passwd", description = 
"Password")char[] password,
+                       @MBeanOperationParameter(name = "read", description = 
"Administration read")boolean read,
+                       @MBeanOperationParameter(name = "readAndWrite", 
description = "Administration write")boolean write,
+                       @MBeanOperationParameter(name = "admin", description = 
"Administration rights")boolean admin);
+
+    /**
+     * Create users with given details.
+     * Since Qpid JMX API 2.3 if the user passes true for parameters read, 
write, or admin, a
+     * exception will be thrown as access rights can no longer be maintain via 
this interface.
+     *
+     * @deprecated since Qpid JMX API 2.3 / 1.12
+     * @since Qpid JMX API 1.7
+     *
+     * @param username The username to create
+     * @param password The password for the user
+     * @param read     The set of permission to give the new user
+     * @param write    The set of permission to give the new user
+     * @param admin    The set of permission to give the new user
+     *
+     * @return true if the user was created successfully, or false otherwise
+     */
+    @Deprecated
+    @MBeanOperation(name = "createUser", description = "Create a new user.",
+                    impact = MBeanOperationInfo.ACTION)
+    boolean createUser(@MBeanOperationParameter(name = "username", description 
= "Username")String username,
+                       @MBeanOperationParameter(name = "password", description 
= "Password")String password,
+                       @MBeanOperationParameter(name = "read", description = 
"Administration read")boolean read,
+                       @MBeanOperationParameter(name = "readAndWrite", 
description = "Administration write")boolean write,
+                       @MBeanOperationParameter(name = "admin", description = 
"Administration rights")boolean admin);
+
+}

Modified: 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/UserManagementTabControl.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/UserManagementTabControl.java?rev=1149109&r1=1149108&r2=1149109&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/UserManagementTabControl.java
 (original)
+++ 
qpid/trunk/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/users/UserManagementTabControl.java
 Thu Jul 21 10:57:07 2011
@@ -37,7 +37,6 @@ import javax.management.openmbean.Tabula
 import org.apache.qpid.management.ui.ApiVersion;
 import org.apache.qpid.management.ui.ApplicationRegistry;
 import org.apache.qpid.management.ui.ManagedBean;
-import org.apache.qpid.management.common.mbeans.UserManagement;
 import org.apache.qpid.management.ui.jmx.JMXManagedObject;
 import org.apache.qpid.management.ui.jmx.MBeanUtility;
 import org.apache.qpid.management.ui.views.TabControl;
@@ -83,7 +82,7 @@ public class UserManagementTabControl ex
     private TableViewer _tableViewer = null;
 
     private TabularDataSupport _userDetails = null;
-    private UserManagement _ummb;
+    private LegacySupportingUserManagement _ummb;
     private ApiVersion _ApiVersion;
     
     public UserManagementTabControl(TabFolder tabFolder, JMXManagedObject 
mbean, MBeanServerConnection mbsc)
@@ -91,9 +90,9 @@ public class UserManagementTabControl ex
         super(tabFolder);
         _mbean = mbean;
         _ApiVersion = 
ApplicationRegistry.getServerRegistry(mbean).getManagementApiVersion();
-        _ummb = (UserManagement)
+        _ummb = (LegacySupportingUserManagement)
                 MBeanServerInvocationHandler.newProxyInstance(mbsc, 
mbean.getObjectName(),
-                                                            
UserManagement.class, false);
+                                                            
LegacySupportingUserManagement.class, false);
         _toolkit = new FormToolkit(_tabFolder.getDisplay());
         _form = _toolkit.createScrolledForm(_tabFolder);
         _form.getBody().setLayout(new GridLayout());
@@ -171,6 +170,13 @@ public class UserManagementTabControl ex
         
         String[] titles = { "Username", "JMX Management Rights" };
         int[] bounds = { 310, 200 };
+        if(!settingManagementRightsSupported())
+        {
+            //Since Qpid JMX API 2.3 / 1.12 only Username is used
+            titles = new String[]{ "Username"};
+            bounds = new int[]{ 310 };
+        }
+
         for (int i = 0; i < titles.length; i++) 
         {
             final int index = i;
@@ -214,7 +220,16 @@ public class UserManagementTabControl ex
         
         Composite buttonsComposite = _toolkit.createComposite(tableComposite);
         gridData = new GridData(SWT.FILL, SWT.TOP, false, false);
-        gridData.heightHint = 165;
+        if(!settingManagementRightsSupported())
+        {
+            //The 'Set Rights' button is not shown from Qpid JMX API 2.3 / 1.12
+            //onward, provide less space
+            gridData.heightHint = 135;
+        }
+        else
+        {
+            gridData.heightHint = 165;
+        }
         buttonsComposite.setLayoutData(gridData);
         buttonsComposite.setLayout(new GridLayout());
         
@@ -292,14 +307,14 @@ public class UserManagementTabControl ex
                     
                     if (returnValue  == InputDialog.OK)
                     {
-                        char[] password = id.getValue().toCharArray();
+                        char[] passwordArray = id.getValue().toCharArray();
 
                         // Qpid JMX API 1.1 and below expects the password to 
be sent as a hashed value.
                         if (_ApiVersion.lessThanOrEqualTo(1,1))
                         {
                             try
                             {
-                                password = ViewUtility.getHash(id.getValue());
+                                passwordArray = 
ViewUtility.getHash(id.getValue());
                             }
                             catch (Exception hashException)
                             {
@@ -312,7 +327,18 @@ public class UserManagementTabControl ex
 
                         try
                         {
-                            boolean result = _ummb.setPassword(user, password);
+                            boolean result;
+
+                            //For Qpid JMX API >=1.7 use String based method 
instead of older char[] based method.
+                            if(_ApiVersion.greaterThanOrEqualTo(1, 7))
+                            {
+                                result = _ummb.setPassword(user, 
id.getValue());
+                            }
+                            else
+                            {
+                                result = _ummb.setPassword(user, 
passwordArray);
+                            }
+
                             ViewUtility.operationResultFeedback(result, 
"Updated user password", "Failed to update user password");
                         }
                         catch(Exception e2)
@@ -324,25 +350,34 @@ public class UserManagementTabControl ex
                 }
             }
         });
-        
-        final Button setRightsButton = _toolkit.createButton(buttonsComposite, 
"Set Rights ...", SWT.PUSH);
-        gridData = new GridData(SWT.CENTER, SWT.BOTTOM, false, false);
-        gridData.widthHint = 125;
-        setRightsButton.setLayoutData(gridData);
-        setRightsButton.setEnabled(false);
-        setRightsButton.addSelectionListener(new SelectionAdapter()
+
+        final Button setRightsButton;
+        if(!settingManagementRightsSupported())
         {
-            public void widgetSelected(SelectionEvent e)
+            //The 'Set Rights' button is not used from Qpid JMX API 2.3 / 1.12 
onward
+            setRightsButton = null;
+        }
+        else
+        {
+            setRightsButton = _toolkit.createButton(buttonsComposite, "Set 
Rights ...", SWT.PUSH);
+            gridData = new GridData(SWT.CENTER, SWT.BOTTOM, false, false);
+            gridData.widthHint = 125;
+            setRightsButton.setLayoutData(gridData);
+            setRightsButton.setEnabled(false);
+            setRightsButton.addSelectionListener(new SelectionAdapter()
             {
-                int selectionIndex = _table.getSelectionIndex();
-
-                if (selectionIndex != -1)
+                public void widgetSelected(SelectionEvent e)
                 {
-                    setRights(setRightsButton.getShell());
+                    int selectionIndex = _table.getSelectionIndex();
+
+                    if (selectionIndex != -1)
+                    {
+                        setRights(setRightsButton.getShell());
+                    }
                 }
-            }
-        });
-        
+            });
+        }
+
         _tableViewer.addSelectionChangedListener(new 
ISelectionChangedListener(){
             public void selectionChanged(SelectionChangedEvent evt)
             {
@@ -351,14 +386,20 @@ public class UserManagementTabControl ex
                 if (selectionIndex == -1)
                 {
                     deleteUsersButton.setEnabled(false);
-                    setRightsButton.setEnabled(false);
                     setPasswordButton.setEnabled(false);
+                    if(setRightsButton != null)
+                    {
+                        setRightsButton.setEnabled(false);
+                    }
                     return;
                 }
                 else
                 {
                     deleteUsersButton.setEnabled(true);
-                    setRightsButton.setEnabled(true);
+                    if(setRightsButton != null)
+                    {
+                        setRightsButton.setEnabled(true);
+                    }
                 }
                 
                 if (_table.getSelectionCount() > 1)
@@ -386,11 +427,17 @@ public class UserManagementTabControl ex
             //this only reloaded the JMX rights file before Qpid JMX API 1.2
             _toolkit.createLabel(miscGroup, " Loads the current management 
rights file from disk");
         }
-        else
+        else if(settingManagementRightsSupported())
         {
-            //since Qpid JMX API 1.2 it also reloads the password file
+            //from Qpid JMX API 1.2 to 2.3 / 1.12 it also reloads the password 
file
             _toolkit.createLabel(miscGroup, " Loads the current password and 
management rights files from disk");
         }
+        else
+        {
+            //since Qpid JMX API 2.3 / 1.12 it only reloads the password file
+            _toolkit.createLabel(miscGroup, " Loads the current password 
data");
+        }
+
         reloadUserDetails.addSelectionListener(new SelectionAdapter()
         {
             public void widgetSelected(SelectionEvent e)
@@ -453,7 +500,7 @@ public class UserManagementTabControl ex
             {
                 case 0 : // username column 
                     return (String) ((CompositeData) element).get(USERNAME);
-                case 1 : // rights column 
+                case 1 : // rights column (used for API < 2.3 / 1.12)
                     return classifyUserRights((CompositeData) element);
                 default :
                     return "-";
@@ -510,11 +557,11 @@ public class UserManagementTabControl ex
             int comparison = 0;
             switch(column)
             {
-                case 0:
+                case 0: //username column
                     comparison = String.valueOf(user1.get(USERNAME)).compareTo(
                                                 
String.valueOf(user2.get(USERNAME)));
                     break;
-                case 1:
+                case 1: // rights column (used for API < 2.3 / 1.12)
                     comparison = 
classifyUserRights(user1).compareTo(classifyUserRights(user2));
                     break;
                 default:
@@ -555,7 +602,12 @@ public class UserManagementTabControl ex
     
     private void setRights(final Shell parent)
     {
-        
+        if(!settingManagementRightsSupported())
+        {
+            throw new UnsupportedOperationException("Setting management 
rights" +
+                        " is not supported using this version of the broker 
management API: " + (_ApiVersion));
+        }
+
         int selectionIndex = _table.getSelectionIndex();
 
         if (selectionIndex == -1)
@@ -699,6 +751,13 @@ public class UserManagementTabControl ex
         
         shell.open();
     }
+
+    protected boolean settingManagementRightsSupported()
+    {
+        //setting management access rights was supported until Qpid JMX API 
1.12 / 2.3
+        return _ApiVersion.lessThan(1,12) ||
+                (_ApiVersion.greaterThanOrEqualTo(2, 0) && 
_ApiVersion.lessThan(2,3));
+    }
     
     private void addUser(final Shell parent)
     {
@@ -706,7 +765,8 @@ public class UserManagementTabControl ex
         
         Composite usernameComposite = _toolkit.createComposite(shell, 
SWT.NONE);
         usernameComposite.setBackground(shell.getBackground());
-        usernameComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, 
false));
+        GridData usernameCompGridData = new GridData(SWT.FILL, SWT.TOP, true, 
false);
+        usernameComposite.setLayoutData(usernameCompGridData);
         usernameComposite.setLayout(new GridLayout(2,false));
         
         
_toolkit.createLabel(usernameComposite,"Username:").setBackground(shell.getBackground());
@@ -715,28 +775,45 @@ public class UserManagementTabControl ex
         
         Composite passwordComposite = _toolkit.createComposite(shell, 
SWT.NONE);
         passwordComposite.setBackground(shell.getBackground());
-        passwordComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, 
false));
+        GridData passwordCompGridData = new GridData(SWT.FILL, SWT.TOP, true, 
false);
+        passwordComposite.setLayoutData(passwordCompGridData);
         passwordComposite.setLayout(new GridLayout(2,false));
         
         
_toolkit.createLabel(passwordComposite,"Password:").setBackground(shell.getBackground());
         final Text passwordText = new Text(passwordComposite, SWT.BORDER | 
SWT.PASSWORD);
         passwordText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, 
false));
-        
-        Group buttonGroup = new Group(shell, SWT.NONE);
-        buttonGroup.setText("JMX Management Rights");
-        buttonGroup.setBackground(shell.getBackground());
-        buttonGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, 
false));
-        buttonGroup.setLayout(new GridLayout(4,false));
 
-        final Button noneButton = new Button(buttonGroup, SWT.RADIO);
-        noneButton.setText("No Access");
-        noneButton.setSelection(true);
-        final Button readButton = new Button(buttonGroup, SWT.RADIO);
-        readButton.setText("Read Only");
-        final Button writeButton = new Button(buttonGroup, SWT.RADIO);
-        writeButton.setText("Read + Write");
-        final Button adminButton = new Button(buttonGroup, SWT.RADIO);
-        adminButton.setText("Admin");
+        final Button readButton;
+        final Button writeButton;
+        final Button adminButton;
+        if(settingManagementRightsSupported())
+        {
+            Group buttonGroup = new Group(shell, SWT.NONE);
+            buttonGroup.setText("JMX Management Rights");
+            buttonGroup.setBackground(shell.getBackground());
+            buttonGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, 
false));
+            buttonGroup.setLayout(new GridLayout(4,false));
+
+            final Button noneButton = new Button(buttonGroup, SWT.RADIO);
+            noneButton.setText("No Access");
+            noneButton.setSelection(true);
+            readButton = new Button(buttonGroup, SWT.RADIO);
+            readButton.setText("Read Only");
+            writeButton = new Button(buttonGroup, SWT.RADIO);
+            writeButton.setText("Read + Write");
+            adminButton = new Button(buttonGroup, SWT.RADIO);
+            adminButton.setText("Admin");
+        }
+        else
+        {
+            readButton = null;
+            writeButton = null;
+            adminButton = null;
+            //The lack of rights settings will cause the dialog to,
+            //shrink so add width hints to the other components
+            passwordCompGridData.widthHint = 350;
+            usernameCompGridData.widthHint = 350;
+        }
 
         Composite okCancelButtonsComp = _toolkit.createComposite(shell);
         okCancelButtonsComp.setBackground(shell.getBackground());
@@ -784,22 +861,36 @@ public class UserManagementTabControl ex
                         return;
                     }
                 }
-                
-                boolean read = readButton.getSelection();
-                boolean write = writeButton.getSelection();
-                boolean admin = adminButton.getSelection();
+
+                //read the access rights selections if required
+                boolean read = false;
+                boolean write = false;
+                boolean admin = false;
+                if(settingManagementRightsSupported())
+                {
+                    read = readButton.getSelection();
+                    write = writeButton.getSelection();
+                    admin = adminButton.getSelection();
+                }
                 
                 shell.dispose();
                 try
                 {
                     boolean result = false;
-                    // If we have Qpid JMX API 1.7 or above, use newer 
createUser method with String based password.
-                    if (_ApiVersion.greaterThanOrEqualTo(1,7))
+
+                    if (!settingManagementRightsSupported())
+                    {
+                        // If we have Qpid JMX API 2.3 / 1.12 or above, use 
newer createUser method without rights parameters.
+                        result = _ummb.createUser(username, password);
+                    }
+                    else if (_ApiVersion.greaterThanOrEqualTo(1,7))
                     {
+                        // If we have Qpid JMX API 1.7 or above, use newer 
createUser method with String based password.
                         result = _ummb.createUser(username, password, read, 
write, admin);
                     }
                     else
                     {
+                        // Else we have Qpid JMX API 1.6 or below, use older 
createUser method with char[] based password.
                         result = _ummb.createUser(username, passwordChars, 
read, write, admin);
                     }
                     



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to