Witam, mam bardzo dziwny problem którego nie rozumiem
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf().disable();
http.exceptionHandling()
.authenticationEntryPoint(authEntryPoint)
.and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.authorizeHttpRequests(request -> request
.requestMatchers("/auth/login").permitAll()
.requestMatchers("/addresses/**").hasAnyRole("ADMIN", "PLANNER", "FORWARDER", "ACCOUNTANT")
.requestMatchers("/warehouses/**").hasAnyRole("ADMIN", "PLANNER", "FORWARDER")
.anyRequest().authenticated());
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
return http.build();
}
Mam w bazie danych użytkownika który ma role ADMIN.
Kiedy loguje się jako admin, i pobieram JWT token, i próbuje np dostać się do warehouses to dostaje w Postmanie błąd 401 Unauthorized.
Dla testów usunąłem te dwie liniki :
.requestMatchers("/addresses/**").hasAnyRole("ADMIN", "PLANNER", "FORWARDER", "ACCOUNTANT")
.requestMatchers("/warehouses/**").hasAnyRole("ADMIN", "PLANNER", "FORWARDER")
i teraz do 'warehouses' czy 'addresses' i tak trzeba byc zalogowanym, ale juz po zalogowaniu, i przekazaniu tokena, bez problemu mam do tych endpointow dostep.
Nie rozumiem dlaczego tak sie dzieje, uzytkownik na ktorego sie loguje ma przypisaną role, wszystko jest ok.