* Implementado esqueleto de menu principal.
* Filtro AuthorizationFilter para gestionar inicio de sesión. * Interfaz para página de login básica. * Todos los managed beans movidos a paquete managedbean * Configuración básica de faces-config con navegación de paginas outcome. * Actualizado web.xml * Utilización de librería primefaces para interfaz de usuario. * Aplicado tema bootstrap para primefaces. * Los iconos (glyph-icons) de primefaces no se cargan en la interfaz (Pendiente de investigar). * Actualización de projects archives para inclusión de clases nuevas en JAR/WAR/EAR de forma correcta.
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
package common;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.faces.annotation.FacesConfig;
|
||||
|
||||
@FacesConfig
|
||||
@ApplicationScoped
|
||||
public class ApplicationConfig {
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
package common;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@WebFilter(filterName = "AuthFilter", urlPatterns = { "*.xhtml" })
|
||||
public class AuthorizationFilter implements Filter {
|
||||
|
||||
public AuthorizationFilter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
try {
|
||||
|
||||
HttpServletRequest reqt = (HttpServletRequest) request;
|
||||
HttpServletResponse resp = (HttpServletResponse) response;
|
||||
HttpSession ses = reqt.getSession(false);
|
||||
|
||||
String reqURI = reqt.getRequestURI();
|
||||
if (reqURI.indexOf("/login.xhtml") >= 0 || (ses != null && ses.getAttribute("username") != null)
|
||||
|| reqURI.indexOf("/public/") >= 0 || reqURI.indexOf("/home.xhtml") >= 0 || reqURI.contains("javax.faces.resource"))
|
||||
chain.doFilter(request, response);
|
||||
else
|
||||
resp.sendRedirect(reqt.getContextPath() + "/login.xhtml");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
|
||||
package common;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
public class SessionUtils {
|
||||
|
||||
public static HttpSession getSession() {
|
||||
return (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
|
||||
}
|
||||
|
||||
public static HttpServletRequest getRequest() {
|
||||
return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
|
||||
}
|
||||
|
||||
public static String getUserName() {
|
||||
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
|
||||
return session.getAttribute("username").toString();
|
||||
}
|
||||
|
||||
public static String getUserId() {
|
||||
HttpSession session = getSession();
|
||||
if (session != null)
|
||||
return (String) session.getAttribute("userid");
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
|
||||
/***
|
||||
*
|
||||
* @author Marcos García Núñez (mgarcianun@uoc.edu)
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ManagedBean(name = "home")
|
||||
@SessionScoped
|
||||
public class homeMBean implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public String getUserName() {
|
||||
return SessionUtils.getSession().getAttribute("username").toString();
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return (String) SessionUtils.getSession().getAttribute("userid");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user