The
credentials component provides both username and password properties, catering for the most common authentication scenario. These properties can be bound directly to the username and password fields on a login form. Once these properties are set, calling identity.login() authenticates the user with the credentials provided. An example of a simple login form is as follows:
<div> <h:outputLabel for="name" value="Username"/> <h:inputText id="name" value="#{credentials.username}"/> </div> <div> <h:outputLabel for="password" value="Password"/> <h:inputSecret id="password" value="#{credentials.password}"/> </div> <div> <h:commandButton value="Login" action="#{identity.login}"/> </div>
Similarly, the user is logged out by calling
#{identity.logout}. This action clears the security state of the currently authenticated user and invalidate the user's session.