I have 3 API endpoints all having GET, POST & DELETE functions, 3 are secured using spring boot security,
- /api/travel
- /api/employees
- /api/assoc
I want /api/employees's POST to be publicly accessible, because it's my Sign-up logic as obviously the user doesn't have to sign in to sign up.
Below is the Config file's filter snipppet thats not working:
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity security) throws Exception{
return security.csrf(csrf->csrf.disable())
.authorizeHttpRequests(authorize -> authorize
.requestMatchers(HttpMethod.POST, "/api/employees").permitAll()
.anyRequest().authenticated()
)
.httpBasic(Customizer.withDefaults())
.build();
}
I
I tried POSTing the body as Json in Postman to /api/employees with no authorisation header, but it is giving me 401 unauthorised.
Try option with extends
YOUR_CLASSwithWebSecurityConfigurerAdapter, after that override methodin this method you can put your code inside, remeber YOUR_CLASS should be annotated with: