merveotesi
merveotesi

Reputation: 2183

Spring Security redirect manually(by code,without config)

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?

Upvotes: 0

Views: 308

Answers (1)

Ravi Kadaboina
Ravi Kadaboina

Reputation: 8574

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:

Upvotes: 1

Related Questions