[英]Spring Boot/Security/Apache CXF SOAP service access restriction
我在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;
}
现在我想使用httpBasic身份验证来调用Web服务,但同时我希望WSDL可以公开访问。 是否可以使用Spring Security进行配置? 为了安全起见,我在Java配置类中有以下代码,但它确实不起作用 - 在http://localhost:8080/service/ws?WSDL
访问的Web服务调用和wsdl上强制执行基本身份验证
Spring Security可以根据URL参数进行区分吗? 或者,我可以将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");
}
允许所有在wsdl上应该这样做 -
http
.authorizeRequests()
.antMatchers("/service/ws?wsdl").permitAll()
.antMatchers("/service/**").hasRole("USER").and().httpBasic().and().
csrf().disable();
我最终在下面做了。 显然蚂蚁匹配器不识别任何URL参数所以我使用正则表达式:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().regexMatchers("/service/ws\\?WSDL");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.