1

我在将 mod_jk 与 Spring Security 一起使用时遇到了一些问题,这些问题已经在以前的项目中工作过,但我现在似乎无法让它工作。

当我的网络应用程序位于时,我使用 JBoss(但也可以很容易地使用 Tomcat)遇到了一个相当典型的情况,http://hostname/myapp并且我希望它对浏览器隐藏,这样所有访问都将是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. 有没有人有一个可以与我分享的工作配置!

我已经为此苦苦挣扎了几个小时,阅读了很多帖子,但我没有设法让它发挥作用。

4

1 回答 1

0

回答我自己的问题,以便将来可能帮助其他人。我不得不切换到 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 语句。

于 2012-07-25T07:47:58.120 回答