Package net.ltgt.oidc.servlet
Class HasRoleFilter
java.lang.Object
jakarta.servlet.GenericFilter
jakarta.servlet.http.HttpFilter
net.ltgt.oidc.servlet.AbstractAuthorizationFilter
net.ltgt.oidc.servlet.HasRoleFilter
- All Implemented Interfaces:
Filter,FilterConfig,Serializable
Ensures the user has a given role.
This filter should be installed after the UserFilter as it relies on HttpServletRequest.isUserInRole(java.lang.String).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the init parameter used to configure the expected user role.Fields inherited from class net.ltgt.oidc.servlet.AbstractAuthorizationFilter
IS_PRIVATE_REQUEST_ATTRIBUTE_NAME -
Constructor Summary
ConstructorsConstructorDescriptionHasRoleFilter(String role) Constructs a filter that checks for the given role.HasRoleFilter(AuthenticationRedirector authenticationRedirector) Constructs a filter with the given authentication redirector.HasRoleFilter(AuthenticationRedirector authenticationRedirector, String role) Constructs a filter with the given authentication redirector and role. -
Method Summary
Modifier and TypeMethodDescriptionvoidinit()protected final booleanReturns whether the user is authorized.Methods inherited from class net.ltgt.oidc.servlet.AbstractAuthorizationFilter
configureAuthenticationRequest, doFilter, doRedirectToAuthenticationEndpoint, doSendUnauthorized, isCallbackServlet, redirectToAuthenticationEndpoint, sendForbidden, sendUnauthorizedMethods inherited from class jakarta.servlet.http.HttpFilter
doFilterMethods inherited from class jakarta.servlet.GenericFilter
getFilterConfig, getFilterName, getInitParameter, getInitParameterNames, getServletContext, init
-
Field Details
-
ROLE
Name of the init parameter used to configure the expected user role.- See Also:
-
-
Constructor Details
-
HasRoleFilter
public HasRoleFilter() -
HasRoleFilter
Constructs a filter that checks for the given role.When this constructor is used, the
ROLEinit parameter won't be read; the servlet context attribute will be read though. -
HasRoleFilter
Constructs a filter with the given authentication redirector.When this constructor is used, the servlet context attribute won't be read, though the role will be read from the
ROLEinit parameter. -
HasRoleFilter
Constructs a filter with the given authentication redirector and role.When this constructor is used, the servlet context attribute and the
ROLEinit parameter won't be read.
-
-
Method Details
-
init
- Overrides:
initin classAbstractAuthorizationFilter- Throws:
ServletException
-
isAuthorized
Description copied from class:AbstractAuthorizationFilterReturns whether the user is authorized.Implementations should only use the requests
getUserPrincipal()and/orisUserInRole().- Specified by:
isAuthorizedin classAbstractAuthorizationFilter
-