Search code examples
jsfjakarta-eejava-security

How can I redirect to the original request url with Java EE Security @CustomFormAuthenticationMechanismDefinition


When I use

@FormAuthenticationMechanismDefinition(
        loginToContinue = @LoginToContinue(
                loginPage = "/login.xhtml",
                useForwardToLogin = false))

then, after a successful login, the user gets redirected to the original page they requested.

But I would like some more control over the authentication form, so instead I am using:

@CustomFormAuthenticationMechanismDefinition(
        loginToContinue = @LoginToContinue(
                loginPage = "/login.xhtml",
                useForwardToLogin = false))

I was following this example: https://rieckpil.de/howto-simple-form-based-authentication-for-jsf-2-3-with-java-ee-8-security-api/

But the problem is that now, after successful login, the user is always redirected to index.xhtml instead of to the original page they requested.

Is there a way to achieve the same behavior with a CustomFormAuthenticationMechanismDefinition?


Solution

  • I got it working by adding ajax="false" to my p:commandButton. The Java EE Security Framework was setting the redirect header correctly, but the PrimeFaces p:commandButton ignored it.