private < ReqT , RespT > boolean authenticateCall ( ServerCall < ReqT , RespT > call , Metadata headers ) { // Fail validation for cancelled server calls. if ( call . isCancelled ( ) ) { LOG . debug ( "Server call has been cancelled: %s" , call . getMethodDescriptor ( ) . getFullMethodName ( ) ) ; return false ; } // Try to fetch channel Id from the metadata. UUID channelId = headers . get ( ChannelIdInjector . S_CLIENT_ID_KEY ) ; boolean callAuthenticated = false ; if ( channelId != null ) { try { // Fetch authenticated username for this channel and set it. AuthenticatedUserInfo userInfo = mAuthenticationServer . getUserInfoForChannel ( channelId ) ; if ( userInfo != null ) { AuthenticatedClientUser . set ( userInfo . getAuthorizedUserName ( ) ) ; AuthenticatedClientUser . setConnectionUser ( userInfo . getConnectionUserName ( ) ) ; AuthenticatedClientUser . setAuthMethod ( userInfo . getAuthMethod ( ) ) ; } else { AuthenticatedClientUser . remove ( ) ; } callAuthenticated = true ; } catch ( UnauthenticatedException e ) { String message = String . format ( "Channel: %s is not authenticated for call: %s" , channelId . toString ( ) , call . getMethodDescriptor ( ) . getFullMethodName ( ) ) ; call . close ( Status . UNAUTHENTICATED . withDescription ( message ) , headers ) ; } } else { String message = String . format ( "Channel Id is missing for call: %s." , call . getMethodDescriptor ( ) . getFullMethodName ( ) ) ; call . close ( Status . UNAUTHENTICATED . withDescription ( message ) , headers ) ; } return callAuthenticated ; }
Authenticates given call against auth - server state . Fails the call if it s not originating from an authenticated client channel . It sets thread - local authentication information for the call with the user information that is kept on auth - server .