Login in JSF 2.0 with Glassfish 3.1.2 and JAAS <p>I'm having problems when I try to login with JSF 2. I am getting the following message:</p> <blockquote> <p>WEB9102: Web Login Failed: com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Security Exception</p> </blockquote> <p>This is my login page:</p> <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" template="./modeloLogin.xhtml" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"&gt; &lt;ui:define name="content"&gt; &lt;p:growl id="growl" showDetail="true" life="3000" /&gt; &lt;div id="formulario"&gt; &lt;p:panel id="pnl" header="Login"&gt; &lt;h:form&gt; &lt;h:panelGrid columns="2" cellpadding="5"&gt; &lt;h:outputLabel for="username" value="Usuário:" /&gt; &lt;p:inputText value="#{beanLogin.username}" id="username" required="true" label="username" /&gt; &lt;h:outputLabel for="password" value="Senha:" /&gt; &lt;p:password value="#{beanLogin.password}" feedback="false" minLength="" id="password" label="password" /&gt; &lt;p:commandButton id="loginButton" value="Efetuar Login" update=":growl" action="#{beanLogin.login()}" ajax="false"/&gt; &lt;p:commandLink value="Esqueceu a senha?" &gt;&lt;/p:commandLink&gt; &lt;/h:panelGrid&gt; &lt;/h:form&gt; &lt;/p:panel&gt; &lt;/div&gt; &lt;/ui:define&gt; &lt;/ui:composition&gt; </code></pre> <p>And this is my BeanLogin:</p> <pre><code>/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package sonic.action.login; import java.security.Principal; import javax.ejb.Stateless; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.inject.Named; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; /** * * @author 081315620876 */ @ManagedBean @SessionScoped public class BeanLogin { private String username; private String password; public BeanLogin() { } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String login() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); System.out.println(context == null); System.out.println(request == null); try { request.login(this.username, this.password); if(request.isUserInRole("admin")) { return "/pages/protected/admin/index.xhtml?faces-redirect=true"; } else if(request.isUserInRole("professor")){ return "/pages/protected/professor/index.xhtml?faces-redirect=true"; } } catch (ServletException e) { context.addMessage(null, new FacesMessage("Login failed.")); return "error"; } return "login.xhtml"; } public void logout() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { request.logout(); } catch (ServletException e) { context.addMessage(null, new FacesMessage("Logout failed.")); } } } </code></pre> <p>Thanks in advance for help :)</p>