0

I run a code for login like:

public String login(String username,String password){
    Authentication request = new UsernamePasswordAuthenticationToken(username,password);
                Authentication result = authenticationManager.authenticate(request);
                SecurityContextHolder.getContext().setAuthentication(result);
return null;
                }

I do not use jsf and do not know how to redirect the page to requested secured page after successful login.

I was getting facesContext when using it but now i am not using.

How can redirect by code?

merveotesi
  • 2,145
  • 15
  • 53
  • 84

1 Answers1

1

Just return the view after checking for isAuthenticated(), like this:

 if (authenticationResponseToken.isAuthenticated()) {
            //lookup authentication success url, or find redirect parameter from login bean
            return "/secure/examples";
 }

See also:

Community
  • 1
  • 1
Ravi Kadaboina
  • 8,494
  • 3
  • 30
  • 42