Umesh Awasthi
Umesh Awasthi

Reputation: 23587

how spring security save RedirectUrl

I am wondering how spring save the information about from which page user came from as after successful authentication Spring security tend to redirect user to same location from where he/she came from.

I know how to get the information out of Spring security by something like

protected String getRedirectUrl(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if(session != null) {
        SavedRequest savedRequest = (SavedRequest) session.getAttribute(WebAttributes.SAVED_REQUEST);
        if(savedRequest != null) {
            return savedRequest.getRedirectUrl();
        }
    }

    /* return a sane default in case data isn't there */
    return request.getContextPath() + "/";
} 

But i am not using Spring security in my application and i need to implement same functionality for my Application. I was wondering where to look in to details as how Spring handle this

Upvotes: 0

Views: 375

Answers (1)

Japan Trivedi
Japan Trivedi

Reputation: 4483

Look at the documentation for the class org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler. It is responsible to redirect to the same view from where user has come to login page.

Hope this helps you. Cheers.

Upvotes: 1

Related Questions