Skip to content

Commit

Permalink
javaee-projets - filter jpa
Browse files Browse the repository at this point in the history
  • Loading branch information
ltearno committed Nov 16, 2017
1 parent 17728f2 commit f0a92d9
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public class CategoriesServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

List<Categorie> categories = gestionCategories.findAll();

Map<Integer, Long> nbProduitsParCategorie = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ public class EditionCategorieServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

Categorie categorie = null;

try {
Expand All @@ -45,11 +40,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

Categorie categorie = new Categorie();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public class EditionFabricantServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

Fabricant fabricant = null;

try {
Expand All @@ -47,11 +42,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

Fabricant fabricant = new Fabricant();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public class EditionProduitServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

Produit produit = null;

try {
Expand All @@ -53,11 +48,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

Produit produit = new Produit();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ public class ExportServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

resp.setHeader("Content-disposition", "attachment; filename=" + FILENAME);
resp.setHeader("content-type", "application/xls");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public class FabricantsServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

List<Fabricant> fabricants = gestionFabricants.findAll();

Map<Integer, Long> nbProduitsParFabricant = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public class ImportServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!Session.estConnecte(request)) {
response.sendRedirect("login");
return;
}

String message = importationExcel(request);

Vues.afficherResultatImportation(request, response, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public class LoginServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Vues.afficherLogin(req, resp, "Bienvenue");
if (Session.estConnecte(req))
resp.sendRedirect("produits");
else
Vues.afficherLogin(req, resp, "Bienvenue");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public class ProduitsServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

List<Produit> produits;

String search = req.getParameter("search");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package fr.lteconsulting.training.moviedb.servlet;

import fr.lteconsulting.training.moviedb.outil.Session;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "SecurityFilter", urlPatterns = {
"/produits",
"/editionProduit",
"/suppressionProduit",
"/categories",
"/editionCategorie",
"/suppressionCategorie",
"/fabricants",
"/editionFabricant",
"/suppressionFabricant",
"/export.xls",
"/importation"
})
public class SecurityFilter implements Filter {
public void init(FilterConfig config) throws ServletException {
}

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
if (req instanceof HttpServletRequest && resp instanceof HttpServletResponse) {
if (!Session.estConnecte((HttpServletRequest) req)) {
((HttpServletResponse) resp).sendRedirect("login");
return;
}
}

chain.doFilter(req, resp);
}

public void destroy() {
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.lteconsulting.training.moviedb.servlet;

import fr.lteconsulting.training.moviedb.ejb.GestionCategories;
import fr.lteconsulting.training.moviedb.outil.Session;

import javax.ejb.EJB;
import javax.servlet.ServletException;
Expand All @@ -18,11 +17,6 @@ public class SuppressionCategorieServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

try {
int id = Integer.parseInt(req.getParameter("id"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public class SuppressionFabricantServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

try {
int id = Integer.parseInt(req.getParameter("id"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public class SuppressionProduitServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (!Session.estConnecte(req)) {
resp.sendRedirect("login");
return;
}

try {
int id = Integer.parseInt(req.getParameter("id"));

Expand Down

0 comments on commit f0a92d9

Please sign in to comment.