【发布时间】:2019-10-14 09:36:57
【问题描述】:
我正在开发一个带有 Spring Boot 的 SOAP Web 服务和带有基本身份验证的 Spring Security。身份验证有效,但我想授权匿名用户在许多端点访问。我不知道该怎么做。 我想创建 2 个 wsdl,一个用于具有身份验证的端点,另一个用于没有身份验证的端点。可能吗 ? 否则是否可以使用 @PreAuthorize(permitAll) 之类的东西注释端点或自定义 spring 安全性?
什么是正确的做法以及如何做?
提前致谢。
我试过这个:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "createAuthorRequest")
@ResponsePayload
@PreAuthorize("permitAll()")
public CreateAuthorResponse createAuthor(
@RequestPayload CreateAuthorRequest request
) throws WSException {
return authorService.createAuthor(request);
}
或自定义 spring 安全性:
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.httpBasic()
.and()
.authorizeRequests().antMatchers(HttpMethod.POST, "/ws/createAuthor", "/ws/createAuthorRequest", "/ws/createAuthor**").permitAll()
.antMatchers(HttpMethod.GET, "/ws/createAuthor", "/ws/createAuthorRequest", "/ws/createAuthor**").permitAll()
.antMatchers(HttpMethod.PUT, "/ws/createAuthor", "/ws/createAuthorRequest", "/ws/createAuthor**").permitAll()
.anyRequest().authenticated()
.and()
.csrf().disable().headers().frameOptions().disable();
但它不会改变。使用 SOAP,我不知道如何获取被调用端点的名称。这里是spring security的日志:
2019-05-29 22:49:39.060 INFO 8228 --- [io-8080-exec-10] Spring Security Debugger :
************************************************************
Request received for POST '/ws':
org.apache.catalina.connector.RequestFacade@7445a104
servletPath:/ws
pathInfo:null
headers:
accept-encoding: gzip,deflate
content-type: text/xml;charset=UTF-8
soapaction: ""
content-length: 516
host: localhost:8080
connection: Keep-Alive
user-agent: Apache-HttpClient/4.1.1 (java 1.5)
【问题讨论】:
标签: spring-boot soap spring-security