登录用户的Spring授权

时间:2016-08-02 22:23:19

标签: java spring authentication spring-security

所以我正在尝试实施弹簧授权。我阅读了文档并添加了以下代码。

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/login", "/logout", "/register", "resources/**").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .loginProcessingUrl("/login");
    }
}

这很简单。但我真正想要的是实现我自己的authenticated()方法。因此,当执行anyRequest().authenticated()时,它应该基本上调用我自己实现的authenticated()方法,其中我检查用户是否登录。我想要下面这样的东西

authenticated(){
//I check here if user is present in the session or not
//this means logged in or not
}

所以我真正需要的是知道如何实现authenticated()方法,以便在执行anyRequest().authenticated()时我将调用自己的authenticated()方法。

1 个答案:

答案 0 :(得分:0)

您需要实现自己的AuthenticationManager。如果您@Component它将在您的过滤器链中自动连接。

相关问题