Olá a todos.
Estou tentando fazer um login usando JAAS e JSF 2 no servidor Glassfish v3.1.2
Acontece que estou recebendo esse erro:
Não foi possível encontrar um caso de navegação correspondente na ID de exibição '/login.xhtml' para a ação '#{beanLogin.login()}' com o resultado 'error'
Minha página login.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<ui:define name="content">
<p:growl id="growl" showDetail="true" life="3000" />
<div id="formulario">
<p:panel id="pnl" header="Login">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Usuário:" />
<p:inputText value="#{beanLogin.username}"
id="username" required="true" label="username" />
<h:outputLabel for="password" value="Senha:" />
<p:password value="#{beanLogin.password}" feedback="false" minLength="" id="password" label="password" />
<p:commandButton id="loginButton" value="Efetuar Login" update=":growl"
action="#{beanLogin.login()}" ajax="false"/>
<p:commandLink value="Esqueceu a senha?" ></p:commandLink>
</h:panelGrid>
</h:form>
</p:panel>
</div>
</ui:define>
</ui:composition>
Meu BeanLogin:
[code]@Stateless
@Named
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();
try {
request.login(this.username, this.password);
} catch (ServletException e) {
context.addMessage(null, new FacesMessage("Login failed."));
return "error";
}
return "loginAdmin";
}
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]
Meu Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>pages/login.xhtml</welcome-file>
<welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>
<security-constraint>
<display-name>Páginas de Administradores</display-name>
<web-resource-collection>
<web-resource-name>admin</web-resource-name>
<description>admin</description>
<url-pattern>/pages/protected/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>Páginas de Professores</display-name>
<web-resource-collection>
<web-resource-name>professor</web-resource-name>
<description>professor</description>
<url-pattern>/pages/protected/professor/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>professor</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>sonic</realm-name>
<form-login-config>
<form-login-page>/pages/login.xhtml</form-login-page>
<form-error-page>/pages/login.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>professor</role-name>
</security-role>
</web-app>
Meu Persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="Projeto_SonicPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>sonic</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
Meu glassfish-web.xml:
[code]<?xml version="1.0" encoding="UTF-8"?>
/sonic admin admin professor professor Keep a copy of the generated servlet class' java code. [/code]E apesar de normalmente não precisar usar o faces-config.xml no JSF 2, fiz um para ter certeza de que a página seria direcionada…:
[code]<?xml version='1.0' encoding='UTF-8'?>
<navigation-rule>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-action>>#{beanLogin.login()}</from-action>
<from-outcome>loginAdmin</from-outcome>
<to-view-id>/pages/protected/admin/index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
[/code]
O que vocês acham que pode ser?
Obrigado a todos pela ajuda