0

Pivotal 3.1 サーバー (ポート 8080 および 8443) で Spring STS を使用しています。ボックスには、80 および 443 で実行される別の tomcat 7 インスタンスもあります。

Spring Boot 1.2.4 リリースを使用しています。

アプリケーションがすべてのリクエストを自動的に https にリダイレクトするようにしたい - 私は組み込みの tomcat インスタンスを使用していません。

以前は春を使用していましたが、web.xml にタグがあり、問題なく動作していました。

スプリングブートを使用して同じことを達成するにはどうすればよいですか?

ありがとう、エイドリアン

4

1 に答える 1

6

Spring Security を使用している場合は、Spring Boot リファレンスsecurity.require_ssl=trueに記載されているように、application.properties に追加することでこれを行うことができます。Spring Security 構成をカスタマイズする場合、次のようなものが必要になります。

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            // ...
            .requiresChannel()
                .anyRequest().requiresSecure();
    }
}

Spring Security を使用しておらず、war ファイルを使用しているため、最も簡単な方法は、以下を含む web.xml を作成することです。

src/main/webapp/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee                       http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>all</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
</web-app>

アプリケーション全体のセキュリティ制約をプログラムで設定する方法がないため、web.xml を使用する必要があります。詳細については、How to programmatically setup a <security-constraint> in Servlets 3.x? を参照してください。

于 2015-08-26T18:20:48.250 に答える