【发布时间】:2015-06-10 01:26:15
【问题描述】:
我是 Spring 框架的新手,我已经搜索了与该主题相关的所有可能的 SO 链接,但可以找到任何合适的解决方案。 我有一个在 JBoss Wildfly 上运行的应用程序。它位于 AWS EC2 实例上,该实例位于 Elastic Load Balancer (ELB) 后面。 ELB 中配置了 SSL,因此它只接受来自客户端的 HTTPS 请求,但是我的应用程序服务器仅通过 HTTP 与 ELB 通信。我的应用程序同时使用 Spring MVC 和 Spring Security 进行前端/安全管理。 我的 security-context.xml 文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<context:property-placeholder location="/WEB-INF/config.properties" />
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.etech.security"> </context:component-scan>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="xxx@xxxx.com"
authorities="admin" password="xxxxxxxx" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<security:http use-expressions="true">
<security:intercept-url pattern="/" access="isAuthenticated()" />
<security:intercept-url pattern="/dashboard"
access="isAuthenticated()" />
<security:intercept-url pattern="/resources/**" access="permitAll" />
<security:intercept-url pattern="/login" access="permitAll" />
<security:intercept-url pattern="/**" access="denyAll" />
<security:form-login login-page="/login"
authentication-success-handler-ref="asyncAuthenticationSuccessHandler"
authentication-failure-handler-ref="asyncAuthenticationFailureHandler" />
<security:logout logout-url="/logout" logout-success-url="/" />
</security:http>
<bean id="asyncAuthenticationSuccessHandler"
class="com.etech.security.AsyncAuthenticationSuccessHandler">
<constructor-arg ref="supportMailPassword"></constructor-arg>
</bean>
此设置的问题是,一旦通过身份验证,应用程序就会向客户端返回一个 HTTP 链接,客户端无法访问该链接,因为 ELB 只允许 HTTPS url。如下所示:
Client --HTTPS---> ELB ---HTTP--> AppServer/Application
客户端
但它实际上应该这样做,
Client --HTTPS---> ELB ---HTTP--> AppServer/Application
客户端
什么是正确的方法,我是否需要使用任何类型的过滤器在身份验证/处理后绑定到响应,我可以将响应 URL 更改为 HTTPS?
【问题讨论】:
-
你试过这个解决方案stackoverflow.com/questions/8002272/…吗?
-
我尝试了该解决方案,但由于某种原因,InsecureChannelProcessor 无法从 ELB 检测到“X-Forwarded-Proto”标头,但 SecureChannelProcessor 可以。我绕过了 Insecure 中的标头检查以通过安全通道开始所有流量,但它仍在将 http url 发送回客户端。
标签: java spring spring-mvc spring-security