1
I did the JAAS configuration procedures in my JSF project, when I try to access it shows the information that user and password does not check, but I have already created the user table.
xml context.
<Context path="/FastChoice">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/fastchoice"
connectionName="root" connectionPassword="admin"
userTable="usuario" userNameCol="nome_usuario"
userCredCol="senha" userRoleTable="permissao_usuario"
roleNameCol="nome_permissao"/>
Security class as the log in method
public class SegurancaBean {
private String usuario;
private String senha;
public String logar() {
try {
this.getRequest().login(this.usuario, this.senha);
return "Home?faces-redirect=true";
} catch (ServletException e) {
FacesUtil.adicionarMensagem(FacesMessage.SEVERITY_ERROR,
FacesUtil.getMensagemI18n("username_password_does_not_match"));
return null;
}
}
public String sair() throws ServletException {
this.getRequest().logout();
return "Login?faces-redirect=true";
}
private HttpServletRequest getRequest() {
FacesContext context = FacesContext.getCurrentInstance();
return (HttpServletRequest) context.getExternalContext().getRequest();
}
public String getUsuario() {
return usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
Login.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>#{msg.login}</title>
<h:outputStylesheet library="css" name="sistema.css"/>
</h:head>
<h:body>
<div id="content">
<div style="width: 240px; margin-left: auto; margin-right: auto; margin-top: 150px">
<h1>#{msg.login}</h1>
<h:form id="frm">
<h:messages showDetail="false" showSummary="true"
styleClass="form-messages" errorClass="error"/>
<h:panelGrid columns="2" styleClass="form-grid" style="padding: 10px"
columnClasses="label, campo" id="panel">
<h:outputLabel value="#{msg.username}"/>
<h:inputText value="#{segurancaBean.usuario}" size="20"/>
<h:outputLabel value="#{msg.password}"/>
<h:inputSecret value="#{segurancaBean.senha}" size="20"/>
<h:panelGroup/>
<h:commandButton value="#{msg.login}" action="#{segurancaBean.logar}"/>
</h:panelGrid>
</h:form>
</div>
</div>
</h:body>
The approach I use is to create my own Realm class using JPA. Anyway I suggest an approach where you test JASS first with a simple Servlet and only then integrate with Faces.
– João Paraná
Okay, I’ll look for articles on JPA, because I’ve never used.
– David Filipe
David Filipe, I believe the answer: here may help in understanding your question.
– pss1suporte