如何将这些 spring 安全 xml 配置转换为 java 配置
How to convert these spring security xml configuration to java configuration
我正在尝试将 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;
}
}
我正在尝试将 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;
}
}