我試圖讓Tuckey UrlRewriteFilter爲我的webapp整理網址。我得到的一個問題是,當spring-security發現匿名用戶試圖訪問受保護資源時,它會重定向到一個包含servlet路徑的URL。重寫彈簧安全重定向URL
我想,通過例如:
> GET http://localhost:8080/my-context/protected-resource
< Location: http://localhost:8080/my-context/login
我目前得到的是:
> GET http://localhost:8080/my-context/protected-resource
< Location: http://localhost:8080/my-context/-/login
相關文件,到目前爲止,我發現:
DefaultRedirectStrategy,這有問題的實際重定向:http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/DefaultRedirectStrategy.html。它有一個contextRelative屬性,這個屬性很誘人,但我不認爲會削減它,如果我甚至可以找到配置它的方法。
一篇博客文章,幫助讓我到這地步:http://nonrepeatable.blogspot.com/2009/11/using-spring-security-with-tuckey.html
我想知道的是:
- 燦/我應該說服Tuckey重寫Location頭。 <出站規則>在這裏似乎沒有幫助。
- 可以/我應該以某種方式調整SS配置以發出重寫的URL。我認爲這不是很整潔,因爲如果重寫被禁用,它會中斷。
web.xml
看起來像
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>LogLevel</param-name>
<param-value>log4j</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>my-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>psms</servlet-name>
<url-pattern>/-/*</url-pattern>
</servlet-mapping>
urlrewrite.xml
樣子:
<urlrewrite>
<rule>
<from>^/(.*)$</from>
<to>/-/$1</to>
</rule>
</urlrewrite>
applicationContent-security.xml
樣子:
<http auto-config="true">
<!-- allow GET requests to /login without authentication -->
<intercept-url pattern="/-/login" method="GET" filters="none"/>
<intercept-url pattern="/-/admin/**" access="ROLE_ADMIN"/>
<intercept-url pattern="/-/**" access="ROLE_USER"/>
<form-login login-page="/-/login"
login-processing-url="/-/login.do"
authentication-failure-url="/-/login?login_error"
default-target-url="/-/index"
always-use-default-target="true"/>
<logout logout-url="/-/logout"
logout-success-url="/-/login"/>
<access-denied-handler error-page="/-/access-denied"/>
</http>
並將登錄頁面屬性設置爲/ login? – rodrigoap 2009-11-20 15:33:37