private AuthenticatedUser getAuthenticatedUser ( GuacamoleSession existingSession , Credentials credentials ) throws GuacamoleException { try { // Re-authenticate user if session exists if ( existingSession != null ) { AuthenticatedUser updatedUser = updateAuthenticatedUser ( existingSession . getAuthenticatedUser ( ) , credentials ) ; fireAuthenticationSuccessEvent ( updatedUser ) ; return updatedUser ; } // Otherwise, attempt authentication as a new user AuthenticatedUser authenticatedUser = AuthenticationService . this . authenticateUser ( credentials ) ; fireAuthenticationSuccessEvent ( authenticatedUser ) ; if ( logger . isInfoEnabled ( ) ) logger . info ( "User \"{}\" successfully authenticated from {}." , authenticatedUser . getIdentifier ( ) , getLoggableAddress ( credentials . getRequest ( ) ) ) ; return authenticatedUser ; } // Log and rethrow any authentication errors catch ( GuacamoleException e ) { fireAuthenticationFailedEvent ( credentials ) ; // Get request and username for sake of logging HttpServletRequest request = credentials . getRequest ( ) ; String username = credentials . getUsername ( ) ; // Log authentication failures with associated usernames if ( username != null ) { if ( logger . isWarnEnabled ( ) ) logger . warn ( "Authentication attempt from {} for user \"{}\" failed." , getLoggableAddress ( request ) , username ) ; } // Log anonymous authentication failures else if ( logger . isDebugEnabled ( ) ) logger . debug ( "Anonymous authentication attempt from {} failed." , getLoggableAddress ( request ) ) ; // Rethrow exception throw e ; } }
Returns the AuthenticatedUser associated with the given session and credentials performing a fresh authentication and creating a new AuthenticatedUser if necessary .