在弹簧安全过滤器链之前评估Web服务拦截器

发布于 2025-01-24 09:27:11 字数 2751 浏览 3 评论 0原文

我有一个基于SOAP的Web服务应用程序,该应用程序正在利用 Spring Web Services(和Spring WS Security(和Spring WS Security)以及 Spring Security 。我正在使用自定义 AbstractwssecurityInterceptor 验证传入的请求(使用注射authenticationManager),并将成功的身份验证添加到SecurityContext。然后,我拥有一个自定义的ACESSDECISIONMANAGER,它使用自定义的WebsecurityExpressionHandler来验证Interceptor添加到上下文中的主属性的某个属性。

以下是我的配置文件的外观:

securityConfig.java:

@Getter
@Setter
@Configuration
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final AccessDecisionManager customAccessDecisionManager;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.
                cors()
                .and().csrf().disable()
                .authorizeRequests()
                .accessDecisionManager(customAccessDecisionManager)
                .antMatchers(GET, "/actuator/**").permitAll()
                .anyRequest().access("customAccessMethod()")
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

}

webServiceConfig.java:

@EnableWs
@Configuration
@RequiredArgsConstructor
public class WebServiceConfig extends WsConfigurerAdapter {

    private final AuthenticationManager authenticationManager;

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<>(servlet, "/ws/*");
    }

    ...

    ...


    @Bean
    AbstractWsSecurityInterceptor customAuthenticationInterceptor() {

        return new CustomAuthenticationInterceptor(authenticationManager);
    }

    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {

        interceptors.add(customAuthenticationInterceptor());
    }

}

此设置的问题是首先评估了弹簧安全过滤器链,并且未能使身份验证失败,因为在请求之前对AccessDecisionManager进行了评估,要输入自定义AbstractwsSecurityInterceptor,然后将身份验证放在SecurityContext中。

是否有任何方法可以评估Web服务上的请求和WS安全方面的拦截器和处理。这是可能的吗?

预先感谢您的帮助!

I have a SOAP-based web services application which is leveraging Spring Web Services (and Spring WS Security) as well as Spring Security. I am using a custom AbstractWsSecurityInterceptor to authenticate the incoming requests (using an injected AuthenticationManager) and to add the successful authentications to the SecurityContext. I then have a custom AcessDecisionManager which is using a custom WebSecurityExpressionHandler to validate a certain property from the principal added to the context by the interceptor.

Below is an idea of what my configuration files look like:

SecurityConfig.java:

@Getter
@Setter
@Configuration
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final AccessDecisionManager customAccessDecisionManager;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.
                cors()
                .and().csrf().disable()
                .authorizeRequests()
                .accessDecisionManager(customAccessDecisionManager)
                .antMatchers(GET, "/actuator/**").permitAll()
                .anyRequest().access("customAccessMethod()")
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

}

WebServiceConfig.java:

@EnableWs
@Configuration
@RequiredArgsConstructor
public class WebServiceConfig extends WsConfigurerAdapter {

    private final AuthenticationManager authenticationManager;

    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<>(servlet, "/ws/*");
    }

    ...

    ...


    @Bean
    AbstractWsSecurityInterceptor customAuthenticationInterceptor() {

        return new CustomAuthenticationInterceptor(authenticationManager);
    }

    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {

        interceptors.add(customAuthenticationInterceptor());
    }

}

The issue with this setup is that the Spring Security filter chain is evaluated first and fails the authentication because the AccessDecisionManager is evaluated before the request has a chance to enter the custom AbstractWsSecurityInterceptor and place the authentication in the SecurityContext.

Is there any way to evaluate the interceptor and handling of the request on the Web Services and WS Security side of things before it then hits the Spring Security filter chain? Is this a possibility?

Thank you in advance for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文