diff options
10 files changed, 131 insertions, 273 deletions
diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ICommandIds.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ICommandIds.java deleted file mode 100644 index 12dea649c6..0000000000 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ICommandIds.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * 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; - -/** - * Interface defining the application's command IDs. - * Key bindings can be defined for specific commands. - * To associate an action with a command, use IAction.setActionDefinitionId(commandId). - * - * @see org.eclipse.jface.action.IAction#setActionDefinitionId(String) - */ -public interface ICommandIds -{ - //public static final String CMD_ADD_SERVER = "org.apache.qpid.management.ui.add"; - //public static final String CMD_RECONNECT_SERVER = "org.apache.qpid.management.ui.reconnect"; - //public static final String CMD_DISCONNECT_SERVER = "org.apache.qpid.management.ui.disconnect"; - //public static final String CMD_REFRESH = "org.apache.qpid.management.ui.actions.refresh"; -} diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AbstractAction.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AbstractAction.java index b1cf942e37..f70452dd42 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AbstractAction.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AbstractAction.java @@ -26,15 +26,24 @@ import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; import org.apache.qpid.management.ui.Constants; import org.apache.qpid.management.ui.jmx.MBeanUtility; +import org.apache.qpid.management.ui.views.NavigationView; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class AbstractAction { + private NavigationView _navigationView; + protected IWorkbenchWindow _window; + + public static final String RMI_SASL_ERROR = "non-JRMP server"; + public static final String SECURITY_FAILURE = "User authentication has failed"; + public static final String SERVER_UNAVAILABLE = "Qpid server is not running"; /** * We will cache window object in order to @@ -48,8 +57,19 @@ public class AbstractAction { _window.getShell().setImage(ApplicationRegistry.getImage(Constants.CONSOLE_IMAGE)); } + } + + protected NavigationView getNavigationView() + { + if (_navigationView == null) + { + _navigationView = (NavigationView)_window.getActivePage().findView(NavigationView.ID); + } + + return _navigationView; } + protected void handleException(Throwable ex, String title, String msg) { MBeanUtility.printStackTrace(ex); @@ -75,4 +95,21 @@ public class AbstractAction IStatus.OK, msg, null); ErrorDialog.openError(_window.getShell(), "Error", title, status); } + + + /** + * Selection in the workbench has been changed. We can change the state of the 'real' action here + * if we want, but this can only happen after the delegate has been created. + * @see IWorkbenchWindowActionDelegate#selectionChanged + */ + public void selectionChanged(IAction action, ISelection selection) { + } + + /** + * We can use this method to dispose of any system resources we previously allocated. + * @see IWorkbenchWindowActionDelegate#dispose + */ + public void dispose() { + + } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java index ff0f42b49e..c13f54929d 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java @@ -22,13 +22,13 @@ package org.apache.qpid.management.ui.actions; import static org.apache.qpid.management.ui.Constants.*; +import java.io.IOException; + import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; -import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.NumberVerifyListener; import org.apache.qpid.management.ui.views.ViewUtility; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -47,7 +47,6 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD { private static final String[] _domains ={"org.apache.qpid"}; - private NavigationView _navigationView; private String _transport = DEFAULT_PROTOCOL; private String _host; private String _port; @@ -62,19 +61,6 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD } - /* - public AddServer(IWorkbenchWindow window)//, String label) - { - _window = window; - //setText(label); - // The id is used to refer to the action in a menu or toolbar - setId(ICommandIds.CMD_ADD_SERVER); - // Associate the action with a pre-defined command, to allow key bindings. - setActionDefinitionId(ICommandIds.CMD_ADD_SERVER); - //setImageDescriptor(org.apache.qpid.management.ui.Activator.getImageDescriptor("/icons/add.gif")); - } - */ - public void run(IAction action) { if(_window != null) @@ -92,6 +78,17 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD { ViewUtility.popupInfoMessage(ACTION_ADDSERVER, ex.getMessage()); } + catch (IOException ex) + { + if ((ex.getMessage() != null) && (ex.getMessage().indexOf(RMI_SASL_ERROR) != -1)) + { + handleException(ex, null, SECURITY_FAILURE); + } + else + { + handleException(ex, null, SERVER_UNAVAILABLE); + } + } catch (Exception ex) { handleException(ex, null, null); @@ -110,45 +107,6 @@ public class AddServer extends AbstractAction implements IWorkbenchWindowActionD } /** - * Selection in the workbench has been changed. We - * can change the state of the 'real' action here - * if we want, but this can only happen after - * the delegate has been created. - * @see IWorkbenchWindowActionDelegate#selectionChanged - */ - public void selectionChanged(IAction action, ISelection selection) { - } - - /** - * We can use this method to dispose of any system - * resources we previously allocated. - * @see IWorkbenchWindowActionDelegate#dispose - */ - public void dispose() { - - } - - private NavigationView getNavigationView() - { - if (_navigationView == null) - { - _navigationView = (NavigationView)_window.getActivePage().findView(NavigationView.ID); - } - - return _navigationView; - } - - /* - public void run() - { - if(_window != null) - { - createWidgets(); - } - } - */ - - /** * Creates the shell and then opens the popup where user can enter new connection details. * Connects to the new server and adds the server in the navigation page. * Pops up any error occured in connecting to the new server diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java index 3907424748..a3e52149df 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java @@ -25,7 +25,6 @@ import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.ViewUtility; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class CloseConnection extends AbstractAction implements IWorkbenchWindowActionDelegate @@ -53,24 +52,5 @@ public class CloseConnection extends AbstractAction implements IWorkbenchWindowA handleException(ex, null, null); } } - } - - /** - * Selection in the workbench has been changed. We - * can change the state of the 'real' action here - * if we want, but this can only happen after - * the delegate has been created. - * @see IWorkbenchWindowActionDelegate#selectionChanged - */ - public void selectionChanged(IAction action, ISelection selection) { - } - - /** - * We can use this method to dispose of any system - * resources we previously allocated. - * @see IWorkbenchWindowActionDelegate#dispose - */ - public void dispose() { - - } + } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java index 69e74898ab..d3af3661b0 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java @@ -25,7 +25,6 @@ import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.MBeanView; import org.apache.qpid.management.ui.views.ViewUtility; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class EditAttribute extends AbstractAction implements IWorkbenchWindowActionDelegate @@ -49,23 +48,4 @@ public class EditAttribute extends AbstractAction implements IWorkbenchWindowAct } } } - - /** - * Selection in the workbench has been changed. We - * can change the state of the 'real' action here - * if we want, but this can only happen after - * the delegate has been created. - * @see IWorkbenchWindowActionDelegate#selectionChanged - */ - public void selectionChanged(IAction action, ISelection selection) { - } - - /** - * We can use this method to dispose of any system - * resources we previously allocated. - * @see IWorkbenchWindowActionDelegate#dispose - */ - public void dispose() { - - } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java index 3c0dea586e..609484a557 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java @@ -27,14 +27,14 @@ import static org.apache.qpid.management.ui.Constants.INFO_USERNAME; import static org.apache.qpid.management.ui.Constants.PASSWORD; import static org.apache.qpid.management.ui.Constants.USERNAME; +import java.io.IOException; + import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.Constants; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; -import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.TreeObject; import org.apache.qpid.management.ui.views.ViewUtility; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -50,45 +50,12 @@ import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class ReconnectServer extends AbstractAction implements IWorkbenchWindowActionDelegate { - private NavigationView _navigationView; private String _title; private String _serverName; private String _user; private String _password; private boolean _connect; - /** - * Selection in the workbench has been changed. We - * can change the state of the 'real' action here - * if we want, but this can only happen after - * the delegate has been created. - * @see IWorkbenchWindowActionDelegate#selectionChanged - */ - public void selectionChanged(IAction action, ISelection selection) - { - - } - - /** - * We can use this method to dispose of any system - * resources we previously allocated. - * @see IWorkbenchWindowActionDelegate#dispose - */ - public void dispose() - { - - } - - private NavigationView getNavigationView() - { - if (_navigationView == null) - { - _navigationView = (NavigationView)_window.getActivePage().findView(NavigationView.ID); - } - - return _navigationView; - } - public void run(IAction action) { if(_window != null) @@ -114,6 +81,17 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA { ViewUtility.popupInfoMessage("Reconnect Qpid server", ex.getMessage()); } + catch (IOException ex) + { + if ((ex.getMessage() != null) && (ex.getMessage().indexOf(RMI_SASL_ERROR) != -1)) + { + handleException(ex, null, SECURITY_FAILURE); + } + else + { + handleException(ex, null, SERVER_UNAVAILABLE); + } + } catch (Exception ex) { handleException(ex, null, null); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java index b76c36c649..34251c12d7 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java @@ -24,7 +24,6 @@ import org.apache.qpid.management.ui.jmx.MBeanUtility; import org.apache.qpid.management.ui.views.MBeanView; import org.apache.qpid.management.ui.views.NavigationView; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** @@ -32,29 +31,7 @@ import org.eclipse.ui.IWorkbenchWindowActionDelegate; * @author Bhupendra Bhardwaj */ public class Refresh extends AbstractAction implements IWorkbenchWindowActionDelegate -{ - /** - * Selection in the workbench has been changed. We - * can change the state of the 'real' action here - * if we want, but this can only happen after - * the delegate has been created. - * @see IWorkbenchWindowActionDelegate#selectionChanged - */ - public void selectionChanged(IAction action, ISelection selection) - { - - } - - /** - * We can use this method to dispose of any system - * resources we previously allocated. - * @see IWorkbenchWindowActionDelegate#dispose - */ - public void dispose() - { - - } - +{ public void run(IAction action) { if(_window != null) diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java index f8878c44a1..e329255414 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java @@ -24,33 +24,10 @@ import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.ViewUtility; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class RemoveServer extends AbstractAction implements IWorkbenchWindowActionDelegate -{ - /** - * Selection in the workbench has been changed. We - * can change the state of the 'real' action here - * if we want, but this can only happen after - * the delegate has been created. - * @see IWorkbenchWindowActionDelegate#selectionChanged - */ - public void selectionChanged(IAction action, ISelection selection) - { - - } - - /** - * We can use this method to dispose of any system - * resources we previously allocated. - * @see IWorkbenchWindowActionDelegate#dispose - */ - public void dispose() - { - - } - +{ public void run(IAction action) { if(_window != null) diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java index 02d9ed7fdc..ddc529ba3a 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/JMXServerRegistry.java @@ -39,6 +39,7 @@ import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; +import javax.security.auth.callback.CallbackHandler; import javax.security.sasl.SaslClientFactory; import org.apache.qpid.management.ui.ApplicationRegistry; @@ -58,6 +59,8 @@ import org.apache.qpid.management.ui.sasl.UsernameHashedPasswordCallbackHandler; public class JMXServerRegistry extends ServerRegistry { private ObjectName _serverObjectName = null; + private Map<String, Object> _env = null; + private JMXServiceURL _jmxUrl = null; private JMXConnector _jmxc = null; private MBeanServerConnection _mbsc = null; @@ -92,59 +95,27 @@ public class JMXServerRegistry extends ServerRegistry public JMXServerRegistry(ManagedServer server) throws Exception { super(server); - JMXServiceURL jmxUrl = new JMXServiceURL(server.getUrl()); - Map<String, Object> env = null; String securityMechanism = ApplicationRegistry.getSecurityMechanism(); + boolean saslPluginAvailable = false; if (securityMechanism != null) - { - // Check if the JMXMP connector is available - Class klass = Class.forName("javax.management.remote.jmxmp.JMXMPConnector"); - - jmxUrl = new JMXServiceURL("jmxmp", server.getHost(), server.getPort()); - env = new HashMap<String, Object>(); - - if (MECH_CRAMMD5.equals(securityMechanism)) - { - // For SASL/CRAM-MD5 - Map<String, Class<? extends SaslClientFactory>> map = new HashMap<String, Class<? extends SaslClientFactory>>(); - Class<?> clazz = Class.forName("org.apache.qpid.management.ui.sasl.CRAMMD5HashedSaslClientFactory"); - map.put("CRAM-MD5-HASHED", (Class<? extends SaslClientFactory>) clazz); - - Security.addProvider(new JCAProvider(map)); - env.put("jmx.remote.profiles", SASL_CRAMMD5); - env.put("jmx.remote.sasl.callback.handler", - new UsernameHashedPasswordCallbackHandler(server.getUser(), server.getPassword())); - } - else if (MECH_PLAIN.equals(securityMechanism)) + { + try { - // For SASL/PLAIN - Security.addProvider(new SaslProvider()); - env.put("jmx.remote.profiles", SASL_PLAIN); - env.put("jmx.remote.sasl.callback.handler", - new UserPasswordCallbackHandler(server.getUser(), server.getPassword())); + createSASLConnector(securityMechanism); + saslPluginAvailable = true; } - else + catch (Exception ex) { - String text = "Security mechanism " + securityMechanism + " is not supported."; - MBeanUtility.printOutput(text); - throw new Exception(text); + ex.printStackTrace(); + saslPluginAvailable = false; } - // Now create the instance of JMXMPConnector - Class[] paramTypes = {JMXServiceURL.class, Map.class}; - Constructor cons = klass.getConstructor(paramTypes); - - Object[] args = {jmxUrl, env}; - Object theObject = cons.newInstance(args); - - _jmxc = (JMXConnector)theObject; - _jmxc.connect(); - MBeanUtility.printOutput("Starting JMXConnector with SASL. Server=" + server.getName()); } - else + + if (!saslPluginAvailable) { - jmxUrl = new JMXServiceURL(server.getUrl()); - _jmxc = JMXConnectorFactory.connect(jmxUrl, null); + _jmxUrl = new JMXServiceURL(server.getUrl()); + _jmxc = JMXConnectorFactory.connect(_jmxUrl, null); } _mbsc = _jmxc.getMBeanServerConnection(); @@ -162,6 +133,53 @@ public class JMXServerRegistry extends ServerRegistry return _mbsc; } + private void createSASLConnector(String mech) throws Exception + { + String text = "Security mechanism " + mech + " is not supported."; + // Check if the JMXMP connector is available + Class klass = Class.forName("javax.management.remote.jmxmp.JMXMPConnector"); + + _jmxUrl = new JMXServiceURL("jmxmp", getManagedServer().getHost(), getManagedServer().getPort()); + _env = new HashMap<String, Object>(); + CallbackHandler handler; + if (MECH_CRAMMD5.equals(mech)) + { + // For SASL/CRAM-MD5 + Map<String, Class<? extends SaslClientFactory>> map = new HashMap<String, Class<? extends SaslClientFactory>>(); + Class<?> clazz = Class.forName("org.apache.qpid.management.ui.sasl.CRAMMD5HashedSaslClientFactory"); + map.put("CRAM-MD5-HASHED", (Class<? extends SaslClientFactory>) clazz); + + Security.addProvider(new JCAProvider(map)); + handler = new UsernameHashedPasswordCallbackHandler(getManagedServer().getUser(), + getManagedServer().getPassword()); + _env.put("jmx.remote.profiles", SASL_CRAMMD5); + _env.put("jmx.remote.sasl.callback.handler", handler); + + } + else if (MECH_PLAIN.equals(mech)) + { + // For SASL/PLAIN + Security.addProvider(new SaslProvider()); + handler = new UserPasswordCallbackHandler(getManagedServer().getUser(), getManagedServer().getPassword()); + _env.put("jmx.remote.profiles", SASL_PLAIN); + _env.put("jmx.remote.sasl.callback.handler", handler); + } + else + { + MBeanUtility.printOutput(text); + throw new Exception(text); + } + // Now create the instance of JMXMPConnector + Class[] paramTypes = {JMXServiceURL.class, Map.class}; + Constructor cons = klass.getConstructor(paramTypes); + + Object[] args = {_jmxUrl, _env}; + Object theObject = cons.newInstance(args); + + _jmxc = (JMXConnector)theObject; + _jmxc.connect(); + } + /** * removes all listeners from the mbean server. This is required when user * disconnects the Qpid server connection diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java index 2a1a18939f..1da13a9b56 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java @@ -208,20 +208,9 @@ public class NavigationView extends ViewPart */ private void createRMIServerConnection(ManagedServer server) throws Exception { - try - { - // Currently Qpid Management Console only supports JMX MBeanServer - ServerRegistry serverRegistry = new JMXServerRegistry(server); - ApplicationRegistry.addServer(server, serverRegistry); - } - catch (IOException ex) - { - if (ex.getCause() == null) - { - throw ex; - } - throw (Exception)ex.getCause(); - } + // Currently Qpid Management Console only supports JMX MBeanServer + ServerRegistry serverRegistry = new JMXServerRegistry(server); + ApplicationRegistry.addServer(server, serverRegistry); } /** |