Class ExceptionTranslatingServerInterceptor
java.lang.Object
net.devh.boot.grpc.server.security.interceptors.ExceptionTranslatingServerInterceptor
- All Implemented Interfaces:
ServerInterceptor
@GrpcGlobalServerInterceptor
@Order(5000)
public class ExceptionTranslatingServerInterceptor
extends Object
implements ServerInterceptor
Server interceptor that translates any
AuthenticationException
and AccessDeniedException
to
appropriate grpc status responses.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
closeCallAccessDenied
(ServerCall<?, ?> call, AccessDeniedException aex) Close the call withStatus.PERMISSION_DENIED
.protected void
closeCallUnauthenticated
(ServerCall<?, ?> call, AuthenticationException aex) Close the call withStatus.UNAUTHENTICATED
.<ReqT,
RespT>
ServerCall.Listener<ReqT>interceptCall
(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) protected <ReqT> ServerCall.Listener<ReqT>
Creates a new no-op call listener because you can neither return null nor throw an exception ininterceptCall(ServerCall, Metadata, ServerCallHandler)
.
-
Field Details
-
UNAUTHENTICATED_DESCRIPTION
A constant that contains the response message for unauthenticated calls.- See Also:
-
ACCESS_DENIED_DESCRIPTION
A constant that contains the response message for calls with insufficient permissions.- See Also:
-
-
Constructor Details
-
ExceptionTranslatingServerInterceptor
public ExceptionTranslatingServerInterceptor()
-
-
Method Details
-
interceptCall
public <ReqT,RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) - Specified by:
interceptCall
in interfaceServerInterceptor
-
noOpCallListener
Creates a new no-op call listener because you can neither return null nor throw an exception ininterceptCall(ServerCall, Metadata, ServerCallHandler)
.- Type Parameters:
ReqT
- The type of the request.- Returns:
- The newly created dummy listener.
-
closeCallUnauthenticated
Close the call withStatus.UNAUTHENTICATED
.- Parameters:
call
- The call to close.aex
- The exception that was the cause.
-
closeCallAccessDenied
Close the call withStatus.PERMISSION_DENIED
.- Parameters:
call
- The call to close.aex
- The exception that was the cause.
-