如何将这些Spring Security XML配置转换为Java配置

时间:2018-06-28 16:01:42

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

我正在尝试将spring security xml的配置转换为java的配置,有人知道如何将以下这些标记转换:

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

这个

    <oauth:provider consumer-details-service-ref="oauthConsumerDetails" token-services-ref="tokenServices"
    require10a="false" authenticate-token-url="/oauth_authenticate_token" />

这个

<oauth:token-services id="tokenServices" />

还有这个

<global-method-security  pre-post-annotations="enabled" secured-annotations="enabled"/>

1 个答案:

答案 0 :(得分:1)

我不完全了解您想要什么,但是这里有一些带有Java配置注释的代码可以为您提供帮助:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private UserService userDetailsService;

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

@Autowired
public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(authenticationProvider());
}

@Bean
public DaoAuthenticationProvider authenticationProvider() {
    DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
    authenticationProvider.setUserDetailsService(userDetailsService);
    authenticationProvider.setPasswordEncoder(passwordEncoder());
    return authenticationProvider;
}

}