Three things:

- Inject the auth Invoker.
- Inject the Authenticator and formalize the chaining authenticator pattern.
- Simplify PeerNode creation and make the PeerAuthenticator a chainer.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5162 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-06-08 13:04:27 +00:00
parent da11bd0ea0
commit 8c37ca7bfa
11 changed files with 169 additions and 103 deletions
@@ -24,7 +24,9 @@ package com.threerings.presents.server;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.Invoker;
import com.samskivert.util.ResultListener;
import com.threerings.presents.annotation.MainInvoker;
import com.threerings.presents.data.AuthCodes;
import com.threerings.presents.net.AuthRequest;
@@ -43,26 +45,18 @@ import static com.threerings.presents.Log.log;
*/
public abstract class Authenticator
{
/**
* Called by the connection manager to give us a reference to it for reporting authenticated
* connections.
*/
public void setConnectionManager (ConnectionManager conmgr)
{
_conmgr = conmgr;
}
/**
* Called by the connection management code when an authenticating connection has received its
* authentication request from the client.
*/
public void authenticateConnection (final AuthingConnection conn)
public void authenticateConnection (Invoker invoker, final AuthingConnection conn,
final ResultListener<AuthingConnection> onComplete)
{
final AuthRequest req = conn.getAuthRequest();
final AuthResponseData rdata = createResponseData();
final AuthResponse rsp = new AuthResponse(rdata);
getInvoker().postUnit(new Invoker.Unit("authenticateConnection") {
invoker.postUnit(new Invoker.Unit("authenticateConnection") {
public boolean invoke() {
try {
processAuthentication(conn, rsp);
@@ -84,21 +78,12 @@ public abstract class Authenticator
// if the authentication request was granted, let the connection manager know that
// we just authed
if (AuthResponseData.SUCCESS.equals(rdata.code)) {
_conmgr.connectionDidAuthenticate(conn);
onComplete.requestCompleted(conn);
}
}
});
}
/**
* Return the invoker on which to process the authentication. The default implementation
* returns PresentsServer.invoker.
*/
protected Invoker getInvoker ()
{
return PresentsServer.invoker;
}
/**
* Create a new AuthResponseData instance to use for authenticating a connection.
*/
@@ -117,7 +102,4 @@ public abstract class Authenticator
*/
protected abstract void processAuthentication (AuthingConnection conn, AuthResponse rsp)
throws PersistenceException;
/** The connection manager with which we're working. */
protected ConnectionManager _conmgr;
}