gpt4 book ai didi

java - 如何将这些spring security xml配置转换为java配置

转载 作者:行者123 更新时间:2023-12-02 11:04:31 26 4
gpt4 key购买 nike

我正在尝试将 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"/>

最佳答案

我不完全明白你想要什么,但这里有一些带有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;
}

}

关于java - 如何将这些spring security xml配置转换为java配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51087215/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com