Modified authentication process such that an authenticator thread is no

longer maintained. Implementations can choose to create their own
authentication thread if they wish or use some existing combination of the
invoker and dobjmgr threads. Also added an invoker to the base server
class.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1085 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-03-05 03:19:18 +00:00
parent 7dc7545541
commit 38ca708a4f
7 changed files with 104 additions and 174 deletions
@@ -1,115 +0,0 @@
//
// $Id: AuthManager.java,v 1.8 2001/12/04 07:32:10 mdb Exp $
package com.threerings.presents.server.net;
import com.samskivert.util.LoopingThread;
import com.samskivert.util.Queue;
import com.threerings.presents.Log;
import com.threerings.presents.net.AuthRequest;
import com.threerings.presents.net.AuthResponse;
import com.threerings.presents.net.AuthResponseData;
/**
* The authentication manager takes care of the authentication process.
* Authentication happens on multiple threads. The conmgr thread parses
* the authentication request and passes it on to the authmgr thread. The
* authmgr thread invokes the (pluggable) authenticator to do the actual
* authentication. Then the response message is queued up to be delivered
* by the conmgr thread.
*
* <p> This structure prevents authentication to take place
* asynchronously, but in a controlled manner. Only one authentication
* will be processed at a time, but the dobj and conmgr threads will
* continue to operate independent of the authentication process.
*/
public class AuthManager extends LoopingThread
{
/**
* Constructs an auth manager which will use the specified
* authenticator to authorize logon requests.
*/
public AuthManager (Authenticator author)
{
setAuthenticator(author);
}
/**
* Specifies the authenticator that should be used by the auth manager
* to authenticate logon requests.
*/
public void setAuthenticator (Authenticator author)
{
_author = author;
}
/**
* Puts an authenticating connection on the queue. The connection will
* be authenticated and an auth response delivered.
*/
public void postAuthingConnection (AuthingConnection aconn)
{
_authq.append(aconn);
}
/**
* The connection manager introduces itself to the auth manager so
* that the auth manager can let it know when it has authorized
* connections.
*/
public void setConnectionManager (ConnectionManager conmgr)
{
_conmgr = conmgr;
}
/**
* Process auth requests.
*/
protected void iterate ()
{
// grab the next authing connection from the queue
Object item = _authq.get();
// if we're being kicked and requested to exit, we'll just post
// some bogus item on the queue to wake up the auth manager and
// get him the hell out of dodge
if (!(item instanceof AuthingConnection)) {
return;
}
AuthingConnection aconn = (AuthingConnection)item;
try {
// instruct the authenticator to process the auth request
AuthResponse rsp = _author.process(aconn.getAuthRequest());
// 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
if (AuthResponseData.SUCCESS.equals(rsp.getData().code)) {
_conmgr.connectionDidAuthenticate(aconn);
}
} catch (Exception e) {
Log.warning("Failure processing authreq [conn=" + aconn + "].");
Log.logStackTrace(e);
}
}
protected void kick ()
{
// we post something bogus to the queue to wake up the authmgr
_authq.append(new Integer(0));
}
protected Authenticator _author;
protected ConnectionManager _conmgr;
protected Queue _authq = new Queue();
}
@@ -1,5 +1,5 @@
//
// $Id: AuthingConnection.java,v 1.5 2001/12/03 20:14:51 mdb Exp $
// $Id: AuthingConnection.java,v 1.6 2002/03/05 03:19:18 mdb Exp $
package com.threerings.presents.server.net;
@@ -41,7 +41,7 @@ public class AuthingConnection
_authreq = (AuthRequest)msg;
// post ourselves for processing by the authmgr
_cmgr.getAuthManager().postAuthingConnection(this);
_cmgr.getAuthenticator().authenticateConnection(this);
} catch (ClassCastException cce) {
Log.warning("Received non-authreq message during " +
@@ -1,5 +1,5 @@
//
// $Id: ConnectionManager.java,v 1.14 2001/12/03 20:14:51 mdb Exp $
// $Id: ConnectionManager.java,v 1.15 2002/03/05 03:19:18 mdb Exp $
package com.threerings.presents.server.net;
@@ -34,19 +34,13 @@ public class ConnectionManager extends LoopingThread
*
* @param config A config object from which the connection manager
* will fetch its configuration parameters.
* @param authmgr The authentication manager to use when
* authenticating client connections.
*/
public ConnectionManager (Config config, AuthManager authmgr)
public ConnectionManager (Config config)
throws IOException
{
// the listen port is specified in our configuration
_port = config.getValue(CM_PORT_KEY, Client.DEFAULT_SERVER_PORT);
// keep a handle on our authentication manager
_authmgr = authmgr;
// complete the introductions
_authmgr.setConnectionManager(this);
// we use this to wait for activity on our sockets
_selset = new SelectSet();
@@ -67,12 +61,22 @@ public class ConnectionManager extends LoopingThread
}
/**
* Returns a reference to the auth manager being used to authenticate
* connections.
* Specifies the authenticator that should be used by the connection
* manager to authenticate logon requests.
*/
public AuthManager getAuthManager ()
public void setAuthenticator (Authenticator author)
{
return _authmgr;
// say hello to our new authenticator
_author = author;
_author.setConnectionManager(this);
}
/**
* Returns the entity that is being used to authenticate connections.
*/
public Authenticator getAuthenticator ()
{
return _author;
}
/**
@@ -310,7 +314,7 @@ public class ConnectionManager extends LoopingThread
}
protected int _port;
protected AuthManager _authmgr;
protected Authenticator _author;
protected SelectSet _selset;
protected NonblockingServerSocket _listener;