Java 如何在运行时修改Spring安全过滤器链?

Java 如何在运行时修改Spring安全过滤器链?,java,spring,spring-security,Java,Spring,Spring Security,我使用的是Spring安全性,我的配置如下所示。我正在使用图书馆 有没有办法在运行时更改过滤器?我可以在中看到getRequestMatcher()方法,但无法设置它。我是否以错误的方式处理这个问题 我认为您可以实现一个定制的RequestMatcher来检查url: public class CustomizedAntRequestMatcher implements RequestMatcher { @Override public boolean matches(HttpS

我使用的是Spring安全性,我的配置如下所示。我正在使用图书馆


有没有办法在运行时更改过滤器?我可以在中看到
getRequestMatcher()
方法,但无法设置它。我是否以错误的方式处理这个问题

我认为您可以实现一个定制的RequestMatcher来检查url:

public class CustomizedAntRequestMatcher implements RequestMatcher {
    @Override
    public boolean matches(HttpServletRequest request) {
        String url = "/saml/SSO/**"; //change this line to get your dynamic configuration
        AntPathRequestMatcher antPathRequestMatcher = new AntPathRequestMatcher(url);
        return antPathRequestMatcher.matches(request);
    }
}
然后使用自定义请求匹配器替换AntPathRequestMatcher:

chains.add(new DefaultSecurityFilterChain(new CustomizedRequestMatcher(),
                    samlWebSSOProcessingFilter(samlAuthenticationProvider, contextProvider, samlProcessor)));

如果这种方法不能解决您的问题,请与我联系。

Adam,您的回答很有帮助。您还可以建议如何在运行时修改我在
第1行中添加的过滤器吗你好,您解决了这个问题吗?很抱歉,我来不及回复这个评论。关于这个问题,我不太清楚您的动态配置。我认为您可以实现一个bean来管理您的配置,并在“第1行”中获取该bean,然后从该bean获取您的配置。
public class CustomizedAntRequestMatcher implements RequestMatcher {
    @Override
    public boolean matches(HttpServletRequest request) {
        String url = "/saml/SSO/**"; //change this line to get your dynamic configuration
        AntPathRequestMatcher antPathRequestMatcher = new AntPathRequestMatcher(url);
        return antPathRequestMatcher.matches(request);
    }
}
chains.add(new DefaultSecurityFilterChain(new CustomizedRequestMatcher(),
                    samlWebSSOProcessingFilter(samlAuthenticationProvider, contextProvider, samlProcessor)));