JSF 2.0 redirect to index.jsf after login
10,941
That's not possible.
If you're on Servlet 3.0 (Tomcat 7 / Glassfish 3 / JBoss 6 / etc), then your best bet is to use programmatic login with HttpServletRequest#login()
instead of a JAAS form.
So, instead of
<form action="j_security_check" method="post">
...
<input type="submit" />
</form>
use
<h:form>
...
<h:commandButton value="Login" action="#{bean.login}" />
</h:form>
with
public String login() {
// ...
request.login(username, password);
// ...
return "index.jsf?faces-redirect=true";
}
See also:
Related videos on Youtube
Author by
mbulau
Updated on June 04, 2022Comments
-
mbulau about 2 years
We have a JSF (2.0) based web application, running on JBoss 6.1. We are using the FORM based authentication with JAAS.
Some of the users adding links like this "admin/editUser.jsf" to their bookmarks. This page don't work correctly if the user access this page directly (without using the navigation within the application).
The question is: is there any way to redirect the user to the index.jsf page after login, independent from the requested url?
-
mbulau over 11 yearsI tried a little but I'm not sure how can I transfer this example to my problem, because of I don't have a method like
public String login(){...}
. And I don't know whichfrom-action
orfrom-outcome
is used after submitting the login form. -
puchmu over 11 yearsI suppose you have some method like public void doLogin(username, password), which authenticates the user. It does something when the authentication successes and something else if it fails. So you could add a boolean that returns true if the login successes, then you could use the navigation rule like <from-outcome>true</from-outcome>
-
BalusC over 11 yearsYou're not answering/explaining at all how to do that with JAAS FORM based authentication.
-
puchmu over 11 yearsIt is quite difficult to explain such things without seeing any code snippet, so i can only give basic overall answers