private boolean loginMissingToken ( NextFilter nextFilter , IoSession session , HttpRequestMessage httpRequest , AuthenticationToken authToken , TypedCallbackHandlerMap additionalCallbacks , HttpRealmInfo [ ] realms , int realmIndex , LoginContext [ ] loginContexts ) { HttpRealmInfo realm = realms [ realmIndex ] ; // We build a LoginContext here and call login() so that login // modules have a chance to any challenge parameters to the initial // challenge (KG-2191). ResultAwareLoginContext loginContext = null ; try { LoginContextFactory loginContextFactory = realm . getLoginContextFactory ( ) ; TypedCallbackHandlerMap callbackHandlerMap = new TypedCallbackHandlerMap ( ) ; registerCallbacks ( session , httpRequest , authToken , callbackHandlerMap ) ; callbackHandlerMap . putAll ( additionalCallbacks ) ; loginContext = ( ResultAwareLoginContext ) loginContextFactory . createLoginContext ( callbackHandlerMap ) ; if ( loginContext == null ) { throw new LoginException ( "Login failed; cannot create a login context for authentication token '" + authToken + "\'." ) ; } if ( loggerEnabled ( ) ) { log ( "Login module login required; [%s]." , authToken ) ; } loginContext . login ( ) ; } catch ( LoginException le ) { // Depending on the login modules configured, this could be // a very normal condition. if ( loggerEnabled ( ) ) { // Ignore the common "all modules ignored case", it just gums // up the logs whilst adding no value. if ( le . getMessage ( ) != null && ! le . getMessage ( ) . contains ( "all modules ignored" ) ) { log ( "Login failed: " + le . getMessage ( ) , le ) ; } } if ( loginContext == null ) { // This can happen if the given authentication token is // not one that we support. And if that is the case, then // we will never able to handle the token, so return // 403 now. writeResponse ( HttpStatus . CLIENT_FORBIDDEN , nextFilter , session , httpRequest ) ; return false ; } } catch ( Exception e ) { if ( loggerEnabled ( ) ) { log ( "Login failed." , e ) ; } writeResponse ( HttpStatus . CLIENT_FORBIDDEN , nextFilter , session , httpRequest ) ; return false ; } DefaultLoginResult loginResult = loginContext . getLoginResult ( ) ; String challenge = sendChallengeResponse ( nextFilter , session , httpRequest , loginResult , realms , realmIndex , loginContexts ) ; if ( loggerEnabled ( ) ) { log ( String . format ( "No authentication token was provided. Issuing an authentication challenge '%s'." , challenge ) ) ; } // No matter what happens, we know that the roles currently present // are not sufficient for logging in, so return false. ResourceAddress localAddress = LOCAL_ADDRESS . get ( session ) ; String nextProtocol = localAddress . getOption ( NEXT_PROTOCOL ) ; if ( "http/1.1" . equals ( nextProtocol ) ) { HttpMergeRequestFilter . INITIAL_HTTP_REQUEST_KEY . remove ( session ) ; } return false ; }
Handle the initial login attempt where the client has presumably not sent any specific authentication token yet .