简体   繁体   中英

How to convert these spring security xml configuration to java configuration

I'm trying to convert spring security xml configurations to java configuration, does someone knows to convert these below tags:

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

this one

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

this one

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

and this one

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

I don't understand fully what you want, but here some code with Java configuration annotations that can help you:

@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;
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM