Widened. Modified authenticator to freak out rather than just go ahead and

process an authentication request if it is asked to do so before it has an
invoker (meaning the server is not yet initialized).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4654 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-04-07 19:47:29 +00:00
parent 3546567824
commit 558d9ec2dc
@@ -39,16 +39,15 @@ import com.threerings.presents.server.net.ConnectionManager;
import static com.threerings.presents.Log.log; import static com.threerings.presents.Log.log;
/** /**
* The authenticator is a pluggable component of the authentication * The authenticator is a pluggable component of the authentication framework. The base class
* framework. The base class handles the basic mechanics of authentication * handles the basic mechanics of authentication and a system would extend the base authenticator
* and a system would extend the base authenticator and add code that does * and add code that does the actual client authentication.
* the actual client authentication.
*/ */
public abstract class Authenticator public abstract class Authenticator
{ {
/** /**
* Called by the connection manager to give us a reference to it for * Called by the connection manager to give us a reference to it for reporting authenticated
* reporting authenticated connections. * connections.
*/ */
public void setConnectionManager (ConnectionManager conmgr) public void setConnectionManager (ConnectionManager conmgr)
{ {
@@ -56,8 +55,8 @@ public abstract class Authenticator
} }
/** /**
* Called by the connection management code when an authenticating * Called by the connection management code when an authenticating connection has received its
* connection has received its authentication request from the client. * authentication request from the client.
*/ */
public void authenticateConnection (final AuthingConnection conn) public void authenticateConnection (final AuthingConnection conn)
{ {
@@ -69,26 +68,23 @@ public abstract class Authenticator
public boolean invoke() { public boolean invoke() {
try { try {
processAuthentication(conn, rsp); processAuthentication(conn, rsp);
} catch (Exception e) { // Persistence or Runtime } catch (Exception e) { // Persistence or Runtime
log.log(Level.WARNING, "Error authenticating user " + log.log(Level.WARNING, "Error authenticating user [areq=" + req + "].", e);
"[areq=" + req + "].", e);
rdata.code = AuthCodes.SERVER_ERROR; rdata.code = AuthCodes.SERVER_ERROR;
} }
return true; return true;
} }
public void handleResult () { public void handleResult () {
// stuff a reference to the auth response into the // stuff a reference to the auth response into the connection so that we have
// connection so that we have access to it later in the // access to it later in the authentication process
// authentication process
conn.setAuthResponse(rsp); conn.setAuthResponse(rsp);
// send the response back to the client // send the response back to the client
conn.postMessage(rsp); conn.postMessage(rsp);
// if the authentication request was granted, let the // if the authentication request was granted, let the connection manager know that
// connection manager know that we just authed // we just authed
if (AuthResponseData.SUCCESS.equals(rdata.code)) { if (AuthResponseData.SUCCESS.equals(rdata.code)) {
_conmgr.connectionDidAuthenticate(conn); _conmgr.connectionDidAuthenticate(conn);
} }
@@ -96,26 +92,18 @@ public abstract class Authenticator
}; };
Invoker invoker = getInvoker(); Invoker invoker = getInvoker();
if (invoker != null) { if (invoker == null) {
invoker.postUnit(unit); log.warning("Received authentication request before server initialization completed! " +
"Authenticator has no invoker. [req=" + req + "].");
} else { } else {
// just process it here invoker.postUnit(unit);
try {
unit.invoke();
unit.handleResult();
} catch (Exception e) {
log.log(Level.WARNING, "Error authenticating user " +
"[areq=" + req + "].", e);
}
} }
} }
/** /**
* Return the invoker on which to process the authentication, or null * Return the invoker on which to process the authentication, or null if the authentication
* if the authentication should occur on the calling thread. The default * should occur on the calling thread. The default implementation returns
* implementation returns PresentsServer.invoker. * PresentsServer.invoker.
*/ */
protected Invoker getInvoker () protected Invoker getInvoker ()
{ {
@@ -123,8 +111,7 @@ public abstract class Authenticator
} }
/** /**
* Create a new AuthResponseData instance to use for authenticating * Create a new AuthResponseData instance to use for authenticating a connection.
* a connection.
*/ */
protected AuthResponseData createResponseData () protected AuthResponseData createResponseData ()
{ {
@@ -132,17 +119,14 @@ public abstract class Authenticator
} }
/** /**
* Process the authentication for the specified connection. * Process the authentication for the specified connection. The method may return after it has
* This method may do database operations if and only if getInvoker() * stuffed a valid response code in rsp.getData().code.
* returns non-null. The method may return after it has stuffed a valid
* response code in rsp.getData().code.
* *
* @param conn The client connection. * @param conn The client connection.
* @param rsp The response to the client, which will already contain * @param rsp The response to the client, which will already contain an AuthResponseData
* an AuthResponseData created by createResponseDatA(). * created by createResponseDatA().
*/ */
protected abstract void processAuthentication ( protected abstract void processAuthentication (AuthingConnection conn, AuthResponse rsp)
AuthingConnection conn, AuthResponse rsp)
throws PersistenceException; throws PersistenceException;
/** The connection manager with which we're working. */ /** The connection manager with which we're working. */