I have two configuration:
@Order(1)
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/api/**")
.authorizeRequests()
.anyRequest().hasRole("USER")
.and()
.httpBasic()
.and()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.exceptionHandling()
.authenticationEntryPoint(new ApiAuthenticationEntryPoint(objectMapper));
}
@Order(2)
http.authorizeRequests()
.antMatchers("/product/**").hasRole(SecurityRoles.USER)
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/authenticateTheUser")
.successHandler(customAuthenticationSuccessHandler)
.permitAll()
.and()
.logout()
.permitAll()
.and()
.exceptionHandling()
.accessDeniedPage("/access-denied");
I need to add functionality to register a new user with the REST endpoint /api/users
with no authentication. The other /api/**
endpoints should remain with basic authentication. How to do this? I can't see the method antMatcher
with an option to choose the http method type.
Edit:
I need something like this:
http.antMatcher("/api/users", HttpMethod.POST.toString).permitAll()
.and()
.antMatcher("/api/**")
.authorizeRequests()
.anyRequest().hasRole("USER")
(...)