【发布时间】:2017-04-14 19:47:11
【问题描述】:
我创建了一个 Spring Boot 应用程序,我的前端应用程序位于 /resources/static 文件夹中。
对于路由,我使用的是 Angular JS UI 路由器库。 我已经定义了一条路线,我只想让管理员访问它,现在我正在尝试使用 Spring Security 来保护它。
这是我的网络安全配置类:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/#/admin").hasRole("ADMIN")
.and()
.formLogin()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/member", "/member/**").permitAll()
.antMatchers(
HttpMethod.GET,
"/",
"/*.html",
"/favicon.ico",
"/**/*.html",
"/**/*.css",
"/**/*.js",
"/**/**/*.css",
"/**/**/*.js",
"/**/**/*.html",
"/**/**/**/*.css",
"/**/**/**/*.js",
"/**/**/**/*.html",
"/**/**/**/**/*.css",
"/**/**/**/**/*.js"
).permitAll()
.antMatchers("/auth/**", "/member/**", "/account/**").permitAll()
.and()
.csrf().disable();
}
}
我试图保护的路由可以通过http://localhost:8080/#/admin 访问。
但是,每当我访问该路由时,都不需要登录,任何人都可以查看该页面。
我应该遵循另一种方法吗?
【问题讨论】:
标签: java angularjs spring spring-security spring-boot