2017-03-16 29 views
-1

目前,我在Spring Security和连接的Angular中遇到了一些问题。我配置的Spring Security中的一类,它看起来像:Spring Security authenticated()不适用于AngularJS

@Override 
public void configure(WebSecurity web) throws Exception { 
    web.ignoring() 
      .antMatchers(HttpMethod.OPTIONS, "/**") 
      .antMatchers("/app/**/*.{js,html}") 
      .antMatchers("/static/node_modules/**"); 
} 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
     .csrf().disable() 
     .authorizeRequests() 
      .antMatchers("/auth").permitAll() 
      .antMatchers("/", "/login").permitAll() 
      .antMatchers("/resources/templates/index.html").permitAll() 
      .antMatchers("/api/client, /api/reservation", "/api/reservationreminder", "/api/review", "/api/user", "/api/vehicle", "/api/wash", "/api/washlocation", "/api/washtype", "/api/worker").hasAuthority(AuthoritiesConstants.CLIENT) 
      .antMatchers("/static/app/styles", "/static/app/js").permitAll() 
      .anyRequest().authenticated() 
      .and() 
     .logout() 
      .logoutSuccessUrl("/static/views/pages/login.html") 
      .permitAll() 
      .and() 
     .formLogin() 
      .loginProcessingUrl("/static/views/pages/login.html") 
      .permitAll() 
} 

而对于每次我尝试运行我的应用我有时间无法在浏览器这样的:

enter image description here

但是当我扔出去.anyRequest().authenticated()一切似乎都行得通 - 这样我就可以在浏览器中看到我的应用程序。在这个例子中不起作用的是,Spring Security不起作用 - 我的意思是尽管我每个站点都有角色,但我可以从角色/用户那里进入这些站点,理论上我不能。

enter image description here

回答

0

我使用Spring引导与角(在resource/static文件夹),配置:

.antMatchers("/css/**", "/js/**", "/img/**", "/fonts/**").permitAll() 
.antMatchers("/index.html", "/") 

我怀疑你不需要static前缀。

+0

不。我现在删除静态/并失败,如下所示:http://imgur.com/a/zToHH – bielas

+0

检查此[Spring Boot and Angular](https://github.com/spring-guides/)啧 - 弹簧 - 安全和 - 角JS /树/主/碱性)。你不需要那种类型的控制器。 –

+0

好吧..但我有,需要修复它,因为它是现在.. – bielas

1

你在你的HTML文件的静态资源的URL是错误的,看到Spring Boot Reference

默认情况下,资源被映射到/**但你可以调整它通过spring.mvc.static-path-pattern

从您的HTML文件和您的Spring Security配置中的URL中删除/static