From 9165770546bd8c3567ee0741e2aa379bd2ab3533 Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Fri, 22 Nov 2019 12:52:16 +0530 Subject: [PATCH] Token auth filter now return 440 http code on expired token --- .../org/ros/chatto/security/TokenAuthenticationFilter.java | 5 +++++ chatto/src/main/resources/static/js/chat.js | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java index 61ad59c..562ed51 100644 --- a/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java +++ b/chatto/src/main/java/org/ros/chatto/security/TokenAuthenticationFilter.java @@ -97,6 +97,11 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { } else { userTokenService.deleteToken(userToken.getUserName()); 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; } } diff --git a/chatto/src/main/resources/static/js/chat.js b/chatto/src/main/resources/static/js/chat.js index cdbaab9..23428b6 100644 --- a/chatto/src/main/resources/static/js/chat.js +++ b/chatto/src/main/resources/static/js/chat.js @@ -330,6 +330,7 @@ async function getAllMessages(toUser) { method: 'GET', headers: headers }); + console.log(response); let data = await response.json(); return data; } @@ -342,6 +343,12 @@ async function getNewMessages(toUser, lastMessageTimeStamp) { method: 'GET', headers: headers }); + console.log(response); + if(response.status == 440) + { + window.alert('Token has expired. Please login again'); + return; + } let data = await response.json(); return data; }