From a0ba41c31dc20d835e3a30d7791fa0bd3f7ded85 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 3 Dec 2001 20:14:51 +0000 Subject: [PATCH] Provide a mechanism for the authenticator to pass information to the client object by way of passing the auth response data up to the client after the completion of the authentication phase. This allows information loaded by an authenticator (like a user record) to make its way into the real world. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@722 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/crowd/server/CrowdClient.java | 12 +++--- .../presents/server/ClientManager.java | 37 ++++++------------- .../presents/server/PresentsClient.java | 26 ++++++++----- .../presents/server/net/AuthManager.java | 9 ++++- .../server/net/AuthingConnection.java | 29 ++++++++++++--- .../server/net/ConnectionManager.java | 19 ++++++---- .../server/net/ConnectionObserver.java | 12 +++--- 7 files changed, 83 insertions(+), 61 deletions(-) diff --git a/src/java/com/threerings/crowd/server/CrowdClient.java b/src/java/com/threerings/crowd/server/CrowdClient.java index 5c5d3a0e8..a07c9e38e 100644 --- a/src/java/com/threerings/crowd/server/CrowdClient.java +++ b/src/java/com/threerings/crowd/server/CrowdClient.java @@ -1,9 +1,11 @@ // -// $Id: CrowdClient.java,v 1.3 2001/10/11 04:07:51 mdb Exp $ +// $Id: CrowdClient.java,v 1.4 2001/12/03 20:14:51 mdb Exp $ package com.threerings.crowd.server; +import com.threerings.presents.net.AuthResponseData; import com.threerings.presents.server.PresentsClient; + import com.threerings.crowd.data.BodyObject; /** @@ -12,9 +14,9 @@ import com.threerings.crowd.data.BodyObject; */ public class CrowdClient extends PresentsClient { - protected void sessionWillStart () + protected void sessionWillStart (AuthResponseData rdata) { - super.sessionWillStart(); + super.sessionWillStart(rdata); // cast our client object to a body object _bodobj = (BodyObject)_clobj; @@ -26,9 +28,9 @@ public class CrowdClient extends PresentsClient CrowdServer.mapBody(_username, _bodobj); } - protected void sessionWillResume () + protected void sessionWillResume (AuthResponseData rdata) { - super.sessionWillResume(); + super.sessionWillResume(rdata); // nothing to do here presently } diff --git a/src/java/com/threerings/presents/server/ClientManager.java b/src/java/com/threerings/presents/server/ClientManager.java index d18480fc1..eca1057fc 100644 --- a/src/java/com/threerings/presents/server/ClientManager.java +++ b/src/java/com/threerings/presents/server/ClientManager.java @@ -1,5 +1,5 @@ // -// $Id: ClientManager.java,v 1.11 2001/10/11 04:07:53 mdb Exp $ +// $Id: ClientManager.java,v 1.12 2001/12/03 20:14:51 mdb Exp $ package com.threerings.presents.server; @@ -8,6 +8,8 @@ import java.util.HashMap; import com.threerings.presents.Log; import com.threerings.presents.data.ClientObject; +import com.threerings.presents.net.AuthRequest; +import com.threerings.presents.net.AuthResponse; import com.threerings.presents.net.Credentials; import com.threerings.presents.server.net.*; @@ -83,16 +85,11 @@ public class ClientManager implements ConnectionObserver return _clobjClass; } - /** - * Called when a new connection is established with the connection - * manager. Only fully authenticated connections will be passed on to - * the connection observer. - * - * @param conn The newly established connection. - */ - public synchronized - void connectionEstablished (Connection conn, Credentials creds) + // documentation inherited + public synchronized void connectionEstablished ( + Connection conn, AuthRequest req, AuthResponse rsp) { + Credentials creds = req.getCredentials(); String username = creds.getUsername(); // see if there's a client already registered with this username @@ -101,7 +98,7 @@ public class ClientManager implements ConnectionObserver if (client != null) { Log.info("Session resumed [username=" + username + ", conn=" + conn + "]."); - client.resumeSession(conn); + client.resumeSession(conn, rsp.getData()); } else { Log.info("Session initiated [username=" + username + @@ -109,7 +106,7 @@ public class ClientManager implements ConnectionObserver // create a new client and stick'em in the table try { client = (PresentsClient)_clientClass.newInstance(); - client.startSession(this, username, conn); + client.startSession(this, username, conn, rsp.getData()); _usermap.put(username, client); } catch (Exception e) { Log.warning("Failed to instantiate client instance to " + @@ -123,15 +120,7 @@ public class ClientManager implements ConnectionObserver _conmap.put(conn, client); } - /** - * Called if a connection fails for any reason. If a connection fails, - * connectionClosed will not be called. This call to - * connectionFailed is the last the observers will hear - * about it. - * - * @param conn The connection in that failed. - * @param fault The exception associated with the failure. - */ + // documentation inherited public synchronized void connectionFailed (Connection conn, IOException fault) { @@ -151,11 +140,7 @@ public class ClientManager implements ConnectionObserver } } - /** - * Called when a connection has been closed in an orderly manner. - * - * @param conn The recently closed connection. - */ + // documentation inherited public synchronized void connectionClosed (Connection conn) { // remove the client from the connection map diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index 11928c0b3..96a0c71d5 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -1,5 +1,5 @@ // -// $Id: PresentsClient.java,v 1.24 2001/10/24 00:36:40 mdb Exp $ +// $Id: PresentsClient.java,v 1.25 2001/12/03 20:14:51 mdb Exp $ package com.threerings.presents.server; @@ -53,7 +53,8 @@ public class PresentsClient * connection instance and begins a client session. */ protected void startSession ( - ClientManager cmgr, String username, Connection conn) + ClientManager cmgr, String username, Connection conn, + final AuthResponseData rdata) { _cmgr = cmgr; _username = username; @@ -66,7 +67,7 @@ public class PresentsClient public void objectAvailable (DObject object) { setClientObject((ClientObject)object); - sessionWillStart(); + sessionWillStart(rdata); sendBootstrap(); } @@ -96,7 +97,8 @@ public class PresentsClient * authenticates as this already established client. This must only be * called from the congmr thread. */ - protected void resumeSession (Connection conn) + protected void resumeSession ( + Connection conn, final AuthResponseData rdata) { Connection oldconn = getConnection(); @@ -122,7 +124,7 @@ public class PresentsClient { // now that we're on the dobjmgr thread we can resume our // session resumption - finishResumeSession(); + finishResumeSession(rdata); return false; } }; @@ -134,10 +136,10 @@ public class PresentsClient * resumption. We call some call backs and send the bootstrap info to * the client. */ - protected void finishResumeSession () + protected void finishResumeSession (AuthResponseData rdata) { // let derived classes do any session resuming - sessionWillResume(); + sessionWillResume(rdata); // send off a bootstrap notification immediately because we've // already got our client object @@ -237,8 +239,11 @@ public class PresentsClient *

