Не начинать сеансы для анонимных пользователей - PullRequest
0 голосов
/ 12 февраля 2019

Как я могу отключить сеансы для анонимных пользователей в весенней загрузке 2.0?

Моя текущая конфигурация:

public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/actuator/**").permitAll()
                .antMatchers("/password/forgot/**").permitAll()
                .antMatchers("/password/reset/**").permitAll()
                .antMatchers("/css/**").permitAll()
                .antMatchers("/js/**").permitAll()
                .antMatchers("/img/**").permitAll()
                .antMatchers("/manage/**").permitAll()
                .antMatchers( "/favicon.ico").permitAll()
                .anyRequest().authenticated();

        http
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .successHandler(authSuccessHandler)
                .and()
                .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login")
                .invalidateHttpSession(true)
                .permitAll();
    }
}

Когда я открываю страницу входа, сеанс все еще создается:

enter image description here

1 Ответ

0 голосов
/ 12 февраля 2019

Возможно, сеанс автоматически создается Spring Security.Это поведение можно отключить, установив create-session в never.Это означает, что Spring Security не будет пытаться автоматически создать сеанс.

<http create-session="never">
[...]
</http>

Некоторые подробности здесь: https://www.baeldung.com/spring-security-session

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...