简体   繁体   English

Spring Boot / Security / Apache CXF SOAP服务访问限制

[英]Spring Boot/Security/Apache CXF SOAP service access restriction

I have created Apache CXF SOAP webservice in Spring Boot as per below config: 我在Spring Boot中创建了Apache CXF SOAP webservice,如下所示:

@Bean
public ServletRegistrationBean wsDispatcherServlet() {
 return new ServletRegistrationBean(new CXFServlet(), "/service/*");
}

@Bean
public Endpoint pegaEndpoint() {
 EndpointImpl endpoint = new EndpointImpl(springBus, "/service/");
 endpoint.publish("ws");
 return endpoint;
}

Now I want to use httpBasic authentication to call a web service, but at the same time I want the WSDL to be publicly accessible. 现在我想使用httpBasic身份验证来调用Web服务,但同时我希望WSDL可以公开访问。 Is that possible to configure with Spring Security? 是否可以使用Spring Security进行配置? I have below code in Java Configuration class for security, but it doesnt really work - the basic authentication is enforced on both web service calls and wsdl accessed by http://localhost:8080/service/ws?WSDL 为了安全起见,我在Java配置类中有以下代码,但它确实不起作用 - 在http://localhost:8080/service/ws?WSDL访问的Web服务调用和wsdl上强制执行基本身份验证

Can Spring Security differentiate based on the URL param? Spring Security可以根据URL参数进行区分吗? Or can I set a WSDL location to be different that the URL used to call the web service? 或者,我可以将WSDL位置设置为与用于调用Web服务的URL不同吗?

@Autowired
private void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
 auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}

@Override
public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().                                                                                  
        antMatchers("/service/**").hasRole("USER").and().httpBasic().and().
        csrf().disable();
}

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/service/ws?wsdl");
}

Permit all on the wsdl should do it - 允许所有在wsdl上应该这样做 -

        http
            .authorizeRequests()
                .antMatchers("/service/ws?wsdl").permitAll()
                .antMatchers("/service/**").hasRole("USER").and().httpBasic().and().
        csrf().disable();

I ended up doing below. 我最终在下面做了。 Apparently ant matchers dont recognize any URL parameters so I used regex one: 显然蚂蚁匹配器不识别任何URL参数所以我使用正则表达式:

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().regexMatchers("/service/ws\\?WSDL");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM