Redirect to requested URL after successful login with Pac4j / Shiro

72 Views Asked by At

I´m using Pac4j, Shiro and Keycloak as Auth Provider.

Sometimes the user get a URL and would like to open this URL in my app, but he will be redirected to the login page. Afterwards he should be redirected to the initial requested URL and not the default startpage

For example:

  1. User get URL: http://myapplication.com/portal/userList.jsf
  2. User will be redirect to http://myapplication.com/login.jsf
  3. User will enter his credentials for authentication
  4. User will be redirect to http://myapplication.com/portal/userList.jsf and NOT e.g. default startpage) http://myapplication.com/portal/dashboard.jsf

Before I have used the Form Authentication and call a function in the backend.

In this function I was using the code to get the URL which was initial requested:

final SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(Faces.getRequest());

Faces is from import org.omnifaces.util.Faces;

How can I do this with Pac4j ?

1

There are 1 best solutions below

0
jleleu On

If the originally requested URL is protected, it is saved by pac4j and restored after a successful form authentication.

It really depends on your configuration here. Turn on DEBUG logs on the org.pac4j.core.engine package to see what URL is restored by the DefaultSavedRequestHandler.