[jboss-remoting-commits] JBoss Remoting SVN: r5596 - in remoting3/trunk: jboss-remoting/src/main/java/org/jboss/remoting3/spi and 1 other directories.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Nov 17 17:50:13 EST 2009


Author: david.lloyd at jboss.com
Date: 2009-11-17 17:50:13 -0500 (Tue, 17 Nov 2009)
New Revision: 5596

Modified:
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
   remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java
   remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java
Log:
Support an optional authentication CallbackHandler on the client side

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	2009-11-17 20:58:18 UTC (rev 5595)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java	2009-11-17 22:50:13 UTC (rev 5596)
@@ -61,6 +61,10 @@
 import org.jboss.xnio.WeakCloseable;
 
 import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.callback.NameCallback;
+import javax.security.sasl.RealmCallback;
 
 /**
  *
@@ -489,7 +493,23 @@
     }
 
     public IoFuture<? extends Connection> connect(final URI destination, final OptionMap connectOptions) throws IOException {
-        return connect(destination, connectOptions, null);
+        final String userName = connectOptions.get(RemotingOptions.AUTH_USER_NAME);
+        final String realm = connectOptions.get(RemotingOptions.AUTH_REALM);
+        return connect(destination, connectOptions, new CallbackHandler() {
+            public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+                for (Callback callback : callbacks) {
+                    if (callback instanceof NameCallback && userName != null) {
+                        final NameCallback nameCallback = (NameCallback) callback;
+                        nameCallback.setName(userName);
+                    } else if (callback instanceof RealmCallback && realm != null) {
+                        final RealmCallback realmCallback = (RealmCallback) callback;
+                        realmCallback.setText(realm);
+                    } else {
+                        throw new UnsupportedCallbackException(callback);
+                    }
+                }
+            }
+        });
     }
 
     public IoFuture<? extends Connection> connect(final URI destination, final OptionMap connectOptions, final CallbackHandler callbackHandler) throws IOException {
@@ -507,7 +527,7 @@
             protected Connection translate(final ConnectionHandlerFactory input) {
                 return new ConnectionImpl(input, connectionProviderContext);
             }
-        }));
+        }, callbackHandler));
         return futureResult.getIoFuture();
     }
 
@@ -709,7 +729,7 @@
 
     private final class LocalConnectionProvider implements ConnectionProvider<Void> {
 
-        public Cancellable connect(final URI uri, final OptionMap connectOptions, final Result<ConnectionHandlerFactory> result) throws IllegalArgumentException {
+        public Cancellable connect(final URI uri, final OptionMap connectOptions, final Result<ConnectionHandlerFactory> result, final CallbackHandler callbackHandler) throws IllegalArgumentException {
             result.setResult(new ConnectionHandlerFactory() {
                 public ConnectionHandler createInstance(final ConnectionHandlerContext context) {
                     return loopbackConnectionHandler;

Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java	2009-11-17 20:58:18 UTC (rev 5595)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java	2009-11-17 22:50:13 UTC (rev 5596)
@@ -27,6 +27,8 @@
 import org.jboss.xnio.Cancellable;
 import org.jboss.xnio.OptionMap;
 
+import javax.security.auth.callback.CallbackHandler;
+
 /**
  * A connection provider.  Used to establish connections with remote systems.  There is typically one instance
  * of this interface per connection provider factory per endpoint.
@@ -42,10 +44,11 @@
      * @param uri the URI to connect to
      * @param connectOptions the options to use for this connection
      * @param result the result which should receive the connection
+     * @param callbackHandler the callback handler to use for authentication
      * @return a handle which may be used to cancel the connect attempt
      * @throws IllegalArgumentException if the URI is not valid
      */
-    Cancellable connect(URI uri, OptionMap connectOptions, Result<ConnectionHandlerFactory> result) throws IllegalArgumentException;
+    Cancellable connect(URI uri, OptionMap connectOptions, Result<ConnectionHandlerFactory> result, CallbackHandler callbackHandler) throws IllegalArgumentException;
 
     /**
      * Get the user data associated with this connection provider.

Modified: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java	2009-11-17 20:58:18 UTC (rev 5595)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/socket/SocketConnectionProvider.java	2009-11-17 22:50:13 UTC (rev 5596)
@@ -40,6 +40,8 @@
 import org.jboss.xnio.OptionMap;
 import org.jboss.xnio.Result;
 
+import javax.security.auth.callback.CallbackHandler;
+
 /**
  * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
  * @version 
@@ -61,7 +63,7 @@
       SocketProtocol.initializeMarshalling(endpoint, executor);
    }
 
-   public Cancellable connect(final URI uri, final OptionMap connectOptions, Result<ConnectionHandlerFactory> result) throws IllegalArgumentException {
+   public Cancellable connect(final URI uri, final OptionMap connectOptions, Result<ConnectionHandlerFactory> result, final CallbackHandler callbackHandler) throws IllegalArgumentException {
       result.setResult(new ConnectionHandlerFactory() {
          public ConnectionHandler createInstance(ConnectionHandlerContext connectionContext) {
             final ConnectionHandler connectionHandler = new SocketClientConnectionHandler(uri, connectOptions, getExecutor(), host, port);



More information about the jboss-remoting-commits mailing list