【发布时间】:2019-08-08 08:15:26
【问题描述】:
在 Spring 安全性中,我想对以 api/** 开头的 url 使用基本身份验证 对以 /ldap/ 开头的 url 使用 LDAP Rest 身份验证。我当前的代码还允许 ldap/ 进行基本身份验证。
问题来了,即使我将它们用作单独的 AuthenticationProviders,如 LdapAuthProvider 和 BasicAuthProvider,我如何使用它来指向特定的 url
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Configuration
@Order(1)
public class BasicAuthenticationProvider extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/swagger-ui*", "/info", "/health").permitAll()
.and().authorizeRequests().antMatchers("/order/**").fullyAuthenticated()
.and().httpBasic().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().csrf().disable()
.anonymous().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(inMemoryUserDetailsManager());
}
}
@Configuration
@Order(2)
public class LdapAuthenticationProvider extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/ldap/**").fullyAuthenticated().and().httpBasic()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.ldapAuthentication() code here......
}
}
}
【问题讨论】:
-
我已经添加了我尝试过的代码,它还允许 /ldap/** 具有让我困惑的基本身份验证
-
你有没有想过这个问题?
标签: spring spring-boot spring-mvc spring-security spring-security-ldap