Author: david.lloyd(a)jboss.com
Date: 2010-03-09 09:53:39 -0500 (Tue, 09 Mar 2010)
New Revision: 5813
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionProvider.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NetworkServerProvider.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/AbstractRemoteTestCase.java
Log:
Move authentication to the network server provider interface
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2010-03-09
14:53:10 UTC (rev 5812)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2010-03-09
14:53:39 UTC (rev 5813)
@@ -663,9 +663,6 @@
if (sm != null) {
sm.checkPermission(ADD_PROTOCOL_SERVICE_PERM);
}
- if ("default".equals(name)) {
- throw new IllegalArgumentException("'default' is not an allowed
name");
- }
if (map.putIfAbsent(name, provider) != null) {
throw new DuplicateRegistrationException(type.getDescription() + "
'" + name + "' is already registered");
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java 2010-03-09
14:53:10 UTC (rev 5812)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemotingOptions.java 2010-03-09
14:53:39 UTC (rev 5813)
@@ -140,11 +140,6 @@
public static final Option<Boolean> CALL_BY_VALUE =
Option.simple(RemotingOptions.class, "CALL_BY_VALUE", Boolean.class);
/**
- * Specify the name of a preregistered server authentication provider to use.
- */
- public static final Option<String> AUTHENTICATION_PROVIDER =
Option.simple(RemotingOptions.class, "AUTHENTICATION_PROVIDER", String.class);
-
- /**
* Specify the number of times a client is allowed to retry authentication before
closing the connection.
*/
public static final Option<Integer> AUTHENTICATION_RETRIES =
Option.simple(RemotingOptions.class, "AUTHENTICATION_RETRIES", Integer.class);
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionProvider.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionProvider.java 2010-03-09
14:53:10 UTC (rev 5812)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionProvider.java 2010-03-09
14:53:39 UTC (rev 5813)
@@ -95,13 +95,8 @@
}
private class ProviderInterface implements NetworkServerProvider {
- public ChannelListener<ConnectedStreamChannel<InetSocketAddress>>
getServerListener(final OptionMap optionMap) {
- final String providerName =
optionMap.get(RemotingOptions.AUTHENTICATION_PROVIDER);
- final ServerAuthenticationProvider authenticationProvider =
connectionProviderContext.getProtocolServiceProvider(ProtocolServiceType.SERVER_AUTHENTICATION_PROVIDER,
providerName == null ? "default" : providerName);
- if (authenticationProvider == null) {
- throw new IllegalArgumentException("Missing authentication provider:
" + (providerName == null ? "default" : providerName));
- }
- return new ServerOpenListener(optionMap, connectionProviderContext,
providerDescriptor);
+ public ChannelListener<ConnectedStreamChannel<InetSocketAddress>>
getServerListener(final OptionMap optionMap, final ServerAuthenticationProvider
authenticationProvider) {
+ return new ServerOpenListener(optionMap, connectionProviderContext,
providerDescriptor, authenticationProvider);
}
}
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java 2010-03-09
14:53:10 UTC (rev 5812)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java 2010-03-09
14:53:39 UTC (rev 5813)
@@ -32,10 +32,8 @@
import java.util.Map;
import java.util.Set;
import org.jboss.marshalling.ProviderDescriptor;
-import org.jboss.remoting3.RemotingOptions;
import org.jboss.remoting3.security.ServerAuthenticationProvider;
import org.jboss.remoting3.spi.ConnectionProviderContext;
-import org.jboss.remoting3.spi.ProtocolServiceType;
import org.jboss.xnio.ChannelListener;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.OptionMap;
@@ -55,12 +53,14 @@
private final OptionMap optionMap;
private final ConnectionProviderContext connectionProviderContext;
private final ProviderDescriptor providerDescriptor;
+ private final ServerAuthenticationProvider authenticationProvider;
private static final Logger log = Loggers.serverSasl;
- ServerOpenListener(final OptionMap optionMap, final ConnectionProviderContext
connectionProviderContext, final ProviderDescriptor providerDescriptor) {
+ ServerOpenListener(final OptionMap optionMap, final ConnectionProviderContext
connectionProviderContext, final ProviderDescriptor providerDescriptor, final
ServerAuthenticationProvider authenticationProvider) {
this.optionMap = optionMap;
this.connectionProviderContext = connectionProviderContext;
this.providerDescriptor = providerDescriptor;
+ this.authenticationProvider = authenticationProvider;
}
public void handleEvent(final ConnectedStreamChannel<InetSocketAddress>
channel) {
@@ -71,20 +71,6 @@
}
final RemoteConnection connection = new
RemoteConnection(connectionProviderContext.getExecutor(), channel, optionMap,
providerDescriptor);
- // Get the server authentication provider
- final String authProvider =
optionMap.get(RemotingOptions.AUTHENTICATION_PROVIDER);
- if (authProvider == null) {
- log.warn("No authentication provider available");
- IoUtils.safeClose(connection);
- return;
- }
- final ServerAuthenticationProvider provider =
connectionProviderContext.getProtocolServiceProvider(ProtocolServiceType.SERVER_AUTHENTICATION_PROVIDER,
authProvider);
- if (provider == null) {
- log.warn("No authentication provider available");
- IoUtils.safeClose(connection);
- return;
- }
-
// Calculate available server mechanisms
final Sequence<String> mechs = optionMap.get(Options.SASL_MECHANISMS);
final Set<String> includes = mechs != null ? new
HashSet<String>(mechs) : null;
@@ -176,7 +162,7 @@
}
}
});
- connection.setMessageHandler(new ServerGreetingHandler(connection,
connectionProviderContext, saslServerFactories, provider, propertyMap));
+ connection.setMessageHandler(new ServerGreetingHandler(connection,
connectionProviderContext, saslServerFactories, authenticationProvider, propertyMap));
// and send the greeting
channel.resumeWrites();
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NetworkServerProvider.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NetworkServerProvider.java 2010-03-09
14:53:10 UTC (rev 5812)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NetworkServerProvider.java 2010-03-09
14:53:39 UTC (rev 5813)
@@ -23,6 +23,7 @@
package org.jboss.remoting3.spi;
import java.net.InetSocketAddress;
+import org.jboss.remoting3.security.ServerAuthenticationProvider;
import org.jboss.xnio.ChannelListener;
import org.jboss.xnio.OptionMap;
import org.jboss.xnio.channels.ConnectedStreamChannel;
@@ -36,7 +37,8 @@
* Get the channel open listener for servers of this connection provider type.
*
* @param optionMap options which may be used to configure the returned server
+ * @param authenticationProvider the server authentication provider
* @return the channel listener
*/
- ChannelListener<ConnectedStreamChannel<InetSocketAddress>>
getServerListener(OptionMap optionMap);
+ ChannelListener<ConnectedStreamChannel<InetSocketAddress>>
getServerListener(OptionMap optionMap, ServerAuthenticationProvider
authenticationProvider);
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java 2010-03-09
14:53:10 UTC (rev 5812)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ProtocolServiceType.java 2010-03-09
14:53:39 UTC (rev 5813)
@@ -78,8 +78,6 @@
public static final ProtocolServiceType<ClassExternalizerFactory>
CLASS_EXTERNALIZER_FACTORY;
- public static final ProtocolServiceType<ServerAuthenticationProvider>
SERVER_AUTHENTICATION_PROVIDER;
-
private static final ProtocolServiceType<?>[] SERVICE_TYPES;
public static ProtocolServiceType<?>[] getServiceTypes() {
@@ -99,7 +97,6 @@
CLASS_RESOLVER = new
ProtocolServiceType<ClassResolver>(ClassResolver.class, "CLASS_RESOLVER",
"Class resolver", index++),
OBJECT_RESOLVER = new
ProtocolServiceType<ObjectResolver>(ObjectResolver.class,
"OBJECT_RESOLVER", "Object resolver", index++),
CLASS_EXTERNALIZER_FACTORY = new
ProtocolServiceType<ClassExternalizerFactory>(ClassExternalizerFactory.class,
"CLASS_EXTERNALIZER_FACTORY", "Class externalizer factory", index++),
- SERVER_AUTHENTICATION_PROVIDER = new
ProtocolServiceType<ServerAuthenticationProvider>(ServerAuthenticationProvider.class,
"SERVER_AUTHENTICATION_PROVIDER", "Server authentication provider",
index++)
};
}
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/AbstractRemoteTestCase.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/AbstractRemoteTestCase.java 2010-03-09
14:53:10 UTC (rev 5812)
+++
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/AbstractRemoteTestCase.java 2010-03-09
14:53:39 UTC (rev 5813)
@@ -22,17 +22,14 @@
package org.jboss.remoting3.test;
-import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import org.jboss.remoting3.Connection;
-import org.jboss.remoting3.RemotingOptions;
import org.jboss.remoting3.security.SimpleServerAuthenticationProvider;
import org.jboss.remoting3.spi.NetworkServerProvider;
-import org.jboss.remoting3.spi.ProtocolServiceType;
import org.jboss.remoting3.spi.SpiUtils;
import org.jboss.xnio.AcceptingServer;
import org.jboss.xnio.ChannelListener;
@@ -42,7 +39,6 @@
import org.jboss.xnio.Xnio;
import org.jboss.xnio.channels.BoundChannel;
import org.jboss.xnio.channels.ConnectedStreamChannel;
-import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
@@ -50,27 +46,19 @@
@Test
public abstract class AbstractRemoteTestCase extends InvocationTestBase {
- @BeforeTest
- public void setUp() throws IOException {
- super.setUp();
- enter();
- try {
- final SimpleServerAuthenticationProvider authenticationProvider = new
SimpleServerAuthenticationProvider();
- authenticationProvider.addUser("user", "endpoint",
"password".toCharArray());
-
endpoint.addProtocolService(ProtocolServiceType.SERVER_AUTHENTICATION_PROVIDER,
"test", authenticationProvider);
- } finally {
- exit();
- }
+ final SimpleServerAuthenticationProvider authenticationProvider = new
SimpleServerAuthenticationProvider();
+
+ protected AbstractRemoteTestCase() {
+ authenticationProvider.addUser("user", "endpoint",
"password".toCharArray());
}
protected Connection getConnection() throws Exception {
final NetworkServerProvider provider =
endpoint.getConnectionProviderInterface(getScheme(), NetworkServerProvider.class);
assertNotNull(provider, "No remote provider interface");
final OptionMap serverOptions = OptionMap.builder()
- .set(RemotingOptions.AUTHENTICATION_PROVIDER, "test")
.setSequence(Options.SASL_MECHANISMS, "EXTERNAL",
"DIGEST-MD5")
.getMap();
- final ChannelListener<ConnectedStreamChannel<InetSocketAddress>>
listener = provider.getServerListener(serverOptions);
+ final ChannelListener<ConnectedStreamChannel<InetSocketAddress>>
listener = provider.getServerListener(serverOptions, authenticationProvider);
final Xnio xnio = Xnio.getInstance();
final AcceptingServer<InetSocketAddress, ?, ?> server = getServer(listener,
xnio);
final IoFuture<? extends BoundChannel<InetSocketAddress>> future =
server.bind(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0));