Bonjour les ami(e)s
Je suis en train de developper une application JEE utilisant Glassfish.
Je tente de créer une page JSF d'authentification.
Au niveau du controlleur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 <h:form id="formLogin" prependId="false"> <!-- Form --> <div > <h:form> User Name <p:inputText id="j_username" label="User Name" value="#{authentificationCtrl.loginu}" required="true" style=" width: 96%;" /> Password <h:inputSecret id="j_password" label="Password" value="#{authentificationCtrl.passwordu}" required="true" style=" width: 96%;" /> </h:form> </div> <div class="buttons"> <p:commandButton type="submit" id="login" action="#{authentificationCtrl.doIdentify}" value="Login" icon="ui-icon-person" /> </div> </h:form>
au niveau de CommonServices
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 @EJB CommonServices cs = new CommonServices(); User indentifiedUser ; String loginu; String passwordu; //+ getter +setter public void doIdentify() throws IOException { String s; indentifiedUser = new User(); indentifiedUser.setUsername(loginu); indentifiedUser.setPassword(passwordu); indentifiedUser = cs.authentificate(indentifiedUser); switch (indentifiedUser.getRole().getId()) { case 1: s = "/folder1/folder2/startingTestView.xhtml" ; FacesContext.getCurrentInstance().getExternalContext().redirect(s); // la page de l'administrateur break; case 2: //la page de l'operateur s = "/folder1/folder2/operatorCheckView.xhtml?faces-redirect=true"; FacesContext.getCurrentInstance().getExternalContext().redirect(s); break; default: s = "/index.xhtml?faces-redirect=true"; FacesContext.getCurrentInstance().getExternalContext().redirect(s); break; } }
Finalement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 public User authentificate(User user ){ user=new User(); return u.authentificateUser(user.getUsername(), user.getPassword());}
J'aime bien savoir quelle est l'origine de ces avertissements?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public User authentificateUser(String loginu, String passwordu){ try { Query q = em.createQuery("SELECT u FROM User u WHERE u.username = :loginu AND u.password = :passwordu"); q.setParameter("username", loginu); q.setParameter("password", passwordu); return (User) q.getSingleResult(); } catch (NoResultException e) { System.out.println("Cet utilisateur n'existe pas."); return null; } }
Merci pour vos réponses
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Avertissement: A system exception occurred during an invocation on EJB UserModule, method: public com.XXX.YYY.common.model.User com.XXX.YYY.common.services.UserModule.authentificateUser(java.lang.String,java.lang.String) Avertissement: javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean --- Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of username that does not exist in the query string SELECT u FROM User u WHERE u.username = :loginu AND u.password = :passwordu. --- Avertissement: A system exception occurred during an invocation on EJB CommonServices, method: public com.XXX.YYY.common.model.User com.XXX.YYY.common.services.CommonServices.authentificate(com.XXX.YYY.common.model.User) Avertissement: javax.ejb.EJBTransactionRolledbackException
Partager