diff --git a/backoffice/src/main/java/uy/edu/fing/tse/jsf/SecurityBean.java b/backoffice/src/main/java/uy/edu/fing/tse/jsf/SecurityBean.java new file mode 100644 index 0000000000000000000000000000000000000000..87d9beef4b53e64e654a6709ecc2992f32235164 --- /dev/null +++ b/backoffice/src/main/java/uy/edu/fing/tse/jsf/SecurityBean.java @@ -0,0 +1,26 @@ +package uy.edu.fing.tse.jsf; + +import javax.enterprise.context.RequestScoped; +import javax.faces.context.FacesContext; +import javax.inject.Named; +import java.util.Objects; + +@RequestScoped +@Named("security") +public class SecurityBean { + + public boolean isLogged() { + final var token = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("token"); + return token != null; + } + + public boolean hasRole(final String role) { + final var rol = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("role"); + return Objects.equals(rol, role); + } + + public String getUser() { + return (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user"); + } + +} diff --git a/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java b/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java index 525e65eef471c52fef9cbdccde9ebe7556a08294..7460c038372078566c0aad1beb3d929767a4e225 100644 --- a/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java +++ b/backoffice/src/main/java/uy/edu/fing/tse/jsf/UserLoginBean.java @@ -74,8 +74,7 @@ public class UserLoginBean implements Serializable { if (token != null) { addCookieToken(token); - PrimeFaces.current().executeScript("window.location.href='jsf/gestionhechos.xhtml'"); - //return "jsf/gestionhechos"; + PrimeFaces.current().executeScript("window.location.href='jsf/listarHechos.xhtml'"); } else { FacesContext.getCurrentInstance().addMessage( null, @@ -100,7 +99,7 @@ public class UserLoginBean implements Serializable { //TODO if (valid) { final var s = securityLocal.register(user); - PrimeFaces.current().executeScript("window.location.href='jsf/gestionhechos.xhtml'"); + PrimeFaces.current().executeScript("window.location.href='jsf/listarHechos.xhtml'"); } else { FacesContext.getCurrentInstance().addMessage( null, diff --git a/backoffice/src/main/java/uy/edu/fing/tse/jsf/security/LoginFilter.java b/backoffice/src/main/java/uy/edu/fing/tse/jsf/security/LoginFilter.java index 7fd3082c0f1fbbb6b3bb733b1ec7061de1c65312..641627b112a85a1391740c647c3b7a421c87dbbd 100644 --- a/backoffice/src/main/java/uy/edu/fing/tse/jsf/security/LoginFilter.java +++ b/backoffice/src/main/java/uy/edu/fing/tse/jsf/security/LoginFilter.java @@ -35,7 +35,7 @@ public class LoginFilter implements Filter { try { final Claims claims = Jwts.parser().setSigningKey("1q2w3e4r5t6y7u8i9o0p").parseClaimsJws(token).getBody(); - response.sendRedirect(request.getContextPath() + "/jsf/gestionhechos.xhtml"); + response.sendRedirect(request.getContextPath() + "/jsf/listarHechos.xhtml"); } catch (final Exception e) { chain.doFilter(req, res); return; diff --git a/backoffice/src/main/webapp/WEB-INF/templates/template.xhtml b/backoffice/src/main/webapp/WEB-INF/templates/template.xhtml index 7f24bbd18c2517856e5f3b13b3263cb2f63dac4b..dd6bbe5a37ec6c24cfa1513a57118864385417d2 100644 --- a/backoffice/src/main/webapp/WEB-INF/templates/template.xhtml +++ b/backoffice/src/main/webapp/WEB-INF/templates/template.xhtml @@ -34,12 +34,29 @@ <header> <h1>BackOffice - feiknius</h1> <h:form> - <p:megaMenu orientation="horizontal" style="margin-top:20px" - rendered="#{session.getAttribute('user')!=null}"> - <p:menuitem value="Salir" action="#{userLoginView.logout()}"/> - <p:menuitem value="Listar Hechos" action="gestionhechos.xhtml?faces-redirect=true" async="true"/> - <p:menuitem value="Publicar Hechos" action="publicarcancelar.xhtml?faces-redirect=true" async="true" - rendered="#{session.getAttribute('role') == 'Submitter'}"/> + <p:megaMenu orientation="horizontal" style="margin-top:20px" rendered="#{security.logged}"> + <p:submenu label="#{security.user}"> + <p:column> + <p:submenu label="Gestion"> + <p:menuitem value="Salir" action="#{userLoginView.logout()}"/> + </p:submenu> + </p:column> + </p:submenu> + + <p:menuitem value="Listar Hechos" action="listarHechos.xhtml?faces-redirect=true"/> + + <p:menuitem value="Mecanismos" action="gestionMecanismos.xhtml?faces-redirect=true" + rendered="#{security.hasRole('Admin')}"/> + <p:menuitem value="Perifericos" action="gestionPerifericos.xhtml?faces-redirect=true" + rendered="#{security.hasRole('Admin')}"/> + <p:menuitem value="Usuarios" action="gestionUsuarios.xhtml?faces-redirect=true" + rendered="#{security.hasRole('Admin')}"/> + + <p:menuitem value="Gestionar Hechos" action="gestionSubmitter.xhtml?faces-redirect=true" + rendered="#{security.hasRole('Submitter')}"/> + + <p:menuitem value="Verificar Hechos" action="gestionChecker.xhtml?faces-redirect=true" + rendered="#{security.hasRole('Checker')}"/> </p:megaMenu> </h:form> </header> diff --git a/backoffice/src/main/webapp/jsf/gestionhechos.xhtml b/backoffice/src/main/webapp/jsf/gestionChecker.xhtml similarity index 96% rename from backoffice/src/main/webapp/jsf/gestionhechos.xhtml rename to backoffice/src/main/webapp/jsf/gestionChecker.xhtml index 1fb6395fe7ed8bb2cc51d723cb757185193e38a2..97feec365689509ae24af7ce98a5cbbcdf989247 100644 --- a/backoffice/src/main/webapp/jsf/gestionhechos.xhtml +++ b/backoffice/src/main/webapp/jsf/gestionChecker.xhtml @@ -11,8 +11,7 @@ <ui:define name="contenido"> <h:form> <p:outputPanel style="font-size: 30px;text-align: center"> - <h:outputText value="Bienvenido "/> - <h:outputText value="#{session.getAttribute('user')}"/> + <h:outputText value="Verificacion de hechos - Checker"/> </p:outputPanel> <p:dataTable var="hecho" id="dataHecho" value="#{gestionHechos.facts}" widgetVar="NoticiasTable" diff --git a/backoffice/src/main/webapp/jsf/gestionMecanismos.xhtml b/backoffice/src/main/webapp/jsf/gestionMecanismos.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..998468af53e5be1a734eec1b24e8b8bac6c474c1 --- /dev/null +++ b/backoffice/src/main/webapp/jsf/gestionMecanismos.xhtml @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui" + xmlns:h="http://xmlns.jcp.org/jsf/html" +> +<body> + +<ui:decorate template="/WEB-INF/templates/template.xhtml"> + <ui:define name="contenido"> + <h:form> + <p:outputPanel style="font-size: 30px;text-align: center"> + <h:outputText value="Gestion de Mecanismos Internos"/> + </p:outputPanel> + + </h:form> + </ui:define> +</ui:decorate> +</body> +</html> + diff --git a/backoffice/src/main/webapp/jsf/gestionPerifericos.xhtml b/backoffice/src/main/webapp/jsf/gestionPerifericos.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..de0b740afd61929468204f99e35f3bdc13e09f33 --- /dev/null +++ b/backoffice/src/main/webapp/jsf/gestionPerifericos.xhtml @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui" + xmlns:h="http://xmlns.jcp.org/jsf/html" +> +<body> + +<ui:decorate template="/WEB-INF/templates/template.xhtml"> + <ui:define name="contenido"> + <h:form> + <p:outputPanel style="font-size: 30px;text-align: center"> + <h:outputText value="Gestion de Perifericos"/> + </p:outputPanel> + + </h:form> + </ui:define> +</ui:decorate> +</body> +</html> + diff --git a/backoffice/src/main/webapp/jsf/gestionSubmitter.xhtml b/backoffice/src/main/webapp/jsf/gestionSubmitter.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..5cc2e430875ad6b0b192e994a6f1c42fca6cafdc --- /dev/null +++ b/backoffice/src/main/webapp/jsf/gestionSubmitter.xhtml @@ -0,0 +1,66 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui" + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:f="http://xmlns.jcp.org/jsf/core" +> +<body> + +<ui:decorate template="/WEB-INF/templates/template.xhtml"> + <ui:define name="contenido"> + <h:form> + <p:outputPanel style="font-size: 30px;text-align: center"> + <h:outputText value="Gestion de hechos - Submitter"/> + </p:outputPanel> + + <p:dataTable var="hecho" id="dataHecho" value="#{gestionHechos.facts}" widgetVar="NoticiasTable" + emptyMessage="Hecho no encontrado" filteredValue="#{gestionHechos.filteredFacts}"> + <f:facet name="header"> + <p:outputPanel> + <h:outputText value="Buscar en todos los campos:"/> + <p:inputText id="globalFilter" onkeyup="PF('NoticiasTable').filter()" style="width:150px" + placeholder="Enter keyword"/> + </p:outputPanel> + </f:facet> + + <p:column filterBy="#{hecho.title}" headerText="Titulo" filterMatchMode="contains"> + <h:outputText value="#{hecho.title}"/> + </p:column> + <p:column filterBy="#{hecho.description}" headerText="Descripción" filterMatchMode="contains"> + <h:outputText value="#{hecho.description}"/> + </p:column> + <p:column filterBy="#{hecho.actualState.value}" headerText="Estados" filterMatchMode="exact"> + <f:facet name="filter"> + <p:selectOneMenu onchange="PF('NoticiasTable').filter()" styleClass="custom-filter"> + <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true"/> + <f:selectItems value="#{gestionHechos.estados}" var="e" itemLabel="#{e.value}" + itemValue="#{hecho.actualState.value}"/> + </p:selectOneMenu> + </f:facet> + <h:outputText value="#{hecho.actualState.value}"/> + </p:column> + + <p:column headerText="" style="text-align: center"> + + <p:growl id="message" showDetail="true"/> + + <p:commandButton value="Enviar Verificación" action="#{hecho.setEstado()}" update="@form" + disabled="#{hecho.EstaVerifcado()}"> + <p:confirm header="Confirmar" message="¿Enviar Solicitud?" icon="pi pi-exclamation-triangle"/> + </p:commandButton> + + <p:confirmDialog global="true" showEffect="fade" hideEffect="fade"> + <p:commandButton value="Si" type="button" styleClass="ui-confirmdialog-yes" icon="pi pi-check"/> + <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="pi pi-times"/> + </p:confirmDialog> + + </p:column> + </p:dataTable> + + </h:form> + </ui:define> +</ui:decorate> +</body> +</html> + diff --git a/backoffice/src/main/webapp/jsf/gestionUsuarios.xhtml b/backoffice/src/main/webapp/jsf/gestionUsuarios.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..6e8aa7f6411c5f23548055a47d7c5756a2df49f9 --- /dev/null +++ b/backoffice/src/main/webapp/jsf/gestionUsuarios.xhtml @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui" + xmlns:h="http://xmlns.jcp.org/jsf/html" +> +<body> + +<ui:decorate template="/WEB-INF/templates/template.xhtml"> + <ui:define name="contenido"> + <h:form> + <p:outputPanel style="font-size: 30px;text-align: center"> + <h:outputText value="Gestion de Usuarios"/> + </p:outputPanel> + + </h:form> + </ui:define> +</ui:decorate> +</body> +</html> + diff --git a/backoffice/src/main/webapp/jsf/index.html b/backoffice/src/main/webapp/jsf/index.html index dda0a23c87ec9e23f66da54dad08efe4293982b3..4799d3c612465fcb10c7b6fba4261f50008b3a7e 100644 --- a/backoffice/src/main/webapp/jsf/index.html +++ b/backoffice/src/main/webapp/jsf/index.html @@ -3,7 +3,7 @@ <head> <meta charset="UTF-8"> <title>BackOffice - feiknius</title> - <meta http-equiv="refresh" content="0; url=gestionhechos.xhtml"> + <meta http-equiv="refresh" content="0; url=listarHechos.xhtml"> </head> <body></body> </html> \ No newline at end of file diff --git a/backoffice/src/main/webapp/jsf/listarHechos.xhtml b/backoffice/src/main/webapp/jsf/listarHechos.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..0362fd95e5e9b3fa884788d06f23338a1b8e291d --- /dev/null +++ b/backoffice/src/main/webapp/jsf/listarHechos.xhtml @@ -0,0 +1,50 @@ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:p="http://primefaces.org/ui" + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:f="http://xmlns.jcp.org/jsf/core" +> +<body> + +<ui:decorate template="/WEB-INF/templates/template.xhtml"> + <ui:define name="contenido"> + <h:form> + <p:outputPanel style="font-size: 30px;text-align: center"> + <h:outputText value="Bienvenido "/> + <h:outputText value="#{security.user}"/> + </p:outputPanel> + + <p:dataTable var="hecho" id="dataHecho" value="#{gestionHechos.facts}" widgetVar="NoticiasTable" + emptyMessage="Hecho no encontrada" filteredValue="#{gestionHechos.filteredFacts}"> + <f:facet name="header"> + <p:outputPanel> + <h:outputText value="Buscar en todos los campos:"/> + <p:inputText id="globalFilter" onkeyup="PF('NoticiasTable').filter()" style="width:150px" + placeholder="Enter keyword"/> + </p:outputPanel> + </f:facet> + + <p:column filterBy="#{hecho.title}" headerText="Titulo" filterMatchMode="contains"> + <h:outputText value="#{hecho.title}"/> + </p:column> + <p:column filterBy="#{hecho.description}" headerText="Descripción" filterMatchMode="contains"> + <h:outputText value="#{hecho.description}"/> + </p:column> + <p:column filterBy="#{hecho.actualState.value}" headerText="Estados" filterMatchMode="exact"> + <f:facet name="filter"> + <p:selectOneMenu onchange="PF('NoticiasTable').filter()" styleClass="custom-filter"> + <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true"/> + <f:selectItems value="#{gestionHechos.estados}" var="e" itemLabel="#{e.value}" + itemValue="#{hecho.actualState.value}"/> + </p:selectOneMenu> + </f:facet> + <h:outputText value="#{hecho.actualState.value}"/> + </p:column> + </p:dataTable> + </h:form> + </ui:define> +</ui:decorate> +</body> +</html> +