Spring boot Spring security、thymeleaf和cookie

Spring boot Spring security、thymeleaf和cookie,spring-boot,spring-security,thymeleaf,Spring Boot,Spring Security,Thymeleaf,实际上,我使用spring boot、thymeleaf和spring security。 在应用程序中,安全性被一分为二 一个用于mvc,另一个用于rest调用 我搜索了一种方法,如果login是ok的话,就可以创建一个带有login/password的cookie,以便能够为每个ajax调用添加头 headers: { "Authorization": "Basic " + $.cookie('cookie-authorization') }, 因此,如果登录成功,我会搜索创建co

实际上,我使用spring boot、thymeleaf和spring security。 在应用程序中,安全性被一分为二

一个用于mvc,另一个用于rest调用

我搜索了一种方法,如果login是ok的话,就可以创建一个带有login/password的cookie,以便能够为每个ajax调用添加头

headers: {
    "Authorization": "Basic " + $.cookie('cookie-authorization')
},
因此,如果登录成功,我会搜索创建cookie


是否可以在服务器端对其进行编辑?

您可以使用来自的代码在所有Ajax调用中包含令牌

$(function() {
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    $(document).ajaxSend(function(e, xhr, options) {
        xhr.setRequestHeader(header, token);
    });
})
希望这有帮助