Я пытаюсь настроить метод logout () в Spring-security, вход в систему работает нормально. Я следовал за https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_logout. Даже если он отправляет заголовки и получает cookie-файлы, этот метод не аннулирует HTTP-сессию, пользователь все еще проходит аутентификацию. Я также попытался найти решение здесь: Как выйти из клиента oauth2 в Spring? , но я думаю, что что-то может отсутствовать, пожалуйста, помогите.
@Configuration
@EnableOAuth2Sso
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/error", "/webjars/**").permitAll()
.anyRequest().authenticated()
.and()
.logout()
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.and()
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
}
security.oauth2.client.client-id=XXXXXXXXXXXX
security.oauth2.client.client-secret=XXXXXXXXXXXXXXX
security.oauth2.client.access-token-uri=https://oauth2.googleapis.com/token
security.oauth2.client.user-authorization-uri=https://accounts.google.com/o/oauth2/v2/auth
security.oauth2.resource.user-info-uri=https://openidconnect.googleapis.com/v1/userinfo
security.oauth2.client.scope=openid, email, profile
<script type="text/javascript">
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (settings.type == 'POST' || settings.type == 'PUT'
|| settings.type == 'DELETE') {
if (!(/^http:.*/.test(settings.url) || /^https:.*/
.test(settings.url))) {
//console.log(Cookies.get('XSRF-TOKEN'));
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-XSRF-TOKEN",
Cookies.get('XSRF-TOKEN'));
}
}
}
});
var logout = function () {
$.post("/logout", function () {});
return true;
};
</script>
Вот повар ie ответ при нажатии на кнопку выхода из системы:
![Here's the cookie response when clicking on logout button](https://i.stack.imgur.com/txklY.png)