added cacheevict
This commit is contained in:
parent
4c11415d9c
commit
9a922cf5b9
@ -93,5 +93,6 @@ public class LoggedUser implements HttpSessionBindingListener {
|
|||||||
userSessionRepository.save(userSession);
|
userSessionRepository.save(userSession);
|
||||||
|
|
||||||
userTokenService.deleteToken(chatUser.getUserName());
|
userTokenService.deleteToken(chatUser.getUserName());
|
||||||
|
TokenCacheUtil.evictSingleTokenValue(chatUser.getUserName());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package org.ros.chatto.logged;
|
||||||
|
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
|
||||||
|
public class TokenCacheUtil {
|
||||||
|
@CacheEvict(value = "userTokenCache", key = "#cacheKey")
|
||||||
|
public static void evictSingleTokenValue(String cacheKey) {}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.ros.chatto.logged.TokenCacheUtil;
|
||||||
import org.ros.chatto.model.UserToken;
|
import org.ros.chatto.model.UserToken;
|
||||||
import org.ros.chatto.service.UserTokenService;
|
import org.ros.chatto.service.UserTokenService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -95,6 +96,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
} else {
|
} else {
|
||||||
userTokenService.deleteToken(userToken.getUserName());
|
userTokenService.deleteToken(userToken.getUserName());
|
||||||
|
TokenCacheUtil.evictSingleTokenValue(userToken.getTokenContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,8 @@ var getNewMessagesUrl = `http://${hostAddress}/api/chat/get/messages/`;
|
|||||||
// var messageLog = [];
|
// var messageLog = [];
|
||||||
var username = sessionStorage.getItem('username');
|
var username = sessionStorage.getItem('username');
|
||||||
var password = sessionStorage.getItem('password');
|
var password = sessionStorage.getItem('password');
|
||||||
var authToken = 'Basic ' + btoa(username + ":" + password);
|
var basicAuthToken = 'Basic ' + btoa(username + ":" + password);
|
||||||
|
var authToken = localStorage.getItem('authToken');
|
||||||
var iterations = 100000;
|
var iterations = 100000;
|
||||||
|
|
||||||
var source = document.getElementById("msg_container_template").innerHTML;
|
var source = document.getElementById("msg_container_template").innerHTML;
|
||||||
@ -309,7 +310,8 @@ function messageSend(chatMessageDTO) {
|
|||||||
|
|
||||||
// headers.append('Accept','application/json')
|
// headers.append('Accept','application/json')
|
||||||
headers.append('Content-Type', 'application/json');
|
headers.append('Content-Type', 'application/json');
|
||||||
headers.append('Authorization', authToken);
|
// headers.append('Authorization', basicAuthToken);
|
||||||
|
headers.append('X-AUTH-TOKEN', authToken);
|
||||||
fetch(postNewMessageUrl, {
|
fetch(postNewMessageUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: headers,
|
headers: headers,
|
||||||
@ -323,7 +325,8 @@ async function getAllMessages(toUser) {
|
|||||||
let headers = new Headers();
|
let headers = new Headers();
|
||||||
// headers.append('Accept','application/json')
|
// headers.append('Accept','application/json')
|
||||||
// headers.append('Content-Type', 'application/json');
|
// headers.append('Content-Type', 'application/json');
|
||||||
headers.append('Authorization', authToken);
|
// headers.append('Authorization', basicAuthToken);
|
||||||
|
headers.append('X-AUTH-TOKEN', authToken);
|
||||||
let response = await fetch(getAllMessagesUrl + toUser, {
|
let response = await fetch(getAllMessagesUrl + toUser, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: headers
|
headers: headers
|
||||||
@ -334,7 +337,8 @@ async function getAllMessages(toUser) {
|
|||||||
|
|
||||||
async function getNewMessages(toUser, lastMessageTimeStamp) {
|
async function getNewMessages(toUser, lastMessageTimeStamp) {
|
||||||
let headers = new Headers();
|
let headers = new Headers();
|
||||||
headers.append('Authorization', authToken);
|
// headers.append('Authorization', basicAuthToken);
|
||||||
|
headers.append('X-AUTH-TOKEN', authToken);
|
||||||
let response = await fetch(`${getNewMessagesUrl}${toUser}/${lastMessageTimeStamp}`, {
|
let response = await fetch(`${getNewMessagesUrl}${toUser}/${lastMessageTimeStamp}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: headers
|
headers: headers
|
||||||
|
36
chatto/src/main/resources/static/js/login.js
Normal file
36
chatto/src/main/resources/static/js/login.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
function storeCredentials() {
|
||||||
|
let usernameInput = document.getElementById('username');
|
||||||
|
let passwordInput = document.getElementById('password');
|
||||||
|
let credentials = {
|
||||||
|
username: usernameInput.value,
|
||||||
|
password: passwordInput.value
|
||||||
|
}
|
||||||
|
// sessionStorage.setItem('credentials', JSON.stringify(credentials));
|
||||||
|
sessionStorage.setItem('username', usernameInput.value);
|
||||||
|
sessionStorage.setItem('password', passwordInput.value);
|
||||||
|
|
||||||
|
var jqxhr = $.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: `http://${hostAddress}/api/user`,
|
||||||
|
dataType: 'json',
|
||||||
|
headers: {
|
||||||
|
"Authorization": "Basic " + btoa(usernameInput.value + ":" + passwordInput.value)
|
||||||
|
},
|
||||||
|
});
|
||||||
|
//this section is executed when the server responds with no error
|
||||||
|
jqxhr.done(function() {
|
||||||
|
let authToken = jqxhr.getResponseHeader('X-AUTH-TOKEN');
|
||||||
|
localStorage.setItem('authToken', authToken);
|
||||||
|
console.log("getting header " + authToken);
|
||||||
|
});
|
||||||
|
//this section is executed when the server responds with error
|
||||||
|
jqxhr.fail(function() {
|
||||||
|
console.error('Error retrieving auth token');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let loginForm = document.getElementById('loginForm');
|
||||||
|
loginForm.addEventListener('submit', function(e) {
|
||||||
|
// e.preventDefault();
|
||||||
|
storeCredentials();
|
||||||
|
})
|
@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
function storeCredentials() {
|
|
||||||
let usernameInput = document.getElementById('username');
|
|
||||||
let passwordInput = document.getElementById('password');
|
|
||||||
let credentials = {
|
|
||||||
username: usernameInput.value,
|
|
||||||
password: passwordInput.value
|
|
||||||
}
|
|
||||||
// sessionStorage.setItem('credentials', JSON.stringify(credentials));
|
|
||||||
sessionStorage.setItem('username',usernameInput.value);
|
|
||||||
sessionStorage.setItem('password',passwordInput.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
let loginForm = document.getElementById('loginForm');
|
|
||||||
loginForm.addEventListener('submit', function (e) {
|
|
||||||
storeCredentials();
|
|
||||||
})
|
|
||||||
|
|
||||||
// storeCredentials();
|
|
3
chatto/src/main/resources/static/js/logout.js
Normal file
3
chatto/src/main/resources/static/js/logout.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
document.getElementById('logout-form').addEventListener('submit', function(e) {
|
||||||
|
localStorage.setItem('authToken', null);
|
||||||
|
})
|
@ -83,7 +83,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<script src="../js/loginPage.js" type="text/javascript"></script>
|
<script src="../js/login.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<script src="http://blackpeppersoftware.github.io/thymeleaf-fragment.js/thymeleaf-fragment.js" data-template-prefix="../" defer="defer" th:if="false"></script>
|
<script src="http://blackpeppersoftware.github.io/thymeleaf-fragment.js/thymeleaf-fragment.js" data-template-prefix="../" defer="defer" th:if="false"></script>
|
||||||
<link th:href="@{/css/master.css}" href="../../static/css/master.css" rel="stylesheet" th:if="false">
|
<link th:href="@{/css/master.css}" href="../../static/css/master.css" rel="stylesheet" th:if="false">
|
||||||
<link th:href="@{/css/colors.css}" href="../../static/css/colors.css" rel="stylesheet" th:if="false">
|
<link th:href="@{/css/colors.css}" href="../../static/css/colors.css" rel="stylesheet" th:if="false">
|
||||||
|
<script th:src="@{/js/logout.js}"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -33,7 +34,7 @@
|
|||||||
<div class="card-text">
|
<div class="card-text">
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<form action="#" th:action="@{/logout}" method="POST">
|
<form id="logout-form" action="#" th:action="@{/logout}" method="POST">
|
||||||
<!-- <input type="submit" value="logout"> -->
|
<!-- <input type="submit" value="logout"> -->
|
||||||
<!-- <input type="hidden" th:name="${_csrf.parameterName}"
|
<!-- <input type="hidden" th:name="${_csrf.parameterName}"
|
||||||
th:value="${_csrf.token}" /> -->
|
th:value="${_csrf.token}" /> -->
|
||||||
|
Loading…
Reference in New Issue
Block a user