Alex Rivera | Logout

Spring Security 3 Get Initially Requested URL

Asked 2011-03-22T09:42:44.100
16

I need to modify my spring security login page based on where the user came from. My client wants the styles different between the two. If you come from appcontextroot/test vs appcontextroot/choose. I tried to do the below but the String url=savedRequest.getRedirectUrl(); is equal to the spring login page already and not the initial page requested by the user. Any ideas?

ExternalContext externalContext = FacesUtils.getExternalContext();
    HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
    HttpSession session = request.getSession(false);
    if(session != null) {
        SavedRequest savedRequest = new DefaultSavedRequest(request, new PortResolverImpl());
        String url=savedRequest.getRedirectUrl();
    } 
Edit
Report

1 Answer

0

I didn't make it work with the solution proposed, here's what i found : (Using spring 3.1).

In your fitler class :

CharsetFilter implements Filter {
    @OVerride public void doFilter(ServletRequest request, ServletResponse response, FilterChain next) throws IOException, ServletException {
        HttpServletRequest hsr = (HttpServletRequest) request;
        if (hsr.getUserPrincipal() == null) {
            HttpSession session = hsr.getSession();
            if (!(hsr == null)) {
                logger.info("path : " + hsr.getPathInfo());
                session.setAttribute("beforeLoginUrl", hsr.getPathInfo());
    }
  }
}

Then i your web.xml declare your filter :

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
    <filter-name>charsetFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>charsetFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
    <filter-name>CharsetFilter</filter-name>
    <filter-class>com.ent.foo.CharsetFilter</filter-class>
    <init-param>
        <param-name>requestEncoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

Then in your redirect url after successful login just get the HttpSession back :

@RequestMapping(value = "successful")
public void showSuccessfulogin (HttpSession session) {
    Str
answered 2012-10-25T14:27:51.277

Your Answer