将xml bean配置转换为java配置

时间:2015-12-09 07:58:37

标签: java spring spring-security spring-java-config openid-connect

我基于这个example并尝试在java配置中构建我的代码。我对bean ref感到困惑。我刚接触弹簧的安全性和java配置。有人可以解释我这个

<beans:bean id="preAuthFilter" class="com.sappe.ontrack.security.LoginGoogleFilter">
    <beans:property name="authenticationManager" ref="authenticationManager"/>
</beans:bean>

<beans:bean id="preAuthenticationProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
    <beans:property name="preAuthenticatedUserDetailsService" ref="preAuthUserDeatils" />
</beans:bean>

这是我感到困惑的一部分,这不是一个bean,这是一个用于弹簧安全的标签。

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="preAuthenticationProvider">
    </authentication-provider>
</authentication-manager>

我的代码中有这个

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    // OpenId connect code....
    ........
    @Bean(name="preAuthFilter")
    public CustomFilter preAuthFilter() {
        return new CustomFilter();
    }

    @Bean(name = "preAuthProvider")
    public PreAuthenticatedAuthenticationProvider preAuthProvider() {
        return new PreAuthenticatedAuthenticationProvider();
    }
    @Bean(name="authenticationManager")
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception   {
         return super.authenticationManagerBean();
    }

    public void configure(HttpSecurity http) throws Exception {
        http.addFilter(CustomPreAuthFilter).
            .....//code
    }
}

0 个答案:

没有答案