Token auth filter now return 440 http code on expired token

This commit is contained in:
Rohan Sircar 2019-11-22 12:52:16 +05:30
parent c2e0951144
commit 9165770546
2 changed files with 12 additions and 0 deletions

View File

@ -97,6 +97,11 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
} else { } else {
userTokenService.deleteToken(userToken.getUserName()); userTokenService.deleteToken(userToken.getUserName());
TokenCacheUtil.evictSingleTokenValue(userToken.getTokenContent()); TokenCacheUtil.evictSingleTokenValue(userToken.getTokenContent());
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE);
response.setStatus(440);
response.getWriter().write("Token authentication error: Token has expired");
logger.warn("Token authentication error: Token has expired");
return;
} }
} }

View File

@ -330,6 +330,7 @@ async function getAllMessages(toUser) {
method: 'GET', method: 'GET',
headers: headers headers: headers
}); });
console.log(response);
let data = await response.json(); let data = await response.json();
return data; return data;
} }
@ -342,6 +343,12 @@ async function getNewMessages(toUser, lastMessageTimeStamp) {
method: 'GET', method: 'GET',
headers: headers headers: headers
}); });
console.log(response);
if(response.status == 440)
{
window.alert('Token has expired. Please login again');
return;
}
let data = await response.json(); let data = await response.json();
return data; return data;
} }