晚的答案,但替代,配置驱动的方法是对各种<sec:intercept-url>
标签使用Spring Security与requires-channel="https"
,连同Tomcat的RemoteIpValve
,它处理相同的代理头(x-forwarded-proto
等等)在先前的答案中提到。该阀根据代理头改变HttpServletRequest.isSecure()
的行为以反映代理报告的协议,而不是连接器实际收到的协议 - 因此,任何依赖isSecure()
执行正确事情的Spring框架在卸载SSL时都会正常运行。
SSL redirects in Heroku有配置与webapp-runner和Heroku一起使用的阀门的说明。
此外,我建议使用PropertyPlaceholderConfigurer
来让环境变得不可胜数。例如,在你的春季安全配置:
<sec:intercept-url pattern="/api/**" requires-channel="${REQUIRES_CHANNEL}" access="..."/>
相关application-config.xml
将包括这样的事情:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="properties" ref="applicationProperties"/>
</bean>
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:/application-config.properties</value>
</list>
</property>
</bean>
的application-config.properties
文件将包括REQUIRES_CHANNEL=http
为默认值,然后在部署到Heroku上,你设置heroku config:set REQUIRES_CHANNEL=https
重写。
request.getPa thInfo()可能会返回'null',导致像这样的字符串:'https://yourdomain.comnull',因此您可能需要在将其附加到重定向URL之前检查它。 – Erik 2015-07-24 20:22:57
根据Erik的评论编辑。我一直在争取这一段时间,而且答案恰好在我的鼻子下!谢谢。 – Andy 2016-06-21 01:16:44