禁用弹簧安全性https重定向

时间:2018-05-03 09:20:25

标签: java spring tomcat https

我正在开发一个Web应用程序并配置ssl证书以在Tomcat中的https上运行。

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="150" SSLEnabled="true" clientAuth="false" keystoreFile="conf/expchannel.pfx" keystorePass="***" keystoreType="PKCS12">

由于某些原因,客户希望在8080端口上运行它。无所谓。

问题在于Spring安全登录拦截器。一旦获得请求,它会自动重定向到登录页面,但由于未知原因,它使用8443端口,永远不会提供服务(以超时结束)

配置:

<security:http auto-config="true" use-expressions="true">   
    <security:csrf disabled="true"/>
    <!-- Other pages only autenticated  -->
    <security:intercept-url pattern="/pages/userManagement.xhtml" access="hasRole('ROLE_ADMIN')" />
    <security:intercept-url pattern="/pages/performanceMonitoring.xhtml" access="hasRole('ROLE_ADMIN')" />
    <security:intercept-url pattern="/pages/**" access="hasRole('ROLE_USER')" />

    <security:session-management invalid-session-url="/sessionExpired.xhtml">
    </security:session-management>

    <!-- Set the login page and what to do if login fails -->
    <security:form-login login-page="/login.xhtml" authentication-failure-url="/loginFail.xhtml" 
        default-target-url="/pages/statusOverview.xhtml" />
    <security:csrf/>
</security:http>

在7080端口上运行的其他应用程序实例没有这个问题,我想有一些隐藏的默认行为可以从8080完全更改端口 - &gt;在https请求的情况下为8443。

有没有办法禁用此行为?我正在寻找答案,但我没有找到任何答案。我找到的唯一解决方案是在spring配置中明确设置http和https端口,这对我来说似乎不对。我希望它可以在tomcat配置上进行配置,而不是为每个Web应用程序单独配置。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您需要在该连接器上设置secure="true"以及scheme="https"

请注意,使用端口8080进行安全HTTP就像使用端口80获取明文HTTP:surprising

8443来自Tomcat在连接器上的默认redirectPort设置:Tomcat(或可能是Spring)将用户重定向到它认为的&#34; secure& #34;连接器,因为所有登录都应该通过TLS执行。