tags:

views:

54

answers:

1

http://stackoverflow.com/questions/2206911/best-way-for-user-authentication-on-javaee-6-using-jsf-2-0

I tried this solution. But if i put this to my config

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>sql</realm-name>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/index.xhtml</form-error-page>
    </form-login-config>
</login-config>

instead of

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>sql</realm-name>
</login-config>

the login popup of basic auth doesn't show up anymore.. which was what i aspected. But the Login Page which then comes has no Inputfields.. none of the faclet code had been executed. how could that be?

my login.xhtml code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"&gt;

    <h:head>
        <title>Login</title>
    </h:head>
    <h:body>

        <form action="j_security_check" method="post">
            <h:outputLabel for="j_username">Username:</h:outputLabel>
            <h:inputText id="j_username" required="true" />
            <h:message for="j_username" />
            <br />
            <h:outputLabel for="j_password">Password:</h:outputLabel>
            <h:inputSecret id="j_password" required="true" />
            <h:message for="j_password" />
            <br />
            <h:commandButton value="Login" />
        </form>
    </h:body>
</html>

Thats all what is displayed

Username:
Password:
+1  A: 

In other words, the FacesServlet is not been invoked. As another evidence, rightclick page in browser, choose View source and you'll see that JSF tags are not been processed. The FacesServlet is the one responsible for that.

You need to change the URL of the login page to match the url-pattern of the FacesServlet. If that is for example *.jsf, then update as follows:

<form-login-page>/login.jsf</form-login-page>
BalusC
Okay it was <form-login-page>/faces/login.xhtml</form-login-page>Thanks you pushed me in the right direction.. I forgt the Faces Servlet which autmaticly maps all Faclets! Thanks!
Markus
You're welcome. You can alternatively also map the `FacesServlet` on `*.xhtml`, then you have never to worry about this all.
BalusC
i thougth this mapping is on a virtual directory ?? <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> would work?
Markus
Well, it's just the `url-pattern` on which the servlet should kick in. The servlet itself will determine the final XHTML resource based on its own `url-pattern` and the request URL.
BalusC