我试图了解如何使用 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);
}
}
Run Code Online (Sandbox Code Playgroud)
UPD:我昨天没有注意到这一点,我只是查看了应用程序和网络服务 URL,它们是不同的。这是因为 Apache CXF Web 服务单独启动。
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), customerWebService ); …Run Code Online (Sandbox Code Playgroud)