diff --git a/si-war/nbproject/faces-config.NavData b/si-war/nbproject/faces-config.NavData new file mode 100644 index 0000000..187ec92 --- /dev/null +++ b/si-war/nbproject/faces-config.NavData @@ -0,0 +1,6 @@ + + + + + + diff --git a/si-war/src/java/hola/seguridad/AutorizacionListener.java b/si-war/src/java/hola/seguridad/AutorizacionListener.java new file mode 100644 index 0000000..ccb8bb1 --- /dev/null +++ b/si-war/src/java/hola/seguridad/AutorizacionListener.java @@ -0,0 +1,62 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template + */ +package hola.seguridad; + +import java.io.IOException; +import javax.inject.Named; +import javax.enterprise.context.SessionScoped; +import javax.faces.application.NavigationHandler; +import javax.faces.context.FacesContext; +import javax.faces.event.PhaseEvent; +import javax.faces.event.PhaseId; +import javax.faces.event.PhaseListener; + +/** + * + * @author Josue + */ +@Named(value = "autorizacionListener") +@SessionScoped +public class AutorizacionListener implements PhaseListener { + + /** + * Creates a new instance of AutorizacionListener + */ + public AutorizacionListener() { + } + + + private static final long serialVersionUID = 1L; + + @Override + public void afterPhase(PhaseEvent event) { + try { + //Obtener la pagina actual para validar la sesion + String paginaActual = event.getFacesContext().getViewRoot().getViewId(); + + //inicializar la sesion en caso de no haber sesion + DemoBeanLogin.getSession(); + + //Revisar que no sea la pafina index y que no estes logueado + //para redireccionar + if (!paginaActual.contains("index.xhtml") && DemoBeanLogin.getEstatus() == false) { + FacesContext.getCurrentInstance().getExternalContext().redirect("faces/index.xhtml?faces-redirect=true"); + + NavigationHandler nh = event.getFacesContext().getApplication().getNavigationHandler(); + nh.handleNavigation(event.getFacesContext(), null, "index"); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void beforePhase(PhaseEvent event) {} + + @Override + public PhaseId getPhaseId() { + return PhaseId.RESTORE_VIEW; + } +} diff --git a/si-war/src/java/hola/seguridad/DemoBeanLogin.java b/si-war/src/java/hola/seguridad/DemoBeanLogin.java new file mode 100644 index 0000000..747f027 --- /dev/null +++ b/si-war/src/java/hola/seguridad/DemoBeanLogin.java @@ -0,0 +1,138 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template + */ +package hola.seguridad; + +import hola.BL.LoginBLLocal; +import hola.modelo.Usuario; +import hola.msg.Mensaje; +import static hola.msg.Mensaje.CAMPOS_INCOMPLETOS; +import static hola.msg.Mensaje.DATOS_INCORRECTOS; +import static hola.msg.Mensaje.ELEMENTO_DUPLICADO; +import static hola.msg.Mensaje.SIN_ERROR; +import javax.inject.Named; +import javax.enterprise.context.SessionScoped; +import java.io.Serializable; +import javax.ejb.EJB; +import javax.faces.context.FacesContext; +import javax.servlet.http.HttpSession; + +/** + * + * @author Josue + */ +@Named(value = "demoBeanLogin") +@SessionScoped +public class DemoBeanLogin implements Serializable { + + @EJB + private LoginBLLocal loginBL; + private String rol; + + private boolean permisos =false ; + + //variable para manejar la sesion + public static HttpSession httpSession; + + /** + * Creates a new instance of DemoBeanLogin + */ + public DemoBeanLogin() { + + + } + + public String getRol() { + return rol; + } + + public void setRol(String rol) { + this.rol = rol; + } + + public boolean isPermisos() { + return permisos; + } + + public void setPermisos(boolean permisos) { + this.permisos = permisos; + } + + + private Usuario usuarios = new Usuario(); + private static String http = "caba"; + + public Usuario getUsuarios() { + return usuarios; + } + + public void setUsuarios(Usuario usuarios) { + this.usuarios = usuarios; + } + + + + public static void getSession() { + httpSession = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false); + } + + public String logout() { + //quitar atributo + //invalidar la session + System.out.println(http); + httpSession.removeAttribute(http); + httpSession.invalidate(); + return "index.xhtml"; + } + + public String login() { + //BL de autenticacion de usuario + //poner atributo + + Mensaje mensaje = loginBL.login(usuarios); + + switch (mensaje) { + case SIN_ERROR: + rol = loginBL.rol(usuarios); + System.out.println(rol); + httpSession.setAttribute(http, "true"); + usuarios = new Usuario(); + return "Producto.xhtml"; + case ELEMENTO_DUPLICADO: + return null; + case CAMPOS_INCOMPLETOS: + return null; + case DATOS_INCORRECTOS: + return null; + default: + return null; + } + } + + public static boolean getEstatus() { + if (httpSession != null + && httpSession.getId() != null + && !httpSession.getId().isEmpty() + && httpSession.getAttribute("caba") != null) { + return true; + } else { + return false; + } + } + public void permiso() { + switch (rol) { + case "admin": + permisos = true; + break; + case "capturista": + permisos = false; + break; + case "usuario": + permisos = false; + break; + default: + throw new AssertionError(); + } + } +} diff --git a/si-war/src/java/hola/vista/DemoBeanUsuario.java b/si-war/src/java/hola/vista/DemoBeanUsuario.java index 62e79fa..0533505 100644 --- a/si-war/src/java/hola/vista/DemoBeanUsuario.java +++ b/si-war/src/java/hola/vista/DemoBeanUsuario.java @@ -6,7 +6,6 @@ package hola.vista; import hola.BL.UsuarioBLLocal; import hola.modelo.Usuario; -import hola.msg.Mensaje; import javax.inject.Named; import javax.enterprise.context.SessionScoped; import java.io.Serializable; @@ -61,24 +60,9 @@ public class DemoBeanUsuario implements Serializable { public String agregarUsuario() { usuario.setStatus(1); - usuarioBL.agregar(usuario); + usuarioBL.agregar(usuario); // limpiarFormulario(); - Mensaje mensaje = usuarioBL.agregar(usuario); - - switch (mensaje) { - case SIN_ERROR: - usuario = new Usuario(); - return "Usuario.xhtml";//"productoLista?faces-redirect=true"; // Redirecciona a la lista de productos - case ELEMENTO_DUPLICADO: - return null; - case CAMPOS_INCOMPLETOS: - return null; - case DATOS_INCORRECTOS: - return null; - default: - return null; - } - + return "Usuario.xhtml"; } public List getUsuarios() { @@ -95,7 +79,7 @@ public class DemoBeanUsuario implements Serializable { public void prepararEditar(Usuario usuario) { nuevo = false; - titulo = "Editar usuario"; + titulo = "Editando usuario"; this.usuario = usuario; } @@ -110,7 +94,7 @@ public class DemoBeanUsuario implements Serializable { public void preparar() { nuevo = true; - titulo = "Agregar Usuario"; + titulo = "Agregando Usuario"; usuario = new Usuario(); } diff --git a/si-war/web/Marca.xhtml b/si-war/web/Marca.xhtml index ede51de..f55a6e1 100644 --- a/si-war/web/Marca.xhtml +++ b/si-war/web/Marca.xhtml @@ -13,15 +13,13 @@
- - - - + + SISTEMA DE INVENTARIO - -
+ +
@@ -34,7 +32,6 @@ - @@ -42,79 +39,76 @@
-
+ - - - + - - - - -
- -
-
- +
+ + +
+
+
+ + +

- - -

- - - + +
-
-
- - - - - - - - - - - - - - - - - - - - + + + - - - - -
-
-
- -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- - - + - -
+ + + diff --git a/si-war/web/MarcaCrear.xhtml b/si-war/web/MarcaCrear.xhtml index 52e9d7c..0855f07 100644 --- a/si-war/web/MarcaCrear.xhtml +++ b/si-war/web/MarcaCrear.xhtml @@ -29,7 +29,7 @@

- + + + + + - +
diff --git a/si-war/web/Usuario.xhtml b/si-war/web/Usuario.xhtml index 7cfacff..24ad7c6 100644 --- a/si-war/web/Usuario.xhtml +++ b/si-war/web/Usuario.xhtml @@ -31,7 +31,7 @@ - + @@ -65,25 +65,19 @@ placeholder="Buscar" /> - + - + - - - - - - - + @@ -101,30 +95,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/si-war/web/WEB-INF/faces-config.xml b/si-war/web/WEB-INF/faces-config.xml new file mode 100644 index 0000000..659c773 --- /dev/null +++ b/si-war/web/WEB-INF/faces-config.xml @@ -0,0 +1,41 @@ + + + + + + + hola.seguridad.AutorizacionListener + + + + + * + + accesoDenegado + /producto.xhtml + + + + diff --git a/si-war/web/WEB-INF/web.xml b/si-war/web/WEB-INF/web.xml index 0b9fa3c..b765a39 100644 --- a/si-war/web/WEB-INF/web.xml +++ b/si-war/web/WEB-INF/web.xml @@ -19,6 +19,12 @@ - faces/Menu.xhtml + faces/Producto.xhtml + + + + javax.faces.CONFIG_FILES + /WEB-INF/faces-config.xml + diff --git a/si-war/web/index.xhtml b/si-war/web/index.xhtml new file mode 100644 index 0000000..9ddbaf0 --- /dev/null +++ b/si-war/web/index.xhtml @@ -0,0 +1,66 @@ + + + + + + + + + + Facelets Template + + +
+ + +

Inventario almacen

+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + diff --git a/si-war/web/template/Principal.xhtml b/si-war/web/template/Principal.xhtml index 4082202..e03973f 100644 --- a/si-war/web/template/Principal.xhtml +++ b/si-war/web/template/Principal.xhtml @@ -2,7 +2,8 @@ + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:p="http://primefaces.org/ui"> @@ -21,6 +22,14 @@
+ + + Top