【发布时间】:2017-03-05 21:23:04
【问题描述】:
我有带有 Spring WS 的 SOAP 模拟服务。我正在尝试添加基本的http auth。我使用这种网络服务配置:
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
return new ServletRegistrationBean(servlet);
}
@Bean(name = "cards")
public Wsdl11Definition wsdlDefinition() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("cards.wsdl"));
return wsdl11Definition;
}
}
还有这个spring-security的配置:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and().httpBasic()
.and().authorizeRequests().antMatchers("*.wsdl").permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
但是当我运行 spring-boot 并向服务发送请求时,即使没有身份验证,它也会返回响应。我配置错了什么?
更新: 此外,如果我运行 spring-boot 并对配置进行以下更改:
//@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
//@Bean
//public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
// MessageDispatcherServlet servlet = new MessageDispatcherServlet();
// servlet.setApplicationContext(applicationContext);
// return new ServletRegistrationBean(servlet);
//}
@Bean(name = "cards")
public Wsdl11Definition wsdlDefinition() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("cards.wsdl"));
return wsdl11Definition;
}
}
它工作正常(需要对请求进行身份验证),但 url 映射更改为 [/services/*],这对我来说不是所需的映射。 抱歉,我是 Spring 新手。
【问题讨论】:
-
模拟服务如何?你是如何使用这个的......你的安全设置也是错误的,因为你的
*.wsdl将被覆盖,因为之前的声明是你需要对所有东西都安全。 (订购很重要)。 -
我的意思是像this example中的肥皂服务。
-
还有什么不起作用,你在测试什么(你是如何测试的)以及加载的方式。您只是转储一些配置并期望得到帮助,但您的问题中的信息太少。
-
我在 Soap UI 和 postman 中进行了测试。 Here is code 的项目。
-
在soap ui中我用我的cards.wsdl创建了新的SOAP项目。我向没有身份验证标头的服务发送请求,而不是错误说我未通过身份验证,而是返回正确的响应。
标签: java spring web-services soap spring-boot