Author: rgodfrey Date: Wed May 16 12:59:07 2012 New Revision: 1339146 URL: http://svn.apache.org/viewvc?rev=1339146&view=rev Log: QPID-3997 : [Java Broker] Refactor code to make all calls to getAuthenticationManager() pass in local socket address (note that this commit does not actually implement per socket authentication managers)
Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerConnectionMBeanTest.java Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionSecureOkMethodHandler.java Wed May 16 12:59:07 2012 @@ -61,7 +61,7 @@ public class ConnectionSecureOkMethodHan { AMQProtocolSession session = stateManager.getProtocolSession(); - AuthenticationManager authMgr = ApplicationRegistry.getInstance().getAuthenticationManager(); + AuthenticationManager authMgr = stateManager.getAuthenticationManager(); SaslServer ss = session.getSaslServer(); if (ss == null) Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/handler/ConnectionStartOkMethodHandler.java Wed May 16 12:59:07 2012 @@ -65,7 +65,7 @@ public class ConnectionStartOkMethodHand _logger.info("SASL Mechanism selected: " + body.getMechanism()); _logger.info("Locale selected: " + body.getLocale()); - AuthenticationManager authMgr = ApplicationRegistry.getInstance().getAuthenticationManager(); + AuthenticationManager authMgr = stateManager.getAuthenticationManager(); SaslServer ss = null; try { Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java Wed May 16 12:59:07 2012 @@ -54,10 +54,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.reflect.Proxy; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.UnknownHostException; +import java.net.*; import java.rmi.AlreadyBoundException; import java.rmi.NoSuchObjectException; import java.rmi.NotBoundException; @@ -197,7 +194,7 @@ public class JMXManagedObjectRegistry im //add a JMXAuthenticator implementation the env map to authenticate the RMI based JMX connector server RMIPasswordAuthenticator rmipa = new RMIPasswordAuthenticator(); - rmipa.setAuthenticationManager(appRegistry.getAuthenticationManager()); + rmipa.setAuthenticationManager(appRegistry.getAuthenticationManager(new InetSocketAddress(_jmxPortRegistryServer))); HashMap<String,Object> env = new HashMap<String,Object>(); env.put(JMXConnectorServer.AUTHENTICATOR, rmipa); Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java Wed May 16 12:59:07 2012 @@ -389,7 +389,7 @@ public class AMQProtocolEngine implement // This sets the protocol version (and hence framing classes) for this session. setProtocolVersion(pv); - String mechanisms = ApplicationRegistry.getInstance().getAuthenticationManager().getMechanisms(); + String mechanisms = ApplicationRegistry.getInstance().getAuthenticationManager(getLocalAddress()).getMechanisms(); String locales = "en_US"; Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java Wed May 16 12:59:07 2012 @@ -20,6 +20,7 @@ */ package org.apache.qpid.server.protocol; +import java.net.SocketAddress; import java.util.List; import javax.security.auth.Subject; @@ -60,6 +61,13 @@ public interface AMQProtocolSession exte long getLastReceivedTime(); + /** + * Return the local socket address for the connection + * + * @return the socket address + */ + SocketAddress getLocalAddress(); + public static interface Task { public void doTask(AMQProtocolSession session) throws AMQException; Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java Wed May 16 12:59:07 2012 @@ -302,7 +302,7 @@ public class MultiVersionProtocolEngine public ServerProtocolEngine getProtocolEngine() { final ConnectionDelegate connDelegate = - new org.apache.qpid.server.transport.ServerConnectionDelegate(_appRegistry, _fqdn); + new org.apache.qpid.server.transport.ServerConnectionDelegate(_appRegistry, _fqdn, _appRegistry.getAuthenticationManager(getLocalAddress())); ServerConnection conn = new ServerConnection(_id); conn.setConnectionDelegate(connDelegate); Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java Wed May 16 12:59:07 2012 @@ -143,7 +143,7 @@ public class ProtocolEngine_1_0_0 implem Container container = new Container(_appRegistry.getBrokerId().toString()); - _conn = new ConnectionEndpoint(container,asCallbackHandlerSource(_appRegistry.getAuthenticationManager())); + _conn = new ConnectionEndpoint(container,asCallbackHandlerSource(_appRegistry.getAuthenticationManager(getLocalAddress()))); _conn.setConnectionEventListener(new Connection_1_0(_appRegistry)); _conn.setFrameOutputHandler(this); _conn.setRemoteAddress(_network.getRemoteAddress()); Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java Wed May 16 12:59:07 2012 @@ -164,7 +164,7 @@ public class ProtocolEngine_1_0_0_SASL i Container container = new Container(_appRegistry.getBrokerId().toString()); _conn = new ConnectionEndpoint(container, asCallbackHandlerSource(ApplicationRegistry.getInstance() - .getAuthenticationManager())); + .getAuthenticationManager(getLocalAddress()))); _conn.setConnectionEventListener(new Connection_1_0(_appRegistry)); _conn.setRemoteAddress(getRemoteAddress()); Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java Wed May 16 12:59:07 2012 @@ -60,6 +60,7 @@ import org.apache.qpid.server.virtualhos import org.apache.qpid.server.virtualhost.VirtualHostRegistry; import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -131,11 +132,6 @@ public abstract class ApplicationRegistr _managedObjectRegistry = managedObjectRegistry; } - protected void setAuthenticationManager(AuthenticationManager authenticationManager) - { - _authenticationManager = authenticationManager; - } - protected void setVirtualHostRegistry(VirtualHostRegistry virtualHostRegistry) { _virtualHostRegistry = virtualHostRegistry; @@ -622,6 +618,14 @@ public abstract class ApplicationRegistr return _authenticationManager; } + + @Override + public AuthenticationManager getAuthenticationManager(SocketAddress address) + { + return _authenticationManager; + } + + public PluginManager getPluginManager() { return _pluginManager; Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/IApplicationRegistry.java Wed May 16 12:59:07 2012 @@ -37,6 +37,7 @@ import org.apache.qpid.server.virtualhos import org.apache.qpid.server.virtualhost.VirtualHostRegistry; import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.util.UUID; public interface IApplicationRegistry extends StatisticsGatherer @@ -62,8 +63,26 @@ public interface IApplicationRegistry ex ManagedObjectRegistry getManagedObjectRegistry(); + /** + * Get the default AuthenticationManager + * + * @deprecated + * + * @return the AuthenticationManager + */ AuthenticationManager getAuthenticationManager(); + /** + * Get the AuthenticationManager for the given socket address + * + * If no AuthenticationManager has been specifically set for the given address, then use the default + * AuthenticationManager + * + * @param address The (listening) socket address for which the AuthenticationManager is required + * @return the AuthenticationManager + */ + AuthenticationManager getAuthenticationManager(SocketAddress address); + VirtualHostRegistry getVirtualHostRegistry(); SecurityManager getSecurityManager(); Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/state/AMQStateManager.java Wed May 16 12:59:07 2012 @@ -32,7 +32,9 @@ import org.apache.qpid.protocol.AMQConst import org.apache.qpid.protocol.AMQMethodEvent; import org.apache.qpid.protocol.AMQMethodListener; import org.apache.qpid.server.protocol.AMQProtocolSession; +import org.apache.qpid.server.registry.IApplicationRegistry; import org.apache.qpid.server.security.SecurityManager; +import org.apache.qpid.server.security.auth.manager.AuthenticationManager; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; import java.util.concurrent.CopyOnWriteArraySet; @@ -61,6 +63,18 @@ public class AMQStateManager implements } + /** + * Get the ApplicationRegistry associated with this AMQStateManager + * + * returns the application registry associated with the VirtualHostRegistry of the AMQStateManager + * + * @return the ApplicationRegistry + */ + public IApplicationRegistry getApplicationRegistry() + { + return _virtualHostRegistry.getApplicationRegistry(); + } + public AMQState getCurrentState() { return _currentState; @@ -142,4 +156,14 @@ public class AMQStateManager implements SecurityManager.setThreadSubject(_protocolSession.getAuthorizedSubject()); return _protocolSession; } + + /** + * Get the AuthenticationManager associated with the ProtocolSession of the AMQStateManager + * + * @return the AuthenticationManager + */ + public AuthenticationManager getAuthenticationManager() + { + return getApplicationRegistry().getAuthenticationManager(getProtocolSession().getLocalAddress()); + } } Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java (original) +++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerConnectionDelegate.java Wed May 16 12:59:07 2012 @@ -32,6 +32,7 @@ import org.apache.qpid.server.registry.I import org.apache.qpid.server.security.SecurityManager; import org.apache.qpid.server.security.auth.AuthenticationResult; import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus; +import org.apache.qpid.server.security.auth.manager.AuthenticationManager; import org.apache.qpid.server.subscription.Subscription_0_10; import org.apache.qpid.server.virtualhost.State; import org.apache.qpid.server.virtualhost.VirtualHost; @@ -58,22 +59,25 @@ public class ServerConnectionDelegate ex private final IApplicationRegistry _appRegistry; private int _maxNoOfChannels; private Map<String,Object> _clientProperties; + private final AuthenticationManager _authManager; - public ServerConnectionDelegate(IApplicationRegistry appRegistry, String localFQDN) + public ServerConnectionDelegate(IApplicationRegistry appRegistry, String localFQDN, AuthenticationManager authManager) { - this(createConnectionProperties(appRegistry.getBroker()), Collections.singletonList((Object)"en_US"), appRegistry, localFQDN); + this(createConnectionProperties(appRegistry.getBroker()), Collections.singletonList((Object)"en_US"), appRegistry, localFQDN, authManager); } - public ServerConnectionDelegate(Map<String, Object> properties, + private ServerConnectionDelegate(Map<String, Object> properties, List<Object> locales, IApplicationRegistry appRegistry, - String localFQDN) + String localFQDN, + AuthenticationManager authManager) { - super(properties, parseToList(appRegistry.getAuthenticationManager().getMechanisms()), locales); + super(properties, parseToList(authManager.getMechanisms()), locales); _appRegistry = appRegistry; _localFQDN = localFQDN; - _maxNoOfChannels = ApplicationRegistry.getInstance().getConfiguration().getMaxChannelCount(); + _maxNoOfChannels = appRegistry.getConfiguration().getMaxChannelCount(); + _authManager = authManager; } private static Map<String, Object> createConnectionProperties(final BrokerConfig brokerConfig) @@ -110,13 +114,13 @@ public class ServerConnectionDelegate ex protected SaslServer createSaslServer(String mechanism) throws SaslException { - return _appRegistry.getAuthenticationManager().createSaslServer(mechanism, _localFQDN); + return _authManager.createSaslServer(mechanism, _localFQDN); } protected void secure(final SaslServer ss, final Connection conn, final byte[] response) { - final AuthenticationResult authResult = _appRegistry.getAuthenticationManager().authenticate(ss, response); + final AuthenticationResult authResult = _authManager.authenticate(ss, response); final ServerConnection sconn = (ServerConnection) conn; Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerConnectionMBeanTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerConnectionMBeanTest.java?rev=1339146&r1=1339145&r2=1339146&view=diff ============================================================================== --- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerConnectionMBeanTest.java (original) +++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/transport/ServerConnectionMBeanTest.java Wed May 16 12:59:07 2012 @@ -32,6 +32,7 @@ import org.apache.qpid.transport.Session import javax.management.JMException; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; +import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -80,7 +81,7 @@ public class ServerConnectionMBeanTest e "authid", "remoteProcessName", new Integer(1967), new Integer(1970), vhost.getConfigStore(), Boolean.FALSE); _serverConnection.setConnectionConfig(config); _serverConnection.setVirtualHost(vhost); - _serverConnection.setConnectionDelegate(new ServerConnectionDelegate(getRegistry(), "")); + _serverConnection.setConnectionDelegate(new ServerConnectionDelegate(getRegistry(), "", getRegistry().getAuthenticationManager(new InetSocketAddress(5672)))); _serverSession = new ServerSessionMock(_serverConnection, 1); _mbean = (ServerConnectionMBean) _serverConnection.getManagedObject(); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org