【发布时间】:2025-12-06 14:30:02
【问题描述】:
我正在尝试了解如何使用 Spring Security 保护 SOAP Web 服务。我看到DefaultSecurityFilterChain 是用antMatcher() 创建的,但我的网络服务仍然不需要任何凭据。如何使其安全?
我猜测我没有清楚地理解模式,我只是配置错误,但我找不到。
网络服务网址:http://localhost:8080/services/customer
我的配置:
@Configuration
@EnableWebSecurity(debug = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private MyBasicAuthenticationEntryPoint authenticationEntryPoint;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user1").password(passwordEncoder().encode("user1Pass"))
.authorities("ROLE_USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.antMatcher("/services/**")
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic()
.authenticationEntryPoint(authenticationEntryPoint);
http.addFilterAfter(new CustomFilter(),
BasicAuthenticationFilter.class);
}
}
UPD:我昨天没有注意到这个,我只是查看了应用程序和网络服务的 URL,它们是不同的。这是因为 Apache CXF Web 服务是单独启动的。
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), customerWebService );
endpoint.publish("http://localhost:8080/services/customer");
return endpoint;
}
而且我还没有找到任何可能的方法来启动 Web 服务并在应用程序内发布端点。看来这才是重点。
应用程序:http://localhost:8082/AppName/...
网络服务:http://localhost:8080/services/customer
【问题讨论】:
-
您的 CustomFilter 是做什么的?
-
CustomFilter 它只是记录过滤器。我删除了一段时间。
-
我以这篇文章为例,但我坚持使用我的应用程序。谢谢
标签: java spring soap spring-security