我已经开始开发一个小的单页面应用程序。这是一个典型的在线商店。我需要用户仅登录付款流程,因此每个访问者都可以访问其余的应用程序。
我正在使用AngularJS为前端进行路由,使用Spring Data进行Spring Boot,为后端使用Spring Security。
现在有一些页面安全我“欺骗”Angular:
$routeProvider
[...]
.when("/admin/addproduct", {
templateUrl: "/admin/addproductform",
controller: ""
})
[...]
.otherwise({
redirectTo: "/"
});
跑过我的控制器:
@Controller
public class MainController {
private static final Logger log = LoggerFactory.getLogger(MainController.class);
@RequestMapping(value="/admin/addproductform", method=RequestMethod.GET)
public String addProductForm(){
return "/templates/admin/admin_add_product.html";
}
}
这是我的安全配置:
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/templates/login.html").permitAll()
.and()
.logout().permitAll()
.and()
.authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN")
.and()
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
.csrf()
.disable();
// had to disable csrf, because it screwed with the file upload
// .csrfTokenRepository(csrfTokenRepository());
}
// private CsrfTokenRepository csrfTokenRepository() {
// HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
// repository.setHeaderName("X-XSRF-TOKEN");
// return repository;
// }
}
现在我的问题是,这种做法一般是错误的吗?甚至可以使用AngularJs和Spring Security来保护一些页面吗?
提前致谢