@GrpcGlobalServerInterceptor @Order(value=5100) public class DefaultAuthenticatingServerInterceptor extends Object implements AuthenticatingServerInterceptor
read
the credentials from the client and
authenticate
them. This interceptor sets the
authentication to both grpc's Context
and SecurityContextHolder
.
This works similar to the org.springframework.security.web.authentication.AuthenticationFilter
.
Note: This interceptor works similar to
Contexts.interceptCall(Context, ServerCall, Metadata, ServerCallHandler)
.
AUTHENTICATION_CONTEXT_KEY, SECURITY_CONTEXT_KEY
Constructor and Description |
---|
DefaultAuthenticatingServerInterceptor(AuthenticationManager authenticationManager,
GrpcAuthenticationReader authenticationReader)
Creates a new DefaultAuthenticatingServerInterceptor with the given authentication manager and reader.
|
Modifier and Type | Method and Description |
---|---|
<ReqT,RespT> |
interceptCall(ServerCall<ReqT,RespT> call,
Metadata headers,
ServerCallHandler<ReqT,RespT> next) |
protected void |
onSuccessfulAuthentication(ServerCall<?,?> call,
Metadata headers,
Authentication authentication)
Hook that will be called on successful authentication.
|
protected void |
onUnsuccessfulAuthentication(ServerCall<?,?> call,
Metadata headers,
AuthenticationException failed)
Hook that will be called on unsuccessful authentication.
|
@Autowired public DefaultAuthenticatingServerInterceptor(AuthenticationManager authenticationManager, GrpcAuthenticationReader authenticationReader)
authenticationManager
- The authentication manager used to verify the credentials.authenticationReader
- The authentication reader used to extract the credentials from the call.public <ReqT,RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT,RespT> call, Metadata headers, ServerCallHandler<ReqT,RespT> next)
interceptCall
in interface ServerInterceptor
protected void onSuccessfulAuthentication(ServerCall<?,?> call, Metadata headers, Authentication authentication)
Note: This method is called regardless of whether the authenticated user is authorized or not to perform the requested action.
By default, this method does nothing.
call
- The call instance to receive response messages.headers
- The headers associated with the call.authentication
- The successful authentication instance.protected void onUnsuccessfulAuthentication(ServerCall<?,?> call, Metadata headers, AuthenticationException failed)
Note: This method is called only if the request contains an authentication but the
AuthenticationManager
considers it invalid. This method is not called if an authenticated user is not
authorized to perform the requested action.
By default, this method does nothing.
call
- The call instance to receive response messages.headers
- The headers associated with the call.failed
- The exception related to the unsuccessful authentication.