使用Spring Boot和Spring Security我配置了一个超级简单的应用程序,并添加了基于URL的安全性,但不受尊重。例如,如果我以“侦察员”的身份登录并点击/api/leaders
等管理员URL,我仍然可以看到它。为什么Spring Security Java Config AntMatcher不能阻止这个URL?
我已经尝试了很多排列的网址,甚至尝试anyRequest().denyAll()
和scout
用户仍然可以访问它。
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"com.ssoward.scouts"})
public class MainConfiguration {
public static void main(String[] args) throws Exception {
SpringApplication.run(MainConfiguration.class, args);
}
//security
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
static class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return authenticationManager();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/leaders*").hasRole("ADMIN") //url level security
.antMatchers("/api/scouts*").hasRole("USER"); //url level security
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("leader").password("password").roles("USER", "ADMIN").and()
.withUser("scout").password("password").roles("USER");
}
}
}
整个项目是在Github上:https://github.com/ssoward/scouts
你有春天的安全'DelegatingFilterProxy'映射在你的'/ api'网址吗? –
不,我没有那个过滤器。我以为Spring Boot Actuator会自动配置它。 – checketts