2016-10-24 13 views
2

私はSpring WSでSOAPモックサービスを利用しています。私は基本的なHTTP認証を追加しようとしています。Spring-Boot WS Soapサービスで基本認証が機能しない

@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; 
} 
} 

と春-セキュリティのこの構成:私はこのウェブ・サービスの構成を使用して、私は春ブートを実行し、サービスに要求を送信する際

@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"); 
} 

をしかし、それも、認証なしで応答を返します。私が間違って設定したことは?ありません

//@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マッピングの変更:

UPD:私は、設定を次のように変更して、スプリング・ブートを実行する場合 はまた、私のための望ましいマッピング。 申し訳ありませんが、私は春の初心者です。 @deniumが注文を指摘

として

+1

これはモックサービスですか?どのようにこれを使用していますか?あなたのセキュリティ設定は間違っています。すべてのセキュリティを必要とする前のステートメントで、あなたの '* .wsdl'が上書きされます。 (注文事項)。 –

+0

私はそれが[この例](https://spring.io/guides/gs/producing-web-service/)のような石鹸サービスであることを意味します。 – ipatina

+1

また、動作していないもの、何をテストしています(どのようにテストしていますか)、どのように物事が読み込まれていますか。いくつかの設定だけをダンプして助けが必要ですが、あなたの質問には情報が少なすぎます。 –

答えて

1

試みは、

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.csrf().disable() 
     .antMatchers("*.wsdl").permitAll() 
     .anyRequest().authenticated().hasRole("USER") 
     .and().httpBasic(); 

} 
1

私はちょうど同じ問題を経て、私の解決策がある重要。 コード内のpermitAll()はすでに認証されたユーザーに適用されますので、configure(WebSecurity web)メソッドを使用して無視リストにURLを追加する必要があります。 そしてアルスー私は「*の.wsdl」のためにフィルタリングすることはenoughtではないと思われる、私は「/**/*.wsdl」を使用

私の作業WebSecurityConfigクラスがあり

public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

//Enforce basic auth 
@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.csrf().disable() 
     .httpBasic() 
     .and().authorizeRequests().anyRequest().authenticated(); 
} 

//Ignore basic auth for WSDL URL 
@Override 
public void configure(WebSecurity web) throws Exception { 
    web.ignoring().antMatchers("/**/*.wsdl"); 
} 

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
    //TODO - do parametru 
    auth.inMemoryAuthentication().withUser("user").password("password").roles("USER"); 
} 
0

はちょうどこのコードをコピー&ペーストあなたの "WebServiceConfig"クラス

@Bean 
    public SimplePasswordValidationCallbackHandler securityCallbackHandler() { 
       SimplePasswordValidationCallbackHandler callbackHandler = new SimplePasswordValidationCallbackHandler(); 
       Properties users = new Properties(); 
       users.setProperty("AAA", "BBB"); 
       callbackHandler.setUsers(users); 
       return callbackHandler; 
      } 

      @Bean 
      public Wss4jSecurityInterceptor securityInterceptor() { 
       Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor(); 
       securityInterceptor.setValidationActions("UsernameToken"); 
       securityInterceptor.setSecurementMustUnderstand(true); 
       securityInterceptor.setSecurementUsername("setusername"); 
       securityInterceptor.setSecurementPassword("setpassword"); 
       securityInterceptor.setValidationCallbackHandler(securityCallbackHandler()); 
       return securityInterceptor; 
      } 

      @Override 
      public void addInterceptors(List interceptors) { 
       interceptors.add(securityInterceptor()); 
      } 
関連する問題