I'm trying to allow only users that have role 'ADMIN' to access following endpoints:
../adminconfig/* (those that have 'adminconfig' in the url)
Here is my configuration:
@SpringBootApplication
@EnableWebSecurity
@RestController
public class BootApplication extends WebSecurityConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(BootApplication.class, args);
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("{noop}1").roles("USER").and()
.withUser("admin").password("{noop}1").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests()
.anyRequest().authenticated()
.antMatchers("/adminconfig/**").hasRole("ADMIN")
.and()
.formLogin().and()
.httpBasic();
}
}
But still i can access them with any other user, for example with 'USER' role. What am i doing wrong?