2016-11-08 9 views
0

これは私のSpring構成である:Spring SecurityとSSLでいくつかのパスを無視するには?

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 
import org.springframework.security.config.annotation.web.builders.HttpSecurity; 
import org.springframework.security.config.annotation.web.builders.WebSecurity; 
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 
import org.springframework.security.config.http.SessionCreationPolicy; 
import org.springframework.security.core.authority.AuthorityUtils; 
import org.springframework.security.core.userdetails.User; 
import org.springframework.security.core.userdetails.UserDetails; 
import org.springframework.security.core.userdetails.UserDetailsService; 
import org.springframework.security.core.userdetails.UsernameNotFoundException; 

@Configuration 
@EnableWebSecurity 
@EnableGlobalMethodSecurity(prePostEnabled = true) 
public class X509Configuration extends WebSecurityConfigurerAdapter { 

    @Override 
    public void configure(WebSecurity web) throws Exception { 
     web.ignoring().antMatchers("/ws/items.wsdl"); 
    } 

    @Override 
    public void configure(final HttpSecurity http) throws Exception { 
     http 
      .sessionManagement() 
       .sessionCreationPolicy(SessionCreationPolicy.NEVER) 
       .and() 
      .authorizeRequests() 
       .antMatchers("/ws/items.wsdl").permitAll() 
       .and() 
      // require authorization for everything else 
      .authorizeRequests() 
       .anyRequest().authenticated() 
       .and() 
      .x509() 
       .subjectPrincipalRegex("CN=(.*?)(?:,|$)") 
       .userDetailsService(userDetailsService()) 
       .and() 
      .csrf().disable() 

      // configure form login 
      .formLogin().disable() 

      // configure logout 
      .logout().disable(); 
    } 

    @Bean 
    public UserDetailsService userDetailsService() { 
     return new UserDetailsService() { 
      @Override 
      public UserDetails loadUserByUsername(String username) { 
       if (username.equals("cid")) { 
        return new User(username, "", 
         AuthorityUtils 
           .commaSeparatedStringToAuthorityList("ROLE_USER")); 
       } 
       throw new UsernameNotFoundException("User not found!"); 
      } 
     }; 
    } 
} 

これらは、SSLの設定です:

server: 
    port: 8443 
    ssl: 
    enabled: true 
    key-store: 'classpath:keystore.jks' 
    key-store-password: 'changeit' 
    key-password: 'changeit' 
    trust-store: 'classpath:truststore.jks' 
    trust-store-password: 'changeit' 
    client-auth: need 

私が欲しいものは、SSLのために無視するか、すべての私のWSDLのサイトに可能にすることです。 しかし、この設定では動作しません。私は次のエラーを受け取ります:

http https://localhost:8443/ws/items.wsdl http: error: SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645) while doing GET request to URL: https://localhost:8443/ws/items.wsdl

私はcaの署名付き証明書を使いたくありません。 (署名付き証明書で動作します) どうすればいいですか?どのようなオプションがありますか?

+0

いいえ、私はhttpsコネクタしか持っておらず、私のWSDLが安全でないことを許可したいと考えています。動作しない場合は、http://stackoverflow.com/a/36623801/1648825に記載されているように、新しいHTTP接続を開くことができます。 – user1648825

+0

あなたの問題を解決できますか?私は今この状況を正確に持っています。 – ram

答えて

-1

はこれを削除します。

.authorizeRequests() 
       .antMatchers("/ws/items.wsdl").permitAll() 

をWeb構成は、そのパスを無視すると言っている、まだあなたのHTTPセキュリティは、そのパスへのリクエストが認証を通過させるために言っています。

+0

それは役に立ちません。ブラウザで 'localhost:8443が無効なセキュリティ証明書を使用します。証明書は自己署名されているため信頼できません。エラー:SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]証明書の検証に失敗しました(_ssl.c:645):エラーコード:SEC_ERROR_UNKNOWN_ISSUER' とhttp cli: 'http https:// localhost:8443/ws/items.wsdl'' https:// localhost:8443/ws/items.wsdl'というURLにGETリクエストを行います。 – user1648825

関連する問題