我正在开发一个 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 端口上运行的另一个应用程序实例没有这个问题,我猜有某种隐藏的默认行为在 https 请求的情况下从 8080 -> 8443 准确地更改端口。
有没有办法禁止这种行为?我一直在寻找答案,但我没有找到任何答案。我找到的唯一解决方案是在 spring 配置中显式设置 http 和 https 端口,这对我来说似乎不正确。我希望它可以在 tomcat 配置上配置,而不是针对每个 Web 应用程序单独配置。
感谢您的帮助。
最佳答案
您需要在该连接器上设置 secure="true"
以及 scheme="https"
。
请注意,将端口 8080
用于安全 HTTP 就像将端口 80
用于纯文本 HTTP:surprising .
值 8443
来自 Tomcat 在连接器上的默认 redirectPort
设置:Tomcat(或可能是 Spring)正在将用户重定向到它认为的“安全”端口连接器,因为所有登录都应通过 TLS 执行。
关于java - 禁用 spring security https 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50151359/