我使用Spring Security和Apache代理来开发web应用程序。当使用标准的mod_proxy时,一切正常,但是在切换到AJP代理之后,Spring安全重定向出现了问题。
Apache配置:
<VirtualHost *:80>
ServerName domain.com
ProxyPass / ajp://localhost:8009/Context/
ProxyPassReverse / ajp://localhost:8009/Context/
</VirtualHost>当我调用http://domain.com/login时,我看到了一个登录表单。
当我提交表单时,我会转到http://domain.com/auth并进行身份验证。
然后Spring Security应该重定向到http://domain.com/index,但它会重定向到http://domain.com/Context/index
怎样才能摆脱上下文路径呢?为什么Spring Security到处都要添加它?
Spring Security网站上也有类似的问题,但没有人回答:
http://forum.springsource.org/showthread.php?95141-Why-is-spring-security-including-the-context-path
附注:谷歌没有找到更多与这个问题相关的东西,这似乎很奇怪。我是唯一一个使用Spring Security + AJP的人吗?也许这是一个错误的模式?
解决方案:
<VirtualHost *:80>
ServerName domain.com
RewriteEngine on
RewriteRule ^/Context/(.*)$ /$1 [R=301]
ProxyPass / ajp://localhost:8009/Context/
ProxyPassReverse / ajp://localhost:8009/Context/
</VirtualHost>发布于 2011-05-22 18:45:27
Spring Security是web应用上下文感知的,这意味着它的重定向将始终基于当前的web应用上下文。这是经过设计的,因为您的应用服务器可能正在运行几个不同的web应用程序,这些应用程序不应该相互干扰。
您是否只在服务器上运行此应用程序,并有可能将其部署为Tomcat上的根应用程序(例如,将其放入webapps/ROOT/中)?这将消除您的上下文前缀并解决您的问题。
另一种选择可以是在应用服务器上重写重定向URL,然后将其传递给客户端,例如使用an outbound-rule from org.tuckey's great URLRewriteFilter (类似于mod_rewrite,但用于Java web应用)。当然,你必须在你的web.xml中注意适当的过滤器排序,因为Spring Security也为它的逻辑使用过滤器。
https://stackoverflow.com/questions/6063339
复制相似问题