2014-06-08 94 views
0

我创建了基于示例应用程序的Spring Boot - Security项目,但是Rest Controller正常工作,意味着我可以访问其余资源,但安全性似乎根本不会启动,所以当我添加如下所述的断点时,它不会在那里出现。不知道为什么。Spring Security - 身份验证没有启动

@Configuration 
@EnableWebSecurity 
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
     // @formatter:off 
     auth.inMemoryAuthentication() // breakpoint here 
      .withUser("roy") 
       .password("spring") 
       .roles("ADMIN"); 
     // @formatter:on 
    } 

    @Override 
    @Bean 
    public AuthenticationManager authenticationManagerBean() throws Exception { 
     return super.authenticationManagerBean(); 
    } 

} 

这里是主持和编辑与Codio完整的项目:http://bit.ly/1uFI0t5

+0

尝试添加@EnableAutoConfiguration注释。 –

+0

是的我有, – xybrek

回答

0

你必须告诉框架这是它有固定的网址。

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
     auth.inMemoryAuthentication().withUser("user").password("password").roles("USER"); 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http.authorizeRequests() 
      .antMatchers("/**").access("hasRole('ROLE_USER')") 
      .and().formLogin(); 

    } 
} 
+0

是的我在OAuth2ServerConfiguration的ResourceServerConfiguration – xybrek

+0

顺便说一句,我复制的来源是从这里https://github.com/royclarkson/spring-rest-service-oauth – xybrek

+0

这个代码的问题是该formLogin()无法解析 – xybrek

相关问题