gpt4 book ai didi

java - Apache/mod_jk 与 Spring Security

转载 作者:行者123 更新时间:2023-12-01 05:14:01 25 4
gpt4 key购买 nike

我在将 mod_jk 与 Spring Security 一起使用时遇到了一些问题,该功能已在以前的项目中运行过,但现在似乎无法使其运行。

当我的 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 /

我的 Spring 安全文件

<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语句。

关于java - Apache/mod_jk 与 Spring Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11579889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com