2017-08-04 12 views
2

にHTTPをリダイレクトしません。 HTTPS要求にリダイレクトする要求。春のセキュリティは、私がSSL証明書を使用してTomcatの上でアプリケーションを実行し、それが正常に動作しますが、私は任意のHTTPを強制したい、私は春4とTomcat 7</p> <p>を使用してWebアプリケーションを実装していますHTTPS

私は春のセキュリティのために検索し、以下のようにいくつかの設定を追加しました:

@Configuration 
@EnableWebSecurity 
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, proxyTargetClass = true) 
public class CoreSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .antMatcher("/**") 
      .requiresChannel() 
       .anyRequest().requiresSecure(); 
     http 
      .antMatcher("/**") 
      .portMapper() 
       .http(80).mapsTo(443); 
    } 
} 

しかし、それは正常に動作していないようで、何のリダイレクトが春のセキュリティによって行われません。

この設定に問題はありますか?

+0

「http.headers()。httpStrictTransportSecurity()」を追加して、クライアントにHTTPSを使用する必要があることを伝えることができます。 – ngreen

+0

@ngreen Tomcat web.xmlにredirect configを追加しても問題ありません。いずれにしても、助けてくれてありがとう。 –

答えて

1

Steps to Configure SSL on Tomcat and Setup Auto Redirect from HTTP to HTTPSのおかげで、Tomcatのweb.xmlにredirect configを追加すると、Tomcatはリダイレクトします。

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>My Application</web-resource-name> 
     <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
    <user-data-constraint> 
     <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 
関連する問題

 関連する問題