java - 为什么在 https 中要加上 Spring Security 的 80 端口?

标签 java tomcat spring-security

登录时,我的应用程序从 443 重定向到 80: 原始网址为 https://myhost.com/myapp/login.jsp 但是当我提交 URL 时 https://myhost.com/myapp/j_spring_security_check 被调用,并且在登录成功时,尝试连接到 https://myhost.com:80/myapp/

URL https://myhost.com/myapp/login.jsp 调用 apache 服务器。 这个 apache 调用了一个带有 http(端口 11080)的 tomcat。

登录操作由具有该配置的 Spring Security 处理:

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd">
    <global-method-security secured-annotations="enabled">
    </global-method-security>
    <http auto-config="true">
        <intercept-url pattern="/faces/secure/**" access="ROLE_ADMIN" />
        <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1"/>
        <logout logout-success-url="/index.jsp"/>
        <concurrent-session-control max-sessions="1" exception-if-maximum-exceeded="true"/>
    </http>
    <authentication-provider>
        <jdbc-user-service data-source-ref="dataSource"/>
    </authentication-provider>
</beans:beans>

这个问题只出现在登录和注销操作上,所以我认为是 Spring Security 的问题。

一切正常,当原始 URL 不使用默认 https 端口 443 时没有重定向:https://myhost.com:12345/myapp/login.jsp

当 apache 使用协议(protocol) ajp 调用 Tomcat 时,一切都正常。

不幸的是,我必须在端口 443 上调用 apache 并使用协议(protocol) http 调用 Tomcat。

线程 Spring Security Https Wrong Port几乎是我的问题,除了我不使用 https 调用 Tomcat,而是使用 http。

我的 Tomcat 连接器配置是:

<Connector port="11080" maxHttpHeaderSize="8192"
           maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
           enableLookups="false" redirectPort="8443" acceptCount="100"
           connectionTimeout="20000" disableUploadTimeout="true" />

<Connector port="11009" 
           enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

最佳答案

接受的答案是建议依赖于 Microsoft 特定 header (Front-End-Https) 的自定义阀。相反,您应该使用已经提供的 RemoteIpValve并依赖于事实上的标准 x-forwarded-proto header 。

AJP 代理无需额外工作的原因是它是一个二进制协议(protocol),因此在 Web 服务器/负载平衡器和 Tomcat 之间没有 HTTP 调用,因此没有架构/端口更改问题。

关于java - 为什么在 https 中要加上 Spring Security 的 80 端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8807478/

相关文章:

java - 检索 JTextField 文本值

amazon-web-services - 从浏览器访问 apache tomcat 服务器

tomcat - 在 tomcat 8 上部署地理服务器

java - 如何为多个 servlet 配置 spring security?

java - 在不作为 Windows 服务运行的情况下为 JSP 运行网络服务器

java - 为什么我无法捕获 java.net.SocketTimeoutException?

web-services - 如何使用网络服务创建树?

spring - 如何配置 "health"Actuator 端点以使用 token 身份验证?

java - Spring-Security:MySQL JDBC 身份验证失败

java - 构造函数无法区分同一基本类型的多次出现