Весенняя сессия входа в системуJAVA

Программисты JAVA общаются здесь
Anonymous
Весенняя сессия входа в систему

Сообщение Anonymous »

У меня возникла проблема с процессом входа в систему. При успешном входе в систему пользователь не может видеть/посещать какие-либо закрытые страницы (просто возвращает пользователя в форму входа), и проблема должна быть в Spring Authentication - это фрагмент кода в контроллере при успешном входе в систему:

Код: Выделить всё

UsernamePasswordAuthenticationToken authenticationToken =  new UsernamePasswordAuthenticationToken(username, password); Authentication authentication = authenticationManager.authenticate(authenticationToken); SecurityContextHolder.getContext().setAuthentication(authentication);
и SecurityConfig.java:

Код: Выделить всё

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.requestMatchers("/logged", "/login", "/register").permitAll() // Allow public access
.anyRequest().authenticated() // All other requests require authentication
.and()
.formLogin()
.loginPage("/login") // Specify your login page
.permitAll() // Allow everyone to see the login page
.and()
.logout()
.permitAll();

return http.build();
}

@Bean
public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception {
AuthenticationManagerBuilder authenticationManagerBuilder =
http.getSharedObject(AuthenticationManagerBuilder.class);

authenticationManagerBuilder.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());

return authenticationManagerBuilder.build();
}
@Bean
public CustomUserDetailsService userDetailsService() {
return new CustomUserDetailsService();
}
Я попробовал выполнить поиск в Google, но не смог решить проблему.

Подробнее здесь: https://stackoverflow.com/questions/790 ... in-session

Вернуться в «JAVA»