Spring Session создает новый сеанс после каждой перезагрузки сайта.В чем дело? - PullRequest
0 голосов
/ 14 марта 2019

У кого-нибудь есть идея, что не так с моим HttpSessionIdResolver?После каждой перезагрузки сайта пользователь получает новый идентификатор сеанса.Если я удалю HttpSessionIdResolver из конфигурации, он будет работать нормально, но тогда имя участника будет пустым ...

Примечание: я использую Spring Session с JDBC!

Вот моя безопасностьФайл конфигурации:

@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
@EnableJdbcHttpSession
@EnableJpaRepositories(basePackageClasses = UsersRepository.class)
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Autowired
private CustomUserDetailsService userDetailsService;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

    auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable();
    http.authorizeRequests()
            .antMatchers("/*").authenticated().anyRequest().permitAll()
            .antMatchers("/sources/*").anonymous().anyRequest().permitAll()
            .antMatchers("/public/*").anonymous().anyRequest().permitAll()
            .and()
            .formLogin().
            loginPage("/login").
            loginProcessingUrl("/app-login").
            usernameParameter("app_username").
            passwordParameter("app_password").
            permitAll()
            .and()
            .exceptionHandling().
            accessDeniedPage("/error403");
}

@Bean
public BCryptPasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

@Bean
public HttpSessionIdResolver httpSessionIdResolver(){
    return new HeaderHttpSessionIdResolver("X-Auth-Token");
}
}
...