3

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
  • 359
  • 1
  • 7
  • 19

2 Answers2

6

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
-1

You can use a navigation rule, which redirects the user after submitting the login form, Here is an example of this: http://www.mkyong.com/jsf2/jsf-form-action-navigation-rule-example/

puchmu
  • 109
  • 11
  • I 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 which `from-action` or `from-outcome` is used after submitting the login form. – mbulau Feb 28 '13 at 12:24
  • I 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 true – puchmu Feb 28 '13 at 12:50
  • You're not answering/explaining at all how to do that with JAAS FORM based authentication. – BalusC Feb 28 '13 at 13:05
  • It is quite difficult to explain such things without seeing any code snippet, so i can only give basic overall answers – puchmu Feb 28 '13 at 13:09