我遇到的问题是为身份验证中的多个入口点启用AbstractAuthenticationProcessingFilter
我必须以两种方式登录,一种是使用电子邮件ID,另一种是通过UI通过员工ID登录,两种方式都需要获取我已配置的jwt令牌
员工ID ,具有 LDAP ,具有登录URL / login
的配置电子邮件ID ,具有自定义身份验证,登录URL为 / loginWD
我已经配置了2个WebSecurityConfigurerAdapter
App1ConfigurationAdapter 用于带有订单1的LDAP , App2ConfigurationAdapter 用于 CustomAuthentication with订单2
当我们点击/ loginWD扩展了GenericFilterBean的JWTAuthenticationFilter时,将在AbstractAuthenticationProcessingFilter中的tryAuthentication方法之前被调用
attemptAuthentication AbstractAuthenticationProcessingFilter仅针对订单1而不是订单2
当我以其他方式无法更改订单时。
如何使两者都能使用?
/ * * **对于EMP ID LDAP * / **
full
/ * *用于通过电子邮件发送自定义身份验证 * /
@Order(1)
@Configuration
public class App1ConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Override
@CrossOrigin
protected void configure(HttpSecurity http) throws Exception {
// disable caching
LOGGER.info("Configuring auth filter");
http.headers().cacheControl();
http.csrf().disable().authorizeRequests().antMatchers("/").permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.anyRequest()
.authenticated().and()
.addFilterBefore(new JWTLoginFilter("/login", authenticationManager()), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
LOGGER.info("Establishing the Ldap Connection");
auth.ldapAuthentication().userSearchFilter(SEARCH_FILTER_STRING)
.userSearchBase(CONTEXT_SEARCH).contextSource().url(LDAPURI)
.managerDn(DN)
.managerPassword(new String(Base64.getDecoder().decode(PASSWORD_STRING))).and()
.groupSearchBase(GROUP_SEARCH_BASE_STRING).rolePrefix(ROLE_PREFIX_STRING)
.userSearchFilter(USERSEARCHFILTER_STRING);
}
}
/ * *通用JWT身份验证过滤器 * / **
@Configuration
@Order(2)
public class App2ConfigurationAdapter extends WebSecurityConfigurerAdapter{
@Override
@CrossOrigin
protected void configure(HttpSecurity http) throws Exception {
// disable caching
LOGGER.info("Configuring auth filter");
http.headers().cacheControl();
http.csrf().disable().authorizeRequests().antMatchers("/").permitAll()
.antMatchers(HttpMethod.POST, "/loginWD").permitAll()
.anyRequest()
.authenticated().and()
.addFilterBefore(new JWTLoginFilter("/loginWD", authenticationManager()), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new JWTAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
//.authenticationProvider(customAuthProvider);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
LOGGER.info("Establishing the Custom");
auth.authenticationProvider(customAuthProvider);
}
}