Bonjour,
Je souhaite faire marcher un programme d'authentification dans une application Ecommerce. J'ai un serveur JOnAS qui tourne, un bean d'authentification authBean:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package ecom.beans;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless()
@Remote(AuthBeanInterface.class)
public class AuthBean implements AuthBeanInterface {
@PersistenceContext
private EntityManager entityManager = null;
public boolean authCustomer(String email, String password)
{
CustomerBean cb = entityManager.find(CustomerBean.class, email);
if (cb.password==password){
return true;
} else {
return false;
}
}
} |
avec son interface associée. Avec un bean Entité CustomerBean qui a deux attributs, email et password, qui vont servir d'authentification pour l'utilisateur. Ce sont des String. Puis un bean CustomerBeanCentral qui centralise les méthodes. J'ai donc rajouté dedans un appel vers le bean d'authentification:
1 2 3 4 5
| @Override
public boolean authCustomer(String email, String password) {
AuthBean auth = new AuthBean();
return auth.authCustomer(email, password); } |
Puis un bean shell dans lequel je fais les traitements restants et j'ai un retour dans mon terminal :
1 2 3 4 5 6 7 8 9 10 11 12
| case 7:
System.out.println("Entrez votre email : ");
String email = Tx.readString();
System.out.println("Entrez le mot de passe du compte : ");
String mdp = Tx.readString();
if (CustomerBeanCentral.authCustomer(email,mdp)){
System.out.println("Mot de passe VALIDE");
}
else {
System.out.println("Informations incorrectes !");
} |
J'ai une entrée dans la BD MySQL avec par exemple "david@gmail.com" comme user "david" comme mot de passe.
Quand je rentre les deux dans mon shell j'ai une erreur:
[java] javax.ejb.EJBException: Exception in a business internface with REQUIRED TX attribute....
par contre si je met le code du bean AuthBean dans CustomerBeanCentral tout fonctionne bien!
Avez vous une idée du problème ??
merci
Partager