Proxy_pass因Spring安全性而失败

时间:2013-01-16 10:11:52

标签: apache mod-rewrite spring-security proxypass

我已经编写了一组重定向规则

http://server.com/application/c/<UserIdValue>

的类型

http://localserver.com/application/?userid=<UserIdValue>

我在apache httpd.conf中写了以下规则

<Location  /application>
  ProxyPassReverse http://server.com/application/ 
  RewriteEngine On

  RewriteCond %{REQUEST_URI} /c/ [NC]
  RewriteRule application/c/(.*)$ http://localserver.com/application/?userid=$1 [QSA,P]

有了这个,我可以访问我的应用程序中的登录页面和其他页面,但是当我尝试在应用程序中登录/注销时,它会进入&#39; localserver&#39;位置。

问题在于弹簧安全 j_spring_security_check, j_spring_security_logout 。我不知道该怎么办。

Spring安全性优先于代理传递!!!!!

1 个答案:

答案 0 :(得分:1)

要使其发挥作用,您需要更改两件事:

  1. 将您的ProxyPass / ProxyPassReverse行更改为不以尾随/.
  2. 结尾
  3. 告诉您的Application Server正确设置contextURL(ProxyPassReverse不会为您更改表单上的URI)。如果您使用的是Tomcat,可以通过编辑conf / server.xml,找到其上包含属性protocol =“HTTP / 1.1”的标记,并添加两个新属性来实现:proxyHost =“localserver.com”proxyPort =“ 80“(如果localserver.com和server.com在同一个端口上运行,则不需要proxyPort =”80“。)
  4. 问题1的原因是Spring Security没有规范化URI,因此如果代理为应用服务器提供了http://server.com/application//j_spring_security_check之类的URI,则Spring Security拦截器会将其与http://server.com/application/j_spring_security_check进行匹配,注意由于额外的斜线,它是不同的,并拒绝拦截请求。