Home configuring the refer url redirect in spring security
Reply: 0

configuring the refer url redirect in spring security

user2057 Published in May 25, 2018, 11:12 am

I am using Spring Security, and I am trying to redirect to a page after login. If i am logged out, and go to /myurl/home, I am correctly redirected to the login page. but when I login, I am redirected to a default URL, not /myurl/home.

I have created a subclass of SavedRequestAwareAuthenticationSuccessHandler, and what I am trying to do is if there is a refer in the header, go there, otherwise go to a default url that I can set. here is the code:

public class MySuccessRedirectHandler extends SavedRequestAwareAuthenticationSuccessHandler {

static final Logger logger = LoggerFactory.getLogger(MySuccessRedirectHandler.class);

private String defaultRedirectUrl;

public MySuccessRedirectHandler(String defaultRedirectUrl) {
    this.defaultRedirectUrl = defaultRedirectUrl;

public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
    String  url = (String)request.getSession().getAttribute("referer");
    logger.debug("Referer URL from session:"+url);
    if (url == null) {
    } else {

and my config looks like this:

         // now start login info
        .successHandler(new MySuccessRedirectHandler("/home"))
        // now start logoff info
        .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))

However, each time I log in, I get a null for the refer. How do I get the refer URL so I can get this to work?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.381057 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO