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