I am trying to get Tuckey UrlRewriteFilter to clean up the urls for my webapp. One of the problems is that when spring-security notes that an anonymous user is trying to access a protected resource, it redirects a URL that includes the servlet path.
What I want, for example:
> GET http://localhost:8080/my-context/protected-resource < Location: http://localhost:8080/my-context/login
I am currently getting:
> GET http://localhost:8080/my-context/protected-resource < Location: http://localhost:8080/my-context/-/login
Relevant documents I have found so far:
DefaultRedirectStrategy, which does the actual redirect: http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/DefaultRedirectStrategy.html . This one has a contextRelative property that is tempting, but I don't think it will cut it, even if I can find a way to configure it.
Blog post that helped me so far: http://nonrepeatable.blogspot.com/2009/11/using-spring-security-with-tuckey.html
What I would like to know:
- Can / should I convince Tuckey to rewrite the Location header. <outgoing rule> seems to help nothing.
- You can / need to somehow configure the SS configuration to fix the rewritten URL. I do not think this is pretty accurate, as it will break if the rewrite is disabled.
web.xml looks like
<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 as follows:
<urlrewrite> <rule> <from>^/(.*)$</from> <to>/-/$1</to> </rule> </urlrewrite>
applicationContent-security.xml as follows:
<http auto-config="true"> <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>
java spring-mvc spring-security url-rewriting tuckey-urlrewrite-filter
ptomli
source share