我正在将ADFS支持添加到一个现有的Spring项目中。由于我们已经拥有自己的JWT身份验证,希望能够与ADFS身份验证并行工作,因此我想实现一个新的过滤器链,仅处理特定的API请求路径。我的意思是,我想创建:
但是在调试时,我发现这个新的过滤器链被设置为匹配“任何”请求。所以我可能设置了错误的匹配器。
- ADFS过滤器链,将处理所有/adfs/saml/** API调用
- 保留默认的过滤器链,将处理所有其他API调用
public abstract class SAMLWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
//some code
protected final HttpSecurity samlizedConfig(final HttpSecurity http) throws Exception {
http.httpBasic().authenticationEntryPoint(samlEntryPoint())
.and()
.csrf().ignoringAntMatchers("/saml/**")
.and()
.authorizeRequests().antMatchers("/saml/**").permitAll()
.and()
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
.addFilterAfter(filterChainProxy(), BasicAuthenticationFilter.class);
// store CSRF token in cookie
if (samlConfigBean().getStoreCsrfTokenInCookie()) {
http.csrf()
.csrfTokenRepository(csrfTokenRepository())
.and()
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class);
}
return http;
}
}
我扩展了这个类:
@EnableWebSecurity
@Configuration
@Order(15)
@RequiredArgsConstructor
public class ADFSSecurityConfiguration extends SAMLWebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
samlizedConfig(http)
.authorizeRequests()
.antMatchers("/adfs")
.authenticated();
}
}
但是在调试时,我发现这个新的过滤器链被设置为匹配“任何”请求。所以我可能设置了错误的匹配器。