Class HasRoleFilter
- All Implemented Interfaces:
jakarta.ws.rs.container.ContainerRequestFilter
When the user is not authorized, the default implementation will return a 403 Forbidden error when the user is authenticated but is missing the
required role, and defers to the parent behavior
otherwise.
An instance of this class needs to be registered through a DynamicFeature, or a subclass needs to be created to be
able to create and use a name binding.
-
Field Summary
Fields inherited from class net.ltgt.oidc.servlet.rs.AbstractAuthorizationFilter
IS_PRIVATE_PROPERTY_NAME, servletRequest -
Constructor Summary
ConstructorsConstructorDescriptionHasRoleFilter(String role) Constructs a filter that checks for the given role. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voiddoRedirectToAuthenticationEndpoint(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) CallsredirectToAuthenticationEndpoint(jakarta.ws.rs.container.ContainerRequestContext)from the superclass.protected final voiddoSendUnauthorized(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) CallssendUnauthorized(jakarta.ws.rs.container.ContainerRequestContext)from the superclass.protected final booleanisAuthorized(jakarta.ws.rs.core.SecurityContext securityContext) Returns whether the user is authorized.protected voidredirectToAuthenticationEndpoint(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) This method is called whenever the user is not authorized and the request is a safe navigation request.protected voidsendForbidden(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) This method is called whenever the user is authenticated but not authorized.protected voidsendUnauthorized(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) This method is called whenever is not authorized and the request is not a safe navigation request.Methods inherited from class net.ltgt.oidc.servlet.rs.AbstractAuthorizationFilter
configureAuthenticationRequest, filter, getAuthenticationRedirector
-
Constructor Details
-
HasRoleFilter
Constructs a filter that checks for the given role.
-
-
Method Details
-
isAuthorized
protected final boolean isAuthorized(jakarta.ws.rs.core.SecurityContext securityContext) Description copied from class:AbstractAuthorizationFilterReturns whether the user is authorized.- Specified by:
isAuthorizedin classAbstractAuthorizationFilter
-
redirectToAuthenticationEndpoint
@ForOverride protected void redirectToAuthenticationEndpoint(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) This method is called whenever the user is not authorized and the request is a safe navigation request.This implementation calls
sendForbidden(jakarta.ws.rs.container.ContainerRequestContext)whenever the user is authenticated, and defers to the parent behavior otherwise.- Overrides:
redirectToAuthenticationEndpointin classAbstractAuthorizationFilter- See Also:
-
doRedirectToAuthenticationEndpoint
protected final void doRedirectToAuthenticationEndpoint(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) CallsredirectToAuthenticationEndpoint(jakarta.ws.rs.container.ContainerRequestContext)from the superclass. This is a hook allowing to bypass this class' override's implementation. -
sendUnauthorized
@ForOverride protected void sendUnauthorized(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) This method is called whenever is not authorized and the request is not a safe navigation request.This implementation calls
sendForbidden(jakarta.ws.rs.container.ContainerRequestContext)whenever the user is authenticated, and defers to the parent behavior otherwise.- Overrides:
sendUnauthorizedin classAbstractAuthorizationFilter- See Also:
-
doSendUnauthorized
protected final void doSendUnauthorized(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) CallssendUnauthorized(jakarta.ws.rs.container.ContainerRequestContext)from the superclass. This is a hook allowing to bypass this class' override's implementation. -
sendForbidden
@ForOverride protected void sendForbidden(jakarta.ws.rs.container.ContainerRequestContext containerRequestContext) This method is called whenever the user is authenticated but not authorized.The default implementation simply throws a
ForbiddenException.
-