private synchronized boolean refreshAuthToken ( final AuthHandler handler , final boolean forceRefresh ) { if ( handler == null ) { return false ; } AuthToken token = authToken . get ( ) ; if ( ! forceRefresh && token != null && token . isValid ( ) ) { logger . fine ( "Auth token is already valid" ) ; return true ; } try { handler . setForceRefresh ( forceRefresh ) ; token = handler . call ( ) ; authToken . set ( token ) ; if ( token != null ) { if ( token instanceof UserBearerAuthToken ) { final UserBearerAuthToken bt = ( UserBearerAuthToken ) token ; logger . info ( "Acquired auth token. Expires: " + bt . getExpires ( ) + " token=" + bt . getToken ( ) ) ; } else if ( token instanceof ProjectBearerAuthToken ) { ProjectBearerAuthToken pt = ( ProjectBearerAuthToken ) token ; logger . info ( "Acquired proj token. Expires: " + pt . getExpires ( ) + " token=" + pt . getToken ( ) ) ; } else { logger . info ( "Acquired auth token. Token valid=" + token . isValid ( ) ) ; } } } catch ( ExecutionException e ) { final Throwable cause = e . getCause ( ) ; if ( cause != null ) { logger . warning ( "Authentication failed: " + cause . getMessage ( ) ) ; } else { logger . warning ( "Authentication failed: " + e . getMessage ( ) ) ; } } catch ( Exception e ) { logger . warning ( "Authentication failed: " + e . getMessage ( ) ) ; } finally { handler . setForceRefresh ( false ) ; } return true ; }
Return true if caller should retry false if give up