我创建了一个Spring Boot应用程序,并在/resources/static
文件夹中有我的前端应用程序。用Spring Security保护Angular JS应用程序
对于路由,我使用Angular JS UI路由器库。 我已经定义了一个路由,我只想访问管理员,现在我试图使用Spring Security来保护它。
这里是我WebSecurity配置类:
@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访问。
但是,每当我访问该路由时,都不会请求登录,任何人都可以查看该页面。
我应该遵循另一种方法吗?
这工作,但现在我应该登录访问所有的端点,即使他们之前可用 –