Added action to SecurityExceptionView.
This commit is contained in:
parent
026e3a7ab2
commit
15e9dfb93b
@ -38,8 +38,13 @@ public final class JwtFilter extends OncePerRequestFilter {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
private void handleSecurityException(HttpServletResponse response, int status, String message) throws IOException {
|
||||
final SecurityExceptionView view = new SecurityExceptionView(status, message);
|
||||
private void handleSecurityException(
|
||||
HttpServletResponse response,
|
||||
int status,
|
||||
SecurityExceptionView.Action action,
|
||||
String message
|
||||
) throws IOException {
|
||||
final SecurityExceptionView view = new SecurityExceptionView(status, action, message);
|
||||
response.setStatus(status);
|
||||
response.getWriter().write(this.objectMapper.writeValueAsString(view));
|
||||
}
|
||||
@ -62,12 +67,18 @@ public final class JwtFilter extends OncePerRequestFilter {
|
||||
this.handleSecurityException(
|
||||
response,
|
||||
HttpServletResponse.SC_UNAUTHORIZED,
|
||||
SecurityExceptionView.Action.REFRESH,
|
||||
expiredJwtException.getMessage()
|
||||
);
|
||||
return;
|
||||
} catch (JwtException jwtException) {
|
||||
logger.error("Error while getting username from token.", jwtException);
|
||||
this.handleSecurityException(response, HttpServletResponse.SC_UNAUTHORIZED, jwtException.getMessage());
|
||||
this.handleSecurityException(
|
||||
response,
|
||||
HttpServletResponse.SC_UNAUTHORIZED,
|
||||
SecurityExceptionView.Action.REFRESH,
|
||||
jwtException.getMessage()
|
||||
);
|
||||
return;
|
||||
}
|
||||
final UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
|
||||
|
@ -2,11 +2,17 @@ package app.mealsmadeeasy.api.security;
|
||||
|
||||
public class SecurityExceptionView {
|
||||
|
||||
public enum Action {
|
||||
LOGIN, REFRESH
|
||||
}
|
||||
|
||||
private final int status;
|
||||
private final Action action;
|
||||
private final String message;
|
||||
|
||||
public SecurityExceptionView(int status, String message) {
|
||||
public SecurityExceptionView(int status, Action action, String message) {
|
||||
this.status = status;
|
||||
this.action = action;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@ -14,6 +20,10 @@ public class SecurityExceptionView {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user