[英]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.