【问题标题】:Redirect HTTP to HTTPS in Spring Security or Tomcat在 Spring Security 或 Tomcat 中将 HTTP 重定向到 HTTPS
【发布时间】:2013-06-12 03:25:35
【问题描述】:

目前我的 Spring 应用程序只接受 HTTPS 协议的请求。以下是security-context.xml的一部分

<http auto-config="false" use-expressions="true"
        disable-url-rewriting="true">
        <intercept-url pattern="/signup*" access="permitAll"
            requires-channel="https" />
        <intercept-url pattern="/login*" access="permitAll"
            requires-channel="https" />
        <intercept-url pattern="/logout" access="permitAll"
            requires-channel="https" />
        <form-login authentication-success-handler-ref="myAuthenticationSuccessHandler"
            login-page="/login" authentication-failure-url="/loginFailed" />
        <intercept-url pattern="/**" access="isFullyAuthenticated()"
            requires-channel="https" />
        <session-management
            session-authentication-error-url="/loginFailed">
            <concurrency-control error-if-maximum-exceeded="true"
                max-sessions="2" />
        </session-management>
        <logout invalidate-session="true" delete-cookies="JSESSIONID" />
    </http>

现在,我还希望应用程序能够在用户访问域时将 HTTP GET 请求重定向到 HTTPS,例如从 http://mydomain.comhttps://mydomain.com。我怎样才能做到这一点?我应该在 security-context.xml、控制器还是 Tomcat 本身中应用更改?

【问题讨论】:

    标签: tomcat spring-mvc


    【解决方案1】:

    我在server.xml 中配置了从 HTTP(端口 80)到 HTTPS(端口 443)的重定向

    <Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="443"/>
    

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 2014-12-13
      • 1970-01-01
      • 2012-05-10
      • 2015-04-05
      • 1970-01-01
      • 2018-08-09
      • 2014-12-26
      • 2018-01-07
      相关资源
      最近更新 更多