Code
package com.ronapps.ecommerceapi.security;
import ...
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {
@Autowired
private MyUserDetailsService myUserDetailsService;
@Bean
public AuthenticationManager authenticationManager() throws Exception {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(myUserDetailsService);
provider.setPasswordEncoder(bcryptPasswordEncoder());
return new ProviderManager(provider);
}
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth -> auth
.requestMatchers( "/register_user", "/register_admin", "/login", "/home").permitAll()
.requestMatchers("/user/**").hasRole("USER")
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated())
.httpBasic(Customizer.withDefaults())
.csrf(crsf -> crsf.disable());
return http.build();
}
@Bean
PasswordEncoder bcryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}```
I tried sending an API request to my `register_user` endpoint but i'm getting a 401 error despite using `permitAll()`