繁体   English   中英

带有Spring Security的Apache / mod_jk

[英]Apache/mod_jk with Spring Security

在以前的项目中使用过带有Spring Security的mod_jk时遇到了一些问题,但现在似乎无法使其正常工作。

当我的Web应用程序位于http://hostname/myapp ,我有一个使用JBoss(但很可能是Tomcat)的典型情况,并且我希望将此内容从浏览器中隐藏起来,以便所有访问都将是http://hostname

在Apache中,我有一些规则:

# Remove double "myapp" in url
RewriteRule ^/myapp/(.*) /$1

# Check to see if content can be served locally - rewrite back if not
RewriteCond /dir/to/static/content -f
RewriteRule ^/(.*) /myapp/$1 [PT]

JkMount /myapp/* loadbalancer

我将Spring Security简化为尽可能简单:

<security:http auto-config="true">
<security:intercept-url pattern="/**" access="ROLE_USER" />
</security:http>

在我的web.xml中

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
 </filter-mapping>

问题是,如果没有Spring安全性(即删除springSecurityFilterChain),它可以正常工作,但是包含它,我会遇到类似

Reason: Authentication method not supported: GET

当我尝试登录时。

我的问题是:

  1. 这是需要配置的Spring Security问题,还是我的Apache不正确?
  2. 有没有人可以与我分享工作配置!

我已经为这个问题苦苦挣扎了好几个小时,阅读了很多帖子,但是我没有设法使其正常工作。

回答我自己的问题,将来可能会帮助其他人。 我不得不切换到mod_proxy,而不是mod_jk。

我的设置看起来像这样

<Proxy>
   Order deny,allow
   Allow from all
</Proxy>

RewriteCond /dir/to/static/content/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*) ajp://127.0.0.1:8009/myapp/$1 [P]
ProxyPassReverse /  http://myurl/myapp/
ProxyPassReverseCookiePath /myapp /

我的春季安全档案

<security:http auto-config="false" use-expressions="true" disable-url-rewriting="true">
   <security:intercept-url pattern="/app/login" access="permitAll" />
   <security:intercept-url pattern="/app/**" access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')" />
   <security:form-login
    login-page="/app/login"
    authentication-failure-url="/app/login?f=1"
    default-target-url="/app/map"/>
   <security:logout logout-url="/app/logout"/>
 </security:http>

我认为关键是ProxyPassReverseCookiePath语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM