Spring Security - 身份验证未启动

时间:2014-06-08 18:04:09

标签: java spring spring-security spring-boot

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

@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

1 个答案:

答案 0 :(得分: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();

    }
}
相关问题