8a4c46badc
changed to Presents and Party changed to Crowd. Whee! git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@431 542714f4-19e9-0310-aa3c-eee0fc999fb1
95 lines
2.9 KiB
Java
95 lines
2.9 KiB
Java
//
|
|
// $Id: AuthManager.java,v 1.5 2001/10/11 04:07:53 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;
|
|
|
|
/**
|
|
* 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
|
|
{
|
|
public AuthManager (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);
|
|
|
|
// if the authentication request was granted, let the
|
|
// connection manager know that we just authed a connection
|
|
_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();
|
|
}
|