Я пытался выполнить поиск в Интернете, но нашел только управление сеансами Spring Boot (для одного пользователя).
Это мой контроллер безопасности:
Код: Выделить всё
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
@AllArgsConstructor
public class Config {
@Autowired
private JwtAuthFilter authFilter;
@Bean
public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationProvider authenticationProvider) throws Exception {
return http
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/", "/**", "/auth/**", "/auth/").permitAll();
auth.requestMatchers("/hello", "/data/dashboard").authenticated();
/*auth.requestMatchers("/auth/hello", "/auth/hi").authenticated()
auth.requestMatchers("/auth/workingpage").hasRole("ABCS")
*/})
/*.formLogin(login -> login.loginPage("/auth/login.html")
.loginProcessingUrl("/auth/login")
.defaultSuccessUrl("/hello", true)
.failureForwardUrl("/auth/registration.html")
)*/
.httpBasic(withDefaults()).csrf(AbstractHttpConfigurer::disable)
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(authFilter, UsernamePasswordAuthenticationFilter.class)
.build();
}
@Bean
public AuthenticationProvider authenticationProvider(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder) {
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
authenticationProvider.setUserDetailsService(userDetailsService);
authenticationProvider.setPasswordEncoder(passwordEncoder);
return authenticationProvider;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager();
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... multi-user