Class BaseAuthenticatingServerInterceptor
java.lang.Object
ir.msob.jima.security.api.grpc.oauth2.BaseAuthenticatingServerInterceptor
- All Implemented Interfaces:
io.grpc.ServerInterceptor,net.devh.boot.grpc.server.security.interceptors.AuthenticatingServerInterceptor
@GrpcGlobalServerInterceptor
@Order(5100)
public class BaseAuthenticatingServerInterceptor
extends Object
implements net.devh.boot.grpc.server.security.interceptors.AuthenticatingServerInterceptor
BaseAuthenticatingServerInterceptor is a gRPC server interceptor that handles authentication based on JWT tokens.
It implements the AuthenticatingServerInterceptor interface and is marked as a global server interceptor.
This interceptor extracts the JWT token from the authorization header in the metadata, validates it using the provided
GrpcAuthenticationReader, and sets the authenticated user in the security context.- Author:
- Yaqub Abdi
-
Field Summary
Fields inherited from interface net.devh.boot.grpc.server.security.interceptors.AuthenticatingServerInterceptor
AUTHENTICATION_CONTEXT_KEY, SECURITY_CONTEXT_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<ReqT,RespT>
io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> serverCall, io.grpc.Metadata metadata, io.grpc.ServerCallHandler<ReqT, RespT> serverCallHandler) Intercepts the gRPC server call, extracts the JWT token from the authorization header, validates it, and sets the authenticated user in the security context.
-
Constructor Details
-
BaseAuthenticatingServerInterceptor
public BaseAuthenticatingServerInterceptor()
-
-
Method Details
-
interceptCall
public <ReqT,RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> serverCall, io.grpc.Metadata metadata, io.grpc.ServerCallHandler<ReqT, RespT> serverCallHandler) Intercepts the gRPC server call, extracts the JWT token from the authorization header, validates it, and sets the authenticated user in the security context.- Specified by:
interceptCallin interfaceio.grpc.ServerInterceptor- Type Parameters:
ReqT- The type of the request.RespT- The type of the response.- Parameters:
serverCall- The gRPC server call being intercepted.metadata- Metadata associated with the call.serverCallHandler- The server call handler.- Returns:
- A
ServerCall.Listenerfor processing the server call. - Throws:
io.grpc.StatusRuntimeException- If authentication fails or an error occurs during the process.
-