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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
   | package ma.eCommerce.action;
 
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import javax.naming.*;
 
import ma.eCommerce.modele.Produit;
import ma.eCommerce.services.pub.IProduitServices;
 
public class Authentification {
 
	private String login;
	private String mdp;
	private String variableDeTest;
 
	public Authentification() {
		super();
	}
 
	public String getLogin() {
		return login;
	}
 
	public void setLogin(String login) {
		this.login = login;
	}
 
	public String getMdp() {
		return mdp;
	}
 
	public void setMdp(String mdp) {
		this.mdp = mdp;
	}
 
	public String execute() {
		if (login.equalsIgnoreCase("admin")) {
			try {
				Hashtable<String, String> env = new Hashtable<String, String>();
				env.put("java.naming.factory.initial",
						"org.jnp.interfaces.NamingContextFactory");
				env.put("java.naming.factory.url.pkgs",
						"org.jboss.naming:org.jnp.interfaces");
				env.put("java.naming.provider.url", "127.0.0.1:1099");
 
				Context context = new InitialContext(env);
				IProduitServices PS = (IProduitServices) context
						.lookup("ProduitServicesImpl/remote");
 
				List<Produit> produits = PS.listerTousLesProduits();
				for (Iterator<Produit> it = produits.iterator(); it.hasNext();) {
					Produit pdt = (Produit) it.next();
					this.login = pdt.getCode();
					this.mdp = pdt.getCode();
					this.variableDeTest = pdt.getCode();
				}
			} catch (javax.naming.NamingException e) {
				this.variableDeTest = "javax.naming.NamingException";
			} catch (Exception e) {
				this.variableDeTest = "Autre Exception";
			}
			return "SUCCESS";
		}
		return "ECHEC";
	}
 
	public void setVariableDeTest(String variableDeTest) {
		this.variableDeTest = variableDeTest;
	}
 
	public String getVariableDeTest() {
		return variableDeTest;
	}
 
} | 
Partager