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 ) ; invoker . postUnit ( new Invoker . Unit ( "authenticateConnection" ) { @ Override public boolean invoke ( ) { try { processAuthentication ( conn , rsp ) ; if ( AuthResponseData . SUCCESS . equals ( rdata . code ) && conn . getAuthName ( ) == null ) { // fail early, fail (less) often throw new IllegalStateException ( "Authenticator failed to provide authname" ) ; } } catch ( AuthException e ) { rdata . code = e . getMessage ( ) ; } catch ( Exception e ) { log . warning ( "Error authenticating user" , "areq" , req , e ) ; rdata . code = AuthCodes . SERVER_ERROR ; } return true ; } @ Override public void handleResult ( ) { // stuff a reference to the auth response into the connection so that we have // access to it later in the authentication process conn . setAuthResponse ( rsp ) ; // send the response back to the client conn . postMessage ( rsp ) ; // if the authentication request was granted, let the connection manager know that // we just authed if ( AuthResponseData . SUCCESS . equals ( rdata . code ) ) { onComplete . requestCompleted ( conn ) ; } } } ) ; }
Called by the connection management code when an authenticating connection has received its authentication request from the client .