public class UserRoleAuthorizationInterceptor extends HandlerInterceptorAdapter
HttpServletRequest.isUserInRole(java.lang.String)
Constructor and Description |
---|
UserRoleAuthorizationInterceptor() |
Modifier and Type | Method and Description |
---|---|
protected void |
handleNotAuthorized(HttpServletRequest request,
HttpServletResponse response,
Object handler)
Handle a request that is not authorized according to this interceptor.
|
boolean |
preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler)
This implementation always returns
true . |
void |
setAuthorizedRoles(String... authorizedRoles)
Set the roles that this interceptor should treat as authorized.
|
afterCompletion, afterConcurrentHandlingStarted, postHandle
public final void setAuthorizedRoles(String... authorizedRoles)
authorizedRoles
- array of role namespublic final boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException
HandlerInterceptorAdapter
true
.preHandle
in interface HandlerInterceptor
preHandle
in class HandlerInterceptorAdapter
request
- current HTTP requestresponse
- current HTTP responsehandler
- chosen handler to execute, for type and/or instance evaluationtrue
if the execution chain should proceed with the
next interceptor or the handler itself. Else, DispatcherServlet assumes
that this interceptor has already dealt with the response itself.ServletException
IOException
protected void handleNotAuthorized(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException
This method can be overridden to write a custom message, forward or redirect to some error page or login page, or throw a ServletException.
request
- current HTTP requestresponse
- current HTTP responsehandler
- chosen handler to execute, for type and/or instance evaluationServletException
- if there is an internal errorIOException
- in case of an I/O error when writing the response