lesParametres) {
+ int nbLigne = 0;
+ try {
+ PreparedStatement prepStmt;
+ prepStmt = theConnection.prepareStatement(sql);
+ prepStmt.setString(1, (String) lesParametres.get("ztNom"));
+ prepStmt.setString(2, (String) lesParametres.get("ztPrenom"));
+ prepStmt.setString(3, (String) lesParametres.get("ztMail"));
+ prepStmt.setString(4, (String) lesParametres.get("ztLogin"));
+ prepStmt.setString(5, (String) lesParametres.get("ztMdp"));
+ prepStmt.setString(6, (String) lesParametres.get("ztAdresse"));
+ prepStmt.setString(7, (String) lesParametres.get("ztCP"));
+ prepStmt.setString(8, (String) lesParametres.get("ztVille"));
+ prepStmt.setString(9, (String) lesParametres.get("ztBip"));
+ prepStmt.setInt(10, (Integer) lesParametres.get("ldrGrade"));
+ prepStmt.setString(11, (String) lesParametres.get("taObs"));
+ //prepStmt.setDate(12, java.sql.Date.valueOf(java.time.LocalDate.now()));
+ prepStmt.setTimestamp(12, new Timestamp(Calendar.getInstance().getTimeInMillis()));
+ prepStmt.setInt(13, (Integer) lesParametres.get("idC"));
+ prepStmt.setInt(14, (Integer) lesParametres.get("zhIdP"));
+ if (sql.substring(0, 6).equals("INSERT")) {
+ prepStmt.setInt(15, (Integer) lesParametres.get("idStatut"));
+ prepStmt.setInt(16, (Integer) lesParametres.get("idType"));
+ }
+
+ System.out.println(prepStmt);
+ nbLigne = prepStmt.executeUpdate();
+ prepStmt.close();
+ } catch (SQLException ex) {
+ System.out.println("SQLExeption : " + ex.getMessage());
+ System.out.println("SQLState : " + ex.getSQLState());
+ System.out.println("Code erreur : " + ex.getErrorCode());
+ }
+ Pompier lePompierMaj = null;
+ if (nbLigne > 0) {
+ //lePompierMaj = read((Integer) lesParametres.get("idC"), (Integer) lesParametres.get("zhIdP"));
+ }
+ return lePompierMaj;
+ }
+
+ public Pompier read(int idP) {
+ Pompier unPompier = null;
+ try {
+ PreparedStatement prepStmt;
+ String sql = "SELECT * FROM pompier WHERE id=? ";
+
+ prepStmt = theConnection.prepareStatement(sql);
+ prepStmt.setInt(1, idP);
+ ResultSet result = prepStmt.executeQuery();
+ if (result.next()) {
+ CaserneMySQL laCaserneMySQL = new CaserneMySQL();
+ Caserne laCaserne = laCaserneMySQL.read(result.getInt(2));
+ unPompier = constituerLePompier(result, laCaserne);
+ }
+ prepStmt.close();
+ } catch (SQLException ex) {
+ System.out.println("SQLExeption : " + ex.getMessage());
+ System.out.println("SQLState : " + ex.getSQLState());
+ System.out.println("Code erreur : " + ex.getErrorCode());
+ }
+ return unPompier;
+ }
+}
diff --git a/src/java/bean/Caserne.java b/src/java/bean/Caserne.java
new file mode 100644
index 0000000..1f5f2b9
--- /dev/null
+++ b/src/java/bean/Caserne.java
@@ -0,0 +1,101 @@
+/*
+ * bean/Caserne.java
+ */
+package bean;
+
+import java.util.Objects;
+
+/**
+ *
+ * @author Dominique_2
+ */
+public class Caserne {
+ private int id;
+ private String nom;
+ private String adresse;
+ private String tel;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getNom() {
+ return nom;
+ }
+
+ public void setNom(String nom) {
+ this.nom = nom;
+ }
+
+ public String getAdresse() {
+ return adresse;
+ }
+
+ public void setAdresse(String adresse) {
+ this.adresse = adresse;
+ }
+
+ public String getTel() {
+ return tel;
+ }
+
+ public void setTel(String tel) {
+ this.tel = tel;
+ }
+
+
+
+ public Caserne(int cId, String cNom, String cAdresse, String cTel) {
+ this.id = cId;
+ this.nom = cNom;
+ this.adresse = cAdresse;
+ this.tel = cTel;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 17 * hash + this.id;
+ hash = 17 * hash + Objects.hashCode(this.nom);
+ hash = 17 * hash + Objects.hashCode(this.adresse);
+ hash = 17 * hash + Objects.hashCode(this.tel);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Caserne other = (Caserne) obj;
+ if (this.id != other.id) {
+ return false;
+ }
+ if (!Objects.equals(this.nom, other.nom)) {
+ return false;
+ }
+ if (!Objects.equals(this.adresse, other.adresse)) {
+ return false;
+ }
+ if (!Objects.equals(this.tel, other.tel)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Caserne{" + "id=" + id + ", nom=" + nom + ", adresse=" + adresse + ", tel=" + tel + '}';
+ }
+
+}
diff --git a/src/java/bean/Parametre.java b/src/java/bean/Parametre.java
new file mode 100644
index 0000000..0fc4da4
--- /dev/null
+++ b/src/java/bean/Parametre.java
@@ -0,0 +1,71 @@
+/*
+ * bean/Parametre.java
+ */
+package bean;
+
+/**
+ *
+ * @author Dominique_2
+ */
+public class Parametre {
+ private String typParam;
+ private int code;
+ private String valeur;
+
+
+ /**
+ * @return the code
+ */
+ public int getCode() {
+ return code;
+ }
+
+ /**
+ * @param code the code to set
+ */
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ /**
+ * @return the valeur
+ */
+ public String getValeur() {
+ return valeur;
+ }
+
+ /**
+ * @param valeur the valeur to set
+ */
+ public void setValeur(String valeur) {
+ this.valeur = valeur;
+ }
+
+ public Parametre(String typParam, int code, String valeur) {
+ this.typParam = typParam;
+ this.code = code;
+ this.valeur = valeur;
+ }
+
+ /**
+ * @return the typParam
+ */
+ public String getTypParam() {
+ return typParam;
+ }
+
+ /**
+ * @param typParam the typParam to set
+ */
+ public void setTypParam(String typParam) {
+ this.typParam = typParam;
+ }
+
+ @Override
+ public String toString() {
+ return "Parametre{" + "typParam=" + typParam + ", code=" + code + ", valeur=" + valeur + '}';
+ }
+
+
+
+}
diff --git a/src/java/bean/Pompier.java b/src/java/bean/Pompier.java
new file mode 100644
index 0000000..0b245ae
--- /dev/null
+++ b/src/java/bean/Pompier.java
@@ -0,0 +1,223 @@
+/*
+ * bean/Pompier.java
+ */
+package bean;
+
+import java.util.Objects;
+
+/**
+ *
+ * @author Dominique_2
+ */
+public class Pompier {
+ private Caserne laCaserne;
+ private int id;
+ private String nom;
+ private String prenom;
+ private Parametre leStatut;
+ private Parametre leType;
+ private String mail;
+ private String login;
+ private String mdp;
+ private String adresse;
+ private String cp;
+ private String ville;
+ private String bip;
+ private Parametre leGrade;
+ private String commentaire;
+
+ public Caserne getLaCaserne() {
+ return laCaserne;
+ }
+
+ public void setLaCaserne(Caserne laCaserne) {
+ this.laCaserne = laCaserne;
+ }
+
+ public Pompier(Caserne laCaserne, int id, String nom, String prenom, Parametre leStatut, Parametre leType, String mail, String login, String mdp, String adresse, String cp, String ville, String bip, Parametre leGrade, String commentaire) {
+// this.laCaserne = laCaserne;
+// this.pId = pId;
+// this.pNom = pNom;
+// this.pPrenom = pPrenom;
+ this(laCaserne, id, nom, prenom);
+ this.leStatut = leStatut;
+ this.leType = leType;
+ this.mail = mail;
+ this.login = login;
+ this.mdp = mdp;
+ this.adresse = adresse;
+ this.cp = cp;
+ this.ville = ville;
+ this.bip = bip;
+ this.leGrade = leGrade;
+ this.commentaire = commentaire;
+ }
+
+ public Pompier(Caserne laCaserne, int id, String nom, String prenom) {
+ this.laCaserne = laCaserne;
+ this.id = id;
+ this.nom = nom;
+ this.prenom = prenom;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getNom() {
+ return nom;
+ }
+
+ public void setNom(String nom) {
+ this.nom = nom;
+ }
+
+ public String getPrenom() {
+ return prenom;
+ }
+
+ public void setPrenom(String prenom) {
+ this.prenom = prenom;
+ }
+
+ public Parametre getLeStatut() {
+ return leStatut;
+ }
+
+ public void setLeStatut(Parametre leStatut) {
+ this.leStatut = leStatut;
+ }
+
+ public Parametre getLeType() {
+ return leType;
+ }
+
+ public void setLeType(Parametre leType) {
+ this.leType = leType;
+ }
+
+ public String getMail() {
+ return mail;
+ }
+
+ public void setMail(String mail) {
+ this.mail = mail;
+ }
+
+ 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 getAdresse() {
+ return adresse;
+ }
+
+ public void setAdresse(String adresse) {
+ this.adresse = adresse;
+ }
+
+ public String getCp() {
+ return cp;
+ }
+
+ public void setCp(String cp) {
+ this.cp = cp;
+ }
+
+ public String getVille() {
+ return ville;
+ }
+
+ public void setVille(String ville) {
+ this.ville = ville;
+ }
+
+ public String getBip() {
+ return bip;
+ }
+
+ public void setBip(String bip) {
+ this.bip = bip;
+ }
+
+ public Parametre getLeGrade() {
+ return leGrade;
+ }
+
+ public void setLeGrade(Parametre leGrade) {
+ this.leGrade = leGrade;
+ }
+
+ public String getCommentaire() {
+ return commentaire;
+ }
+
+ public void setCommentaire(String commentaire) {
+ this.commentaire = commentaire;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 67 * hash + Objects.hashCode(this.laCaserne);
+ hash = 67 * hash + this.id;
+ hash = 67 * hash + Objects.hashCode(this.nom);
+ hash = 67 * hash + Objects.hashCode(this.prenom);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Pompier other = (Pompier) obj;
+ if (this.id != other.id) {
+ return false;
+ }
+
+ if (!Objects.equals(this.laCaserne, other.laCaserne)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Pompier{" + "laCaserne=" + laCaserne + ", id=" + id + ", nom=" + nom + ", prenom=" + prenom + ", leStatut=" + leStatut + ", leType=" + leType + ", mail=" + mail + ", login=" + login + ", mdp=" + mdp + ", adresse=" + adresse + ", cp=" + cp + ", ville=" + ville + ", bip=" + bip + ", grade=" + leGrade + ", commentaire=" + commentaire + '}';
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+}
diff --git a/src/java/doc/readMe b/src/java/doc/readMe
new file mode 100644
index 0000000..3393280
--- /dev/null
+++ b/src/java/doc/readMe
@@ -0,0 +1,15 @@
+Variables de session :
+ Variables mises en session après authentification (AuthentifForm.java)
+ lePompierConnecte : pompier authentifié
+ lePompier : pompier à afficher dans pompierJSP
+ lesGrades : collection des grades possibles (
+ lesPeriodes : collections des périodes d'affectation possibles (nuit, matin, ...)
+ lesStatuts : collection des statuts (pompier, chef de centre, resp. alertes)
+ lesTypes : collection des types (pompier volontaires, perso médical, perso adm.)
+ lesPompiers : collection des pompiers de la caserne, reseignée uniquement si le pompier connecté est un chef de centre
+ Variables mises en session dans PompierServlet.java)
+ lePompier : pompier à afficher dans pompierJSP
+
+Attributs utilisés entre la servet PompierServlet.java et pompierJSP :
+ page : 2 --> affichage des données du pompier connecté
+ 3 --> affichage des données d'un pompier de la caserne pour le chef de centre
diff --git a/src/java/filter/authentifFilter.java b/src/java/filter/authentifFilter.java
new file mode 100644
index 0000000..44c7283
--- /dev/null
+++ b/src/java/filter/authentifFilter.java
@@ -0,0 +1,229 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Filter.java to edit this template
+ */
+package filter;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import jakarta.servlet.Filter;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.FilterConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.ServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpSession;
+
+/**
+ *
+ * @author domin
+ */
+public class authentifFilter implements Filter {
+
+ private static final boolean debug = true;
+
+ // The filter configuration object we are associated with. If
+ // this value is null, this filter instance is not currently
+ // configured.
+ private FilterConfig filterConfig = null;
+
+ public authentifFilter() {
+ }
+
+ private void doBeforeProcessing(ServletRequest request, ServletResponse response)
+ throws IOException, ServletException {
+ if (debug) {
+ log("authentifFilter:DoBeforeProcessing");
+ }
+
+ // Write code here to process the request and/or response before
+ // the rest of the filter chain is invoked.
+ // For example, a logging filter might log items on the request object,
+ // such as the parameters.
+ /*
+ for (Enumeration en = request.getParameterNames(); en.hasMoreElements(); ) {
+ String name = (String)en.nextElement();
+ String values[] = request.getParameterValues(name);
+ int n = values.length;
+ StringBuffer buf = new StringBuffer();
+ buf.append(name);
+ buf.append("=");
+ for(int i=0; i < n; i++) {
+ buf.append(values[i]);
+ if (i < n-1)
+ buf.append(",");
+ }
+ log(buf.toString());
+ }
+ */
+ }
+
+ private void doAfterProcessing(ServletRequest request, ServletResponse response)
+ throws IOException, ServletException {
+ if (debug) {
+ log("authentifFilter:DoAfterProcessing");
+ }
+
+ // Write code here to process the request and/or response after
+ // the rest of the filter chain is invoked.
+ // For example, a logging filter might log the attributes on the
+ // request object after the request has been processed.
+ /*
+ for (Enumeration en = request.getAttributeNames(); en.hasMoreElements(); ) {
+ String name = (String)en.nextElement();
+ Object value = request.getAttribute(name);
+ log("attribute: " + name + "=" + value.toString());
+
+ }
+ */
+ // For example, a filter might append something to the response.
+ /*
+ PrintWriter respOut = new PrintWriter(response.getWriter());
+ respOut.println("This has been appended by an intrusive filter.");
+ */
+ }
+
+ /**
+ *
+ * @param request The servlet request we are processing
+ * @param response The servlet response we are creating
+ * @param chain The filter chain we are processing
+ *
+ * @exception IOException if an input/output error occurs
+ * @exception ServletException if a servlet error occurs
+ */
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain)
+ throws IOException, ServletException {
+
+ if (debug) {
+ log("authentifFilter:doFilter()");
+ }
+
+ // Cast de l'objet request
+ HttpServletRequest requete = (HttpServletRequest) request;
+ // Pas de filtrage des css, des images, des js
+ String chemin = requete.getRequestURI().substring(requete.getContextPath().length());
+ //System.out.println("Chemin : " + chemin);
+ if (chemin.startsWith("/css") || chemin.startsWith("/images") || chemin.startsWith("/js")) {
+ //System.out.println(" - passage ok");
+ chain.doFilter(request, response);
+ return;
+ }
+// Récupération de la session
+ HttpSession maSession = requete.getSession();
+// Récupération du booléen d'authentification
+ boolean authentificationOK = false;
+ if (maSession.getAttribute("lePompierConnecte") != null) {
+ authentificationOK = true;
+ }
+ //System.out.println("authentificationOK : "+ authentificationOK);
+ if (authentificationOK) {
+ // Poursuite sans problème
+ chain.doFilter(request, response);
+ } else {
+ // retour vers la page d'authentification
+ request.getRequestDispatcher("authentification").forward(request, response);
+ }
+ }
+
+ /**
+ * Return the filter configuration object for this filter.
+ */
+ public FilterConfig getFilterConfig() {
+ return (this.filterConfig);
+ }
+
+ /**
+ * Set the filter configuration object for this filter.
+ *
+ * @param filterConfig The filter configuration object
+ */
+ public void setFilterConfig(FilterConfig filterConfig) {
+ this.filterConfig = filterConfig;
+ }
+
+ /**
+ * Destroy method for this filter
+ */
+ public void destroy() {
+ }
+
+ /**
+ * Init method for this filter
+ */
+ public void init(FilterConfig filterConfig) {
+ this.filterConfig = filterConfig;
+ if (filterConfig != null) {
+ if (debug) {
+ log("authentifFilter:Initializing filter");
+ }
+ }
+ }
+
+ /**
+ * Return a String representation of this object.
+ */
+ @Override
+ public String toString() {
+ if (filterConfig == null) {
+ return ("authentifFilter()");
+ }
+ StringBuffer sb = new StringBuffer("authentifFilter(");
+ sb.append(filterConfig);
+ sb.append(")");
+ return (sb.toString());
+ }
+
+ private void sendProcessingError(Throwable t, ServletResponse response) {
+ String stackTrace = getStackTrace(t);
+
+ if (stackTrace != null && !stackTrace.equals("")) {
+ try {
+ response.setContentType("text/html");
+ PrintStream ps = new PrintStream(response.getOutputStream());
+ PrintWriter pw = new PrintWriter(ps);
+ pw.print("\n
\nError\n\n\n"); //NOI18N
+
+ // PENDING! Localize this for next official release
+ pw.print("The resource did not process correctly
\n\n");
+ pw.print(stackTrace);
+ pw.print("
\n"); //NOI18N
+ pw.close();
+ ps.close();
+ response.getOutputStream().close();
+ } catch (Exception ex) {
+ }
+ } else {
+ try {
+ PrintStream ps = new PrintStream(response.getOutputStream());
+ t.printStackTrace(ps);
+ ps.close();
+ response.getOutputStream().close();
+ } catch (Exception ex) {
+ }
+ }
+ }
+
+ public static String getStackTrace(Throwable t) {
+ String stackTrace = null;
+ try {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ t.printStackTrace(pw);
+ pw.close();
+ sw.close();
+ stackTrace = sw.getBuffer().toString();
+ } catch (Exception ex) {
+ }
+ return stackTrace;
+ }
+
+ public void log(String msg) {
+ filterConfig.getServletContext().log(msg);
+ }
+
+}
diff --git a/src/java/form/AuthentifForm.java b/src/java/form/AuthentifForm.java
new file mode 100644
index 0000000..3ca6f81
--- /dev/null
+++ b/src/java/form/AuthentifForm.java
@@ -0,0 +1,75 @@
+/*
+ * form/authentifForm.java
+ * Controle des données saisie dans le formulaire d'authentification
+ */
+package form;
+
+import bdd.ParamMySQL;
+import bdd.PompierMySQL;
+import bean.Parametre;
+import bean.Pompier;
+import com.sun.net.httpserver.HttpServer;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpSession;
+import java.util.ArrayList;
+import util.CtrlSaisie;
+import util.MD5;
+
+/**
+ *
+ * @author domin
+ */
+public class AuthentifForm {
+ String message;
+ HttpServletRequest request;
+
+ public AuthentifForm(HttpServletRequest request) {
+ this.request = request;
+ }
+
+ public boolean ctrlAuthentif() {
+ request.removeAttribute("message");
+ // Vérification de la présence des zones obligatoires
+ String[] champsObligatoires = {"ztLogin", "ztMDP"};
+ if (!CtrlSaisie.CtrlChampsObligatoires(request, champsObligatoires)) {
+ return false;
+ }
+
+ // Vérification absence de chevron
+ if (!CtrlSaisie.CtrlChevron(request)) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean ctrlBDD() {
+ boolean trouve = false;
+ String login = request.getParameter("ztLogin");
+ String mdp = MD5.encode(request.getParameter("ztMDP"));
+ PompierMySQL pompierMySQL = new PompierMySQL();
+ Pompier lePompier = pompierMySQL.readAuthentif(login, mdp);
+ if (lePompier!= null) {
+ trouve = true;
+ HttpSession maSession = request.getSession();
+ maSession.setAttribute("lePompierConnecte", lePompier);
+ ParamMySQL paramMySQL = new ParamMySQL();
+ ArrayList lesGrades = paramMySQL.readType("grade");
+ maSession.setAttribute("lesGrades", lesGrades);
+ ArrayList lesPeriodes = paramMySQL.readType("tranche");
+ maSession.setAttribute("lesPeriodes", lesPeriodes);
+ ArrayList lesStatuts = paramMySQL.readType("statAgt");
+ maSession.setAttribute("lesStatuts", lesStatuts);
+ ArrayList lesTypes = paramMySQL.readType("typePer");
+ maSession.setAttribute("lesTypes", lesTypes);
+ if (lePompier.getLeStatut().getCode()==2) {
+ // Recherche des pompiers de la caserne
+ ArrayList lesPompiers = pompierMySQL.readLesPompiersCaserne(lePompier.getLaCaserne().getId());
+ maSession.setAttribute("lesPompiers", lesPompiers);
+ }
+ } else {
+ request.setAttribute("message", "Login ou mot de passe erroné");
+ }
+
+ return trouve;
+ }
+}
diff --git a/src/java/servlets/AuthentifServlet.java b/src/java/servlets/AuthentifServlet.java
new file mode 100644
index 0000000..96f463c
--- /dev/null
+++ b/src/java/servlets/AuthentifServlet.java
@@ -0,0 +1,118 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
+ */
+package servlets;
+
+import bean.Pompier;
+import form.AuthentifForm;
+import java.io.IOException;
+import java.io.PrintWriter;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpSession;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author sio
+ */
+@WebServlet(name = "AuthentifServlet", urlPatterns = {"/"})
+public class AuthentifServlet extends HttpServlet {
+
+ /**
+ * Processes requests for both HTTP GET
and POST
+ * methods.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ protected void processRequest(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ response.setContentType("text/html;charset=UTF-8");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("Servlet AuthentifServlet");
+ out.println("");
+ out.println("");
+ out.println("Servlet AuthentifServlet at " + request.getContextPath() + "
");
+ out.println("");
+ out.println("");
+ }
+ }
+
+ //
+ /**
+ * Handles the HTTP GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ //processRequest(request, response);
+ // Suppression des variables de session
+ System.out.println("doGet AuthentifServlet");
+ HttpSession maSession = request.getSession();
+ maSession.removeAttribute("lePompierConnecte");
+ maSession.removeAttribute("lesPompiers");
+ maSession.removeAttribute("lePompier");
+ getServletContext().getRequestDispatcher("/WEB-INF/authentifJSP.jsp").forward(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ //processRequest(request, response);
+ Pompier lePompier = null;
+ int page = 2;
+ AuthentifForm af = new AuthentifForm(request);
+ if (af.ctrlAuthentif() && af.ctrlBDD()) { // Contrôle des zones saisies et contrôle en base de données
+ HttpSession maSession = request.getSession();
+ lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
+ if (lePompier.getLeStatut().getCode()==2) { // Chef de centre
+ ArrayList lesPompiers = (ArrayList ) maSession.getAttribute("lesPompiers");
+ if (lesPompiers.size() > 0) {
+ lePompier = lesPompiers.get(0);
+ page = 3;
+ }
+ }
+ request.setAttribute("page", page);
+ //request.setAttribute("lePompier", lePompier);
+ maSession.setAttribute("lePompier", lePompier);
+ getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response);
+ } else { // Une erreur a été détectée
+ getServletContext().getRequestDispatcher("/WEB-INF/authentifJSP.jsp").forward(request, response);
+ }
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }//
+
+}
diff --git a/src/java/util/CtrlSaisie.java b/src/java/util/CtrlSaisie.java
new file mode 100644
index 0000000..5954849
--- /dev/null
+++ b/src/java/util/CtrlSaisie.java
@@ -0,0 +1,64 @@
+/*
+ * util/CtrlSaisie.java
+ */
+package util;
+
+import jakarta.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.Enumeration;
+
+/**
+ *
+ * @author domin
+ */
+public abstract class CtrlSaisie {
+ /**
+ * Vérifie la présence des champs obligatoires dans les paramètres transmis
+ * @param request
+ * @param champsObligatoires : tableau de chaine de caractères, avec le nom des champs obligatoires
+ * @return booléen
+ */
+ public static boolean CtrlChampsObligatoires(HttpServletRequest request, String[] champsObligatoires) {
+ ArrayList champsPresents = new ArrayList<>(request.getParameterMap().keySet());
+ int i = 0;
+ int nbChampsO = champsObligatoires.length;
+ boolean erreur = false;
+ while (erreur == false && i < nbChampsO && champsPresents.contains(champsObligatoires[i])){
+ String value=request.getParameter(champsObligatoires[i]);
+ if (value.trim().length() > 0) {
+ i++;
+ } else {
+ erreur = true;
+ }
+ }
+ if (i < nbChampsO) {
+ request.setAttribute("message", "Veuillez renseigner toutes les zones obligatoires ("+i+')');
+ }
+ return (i>=nbChampsO);
+ }
+
+ /**
+ * Contrôle si un champ de saisie contient un chevron
+ * @param request
+ * @return 0 sinon, -1 si oui
+ */
+ public static boolean CtrlChevron(HttpServletRequest request) {
+ // Contrôle car "<" dans les zones de texte
+ Enumeration lesNoms = request.getParameterNames();
+ int erreur = 0;
+ //ArrayList parameterNames = new ArrayList(request.getParameterMap().keySet());
+ while (erreur == 0 && lesNoms.hasMoreElements()) {
+ Object paramObjet=lesNoms.nextElement();
+ String param=(String) paramObjet;
+ String value=request.getParameter(param);
+ if (value.contains("<") || value.contains("<")) {
+ String message = "Veuillez recommencer votre saisie, une anomalie sur une zone de saisie a été détectée ";
+ request.setAttribute("message", message);
+ erreur=1;
+ }
+ }
+ return (erreur > 0) ? false : true;
+
+ }
+
+}
diff --git a/src/java/util/MD5.java b/src/java/util/MD5.java
new file mode 100644
index 0000000..cccd368
--- /dev/null
+++ b/src/java/util/MD5.java
@@ -0,0 +1,36 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package util;
+
+/**
+ *
+ * @author sio
+ */
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public abstract class MD5 {
+
+ public static String encode(String uneChaine){
+ MessageDigest md = null;
+ try {
+ md = MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+ md.update(uneChaine.getBytes());
+ byte[] digest = md.digest();
+ //myHash = DatatypeConverter.printHexBinary(digest).toLowerCase();
+ StringBuilder sb = new StringBuilder();
+ for (byte b : digest) {
+ sb.append(String.format("%02x", b));
+ }
+ return sb.toString();
+ }
+}
diff --git a/web/WEB-INF/authentifJSP.jsp b/web/WEB-INF/authentifJSP.jsp
new file mode 100644
index 0000000..e2e951e
--- /dev/null
+++ b/web/WEB-INF/authentifJSP.jsp
@@ -0,0 +1,41 @@
+<%--
+ Document : authentifJSP
+ Created on : 23 oct. 2021, 10:02:18
+ Author : domin
+--%>
+<%@include file= "jspf/debutJSP.jspf" %>
+
+
+ <%@include file= "jspf/header.jspf" %>
+
+
+
+
+
+ <%@include file= "jspf/footer.jspf" %>
+
+
+
+
+
+