Note: This function will be called on the dobjmgr * thread which means that object manipulations are OK, but client * instance manipulations must done carefully. + * + * @param rdata the data object delivered to the client during the + * authentication phase. */ - protected void sessionWillStart () + protected void sessionWillStart (AuthResponseData rdata) { } @@ -252,8 +257,11 @@ public class PresentsClient *

Note: This function will be called on the dobjmgr * thread which means that object manipulations are OK, but client * instance manipulations must done carefully. + * + * @param rdata the data object delivered to the client during the + * authentication phase. */ - protected void sessionWillResume () + protected void sessionWillResume (AuthResponseData rdata) { } diff --git a/src/java/com/threerings/presents/server/net/AuthManager.java b/src/java/com/threerings/presents/server/net/AuthManager.java index 9c42fbc0f..7cb9e5343 100644 --- a/src/java/com/threerings/presents/server/net/AuthManager.java +++ b/src/java/com/threerings/presents/server/net/AuthManager.java @@ -1,5 +1,5 @@ // -// $Id: AuthManager.java,v 1.5 2001/10/11 04:07:53 mdb Exp $ +// $Id: AuthManager.java,v 1.6 2001/12/03 20:14:51 mdb Exp $ package com.threerings.presents.server.net; @@ -72,8 +72,13 @@ public class AuthManager extends LoopingThread // now ship the response back aconn.postMessage(rsp); + // stuff a reference to the auth response into the connection + // so that we have access to it later in the authentication + // process + aconn.setAuthResponse(rsp); + // if the authentication request was granted, let the - // connection manager know that we just authed a connection + // connection manager know that we just authed _conmgr.connectionDidAuthenticate(aconn); } catch (Exception e) { diff --git a/src/java/com/threerings/presents/server/net/AuthingConnection.java b/src/java/com/threerings/presents/server/net/AuthingConnection.java index 7b57f6347..c763c5600 100644 --- a/src/java/com/threerings/presents/server/net/AuthingConnection.java +++ b/src/java/com/threerings/presents/server/net/AuthingConnection.java @@ -1,5 +1,5 @@ // -// $Id: AuthingConnection.java,v 1.4 2001/10/11 04:07:53 mdb Exp $ +// $Id: AuthingConnection.java,v 1.5 2001/12/03 20:14:51 mdb Exp $ package com.threerings.presents.server.net; @@ -7,8 +7,9 @@ import java.io.IOException; import ninja2.core.io_core.nbio.NonblockingSocket; import com.threerings.presents.Log; -import com.threerings.presents.net.UpstreamMessage; import com.threerings.presents.net.AuthRequest; +import com.threerings.presents.net.AuthResponse; +import com.threerings.presents.net.UpstreamMessage; /** * The authing connection manages the client connection until @@ -58,14 +59,30 @@ public class AuthingConnection return _authreq; } + /** + * Returns the auth response delivered to the client (only valid after + * the auth request has been processed. + */ + public AuthResponse getAuthResponse () + { + return _authrsp; + } + + /** + * Stores a reference to the auth response delivered to this + * connection. This is called by the auth manager after delivering the + * auth response to the client. + */ + public void setAuthResponse (AuthResponse authrsp) + { + _authrsp = authrsp; + } + public String toString () { return "[mode=AUTHING, addr=" + _socket.getInetAddress() + "]"; } - protected int _state = AWAITING_AUTH_REQUEST; protected AuthRequest _authreq; - - protected static final int AWAITING_AUTH_REQUEST = 0; - protected static final int PROCESSING_AUTH_REQUEST = 1; + protected AuthResponse _authrsp; } diff --git a/src/java/com/threerings/presents/server/net/ConnectionManager.java b/src/java/com/threerings/presents/server/net/ConnectionManager.java index 6bee77451..3a05e0595 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionManager.java +++ b/src/java/com/threerings/presents/server/net/ConnectionManager.java @@ -1,5 +1,5 @@ // -// $Id: ConnectionManager.java,v 1.13 2001/10/25 23:37:13 mdb Exp $ +// $Id: ConnectionManager.java,v 1.14 2001/12/03 20:14:51 mdb Exp $ package com.threerings.presents.server.net; @@ -14,7 +14,8 @@ import com.threerings.presents.Log; import com.threerings.presents.client.Client; import com.threerings.presents.io.FramingOutputStream; import com.threerings.presents.io.TypedObjectFactory; -import com.threerings.presents.net.Credentials; +import com.threerings.presents.net.AuthRequest; +import com.threerings.presents.net.AuthResponse; import com.threerings.presents.net.DownstreamMessage; import com.threerings.presents.server.PresentsServer; @@ -104,7 +105,8 @@ public class ConnectionManager extends LoopingThread * Notifies the connection observers of a connection event. Used * internally. */ - protected void notifyObservers (int code, Connection conn, Object arg) + protected void notifyObservers ( + int code, Connection conn, Object arg1, Object arg2) { synchronized (_observers) { for (int i = 0; i < _observers.size(); i++) { @@ -112,10 +114,11 @@ public class ConnectionManager extends LoopingThread (ConnectionObserver)_observers.get(i); switch (code) { case CONNECTION_ESTABLISHED: - obs.connectionEstablished(conn, (Credentials)arg); + obs.connectionEstablished(conn, (AuthRequest)arg1, + (AuthResponse)arg2); break; case CONNECTION_FAILED: - obs.connectionFailed(conn, (IOException)arg); + obs.connectionFailed(conn, (IOException)arg1); break; case CONNECTION_CLOSED: obs.connectionClosed(conn); @@ -171,7 +174,7 @@ public class ConnectionManager extends LoopingThread // and let our observers know about our new connection notifyObservers(CONNECTION_ESTABLISHED, rconn, - conn.getAuthRequest().getCredentials()); + conn.getAuthRequest(), conn.getAuthResponse()); } catch (IOException ioe) { Log.warning("Failure upgrading authing connection to " + @@ -279,7 +282,7 @@ public class ConnectionManager extends LoopingThread _selset.remove(conn.getSelectItem()); // let our observers know what's up - notifyObservers(CONNECTION_FAILED, conn, ioe); + notifyObservers(CONNECTION_FAILED, conn, ioe, null); } /** @@ -293,7 +296,7 @@ public class ConnectionManager extends LoopingThread _selset.remove(conn.getSelectItem()); // let our observers know what's up - notifyObservers(CONNECTION_CLOSED, conn, null); + notifyObservers(CONNECTION_CLOSED, conn, null, null); } /** diff --git a/src/java/com/threerings/presents/server/net/ConnectionObserver.java b/src/java/com/threerings/presents/server/net/ConnectionObserver.java index 6ff8b6676..077df3329 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionObserver.java +++ b/src/java/com/threerings/presents/server/net/ConnectionObserver.java @@ -1,10 +1,11 @@ // -// $Id: ConnectionObserver.java,v 1.5 2001/10/11 04:07:53 mdb Exp $ +// $Id: ConnectionObserver.java,v 1.6 2001/12/03 20:14:51 mdb Exp $ package com.threerings.presents.server.net; import java.io.IOException; -import com.threerings.presents.net.Credentials; +import com.threerings.presents.net.AuthRequest; +import com.threerings.presents.net.AuthResponse; /** * A connection observer can be registered with the connection manager to @@ -24,10 +25,11 @@ public interface ConnectionObserver * the connection observer. * * @param conn The newly established connection. - * @param creds The credentials with which this connection - * (successfully) authenticated. + * @param req The auth request provided by the client. + * @param rsp The auth response provided to the client. */ - public void connectionEstablished (Connection conn, Credentials creds); + public void connectionEstablished ( + Connection conn, AuthRequest req, AuthResponse rsp); /** * Called if a connection fails for any reason. If a connection fails,