Corregido error al comprobar si el usuario tenía sesión iniciada en el
filtro de authorización.
This commit is contained in:
@@ -29,17 +29,16 @@ public class AuthorizationFilter implements Filter {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
try {
|
||||
|
||||
HttpServletRequest reqt = (HttpServletRequest) request;
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
HttpServletResponse resp = (HttpServletResponse) response;
|
||||
HttpSession ses = reqt.getSession(false);
|
||||
HttpSession ses = req.getSession(false);
|
||||
|
||||
String reqURI = reqt.getRequestURI();
|
||||
if (reqURI.indexOf("/login.xhtml") >= 0 || reqURI.indexOf("/RegisterUser.xhtml") >= 0 || reqURI.indexOf("/RegisterUserResult.xhtml") >= 0
|
||||
|| (ses != null && ses.getAttribute("username") != null) || reqURI.indexOf("/public/") >= 0 || reqURI.indexOf("/home.xhtml") >= 0
|
||||
|| reqURI.contains("javax.faces.resource"))
|
||||
String reqURI = req.getRequestURI();
|
||||
if (reqURI.indexOf("/login.xhtml") >= 0 || reqURI.indexOf("/RegisterUser.xhtml") >= 0 || reqURI.indexOf("/home.xhtml") >= 0 || reqURI.indexOf("/public/") >= 0
|
||||
|| reqURI.contains("javax.faces.resource") || SessionUtils.isLogedIn(ses) == true)
|
||||
chain.doFilter(request, response);
|
||||
else
|
||||
resp.sendRedirect(reqt.getContextPath() + "/login.xhtml");
|
||||
resp.sendRedirect(req.getContextPath() + "/login.xhtml");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
package managedbean.common;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import TO.LoggedUserTO;
|
||||
|
||||
|
||||
public class SessionUtils {
|
||||
public static final String SESSION_VAR_USERNAME = "userName";
|
||||
public static final String SESSION_VAR_USERID = "userId";
|
||||
@@ -15,13 +15,21 @@ public class SessionUtils {
|
||||
public static final String SESSION_VAR_USER = "loggedInUser";
|
||||
|
||||
public static HttpSession getSession() {
|
||||
return (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
|
||||
FacesContext ctx = FacesContext.getCurrentInstance();
|
||||
if (ctx != null)
|
||||
return (HttpSession) ctx.getExternalContext().getSession(false);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HttpServletRequest getRequest() {
|
||||
return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
|
||||
}
|
||||
|
||||
public static HttpSession getSession(ServletRequest request) {
|
||||
return ((HttpServletRequest) request).getSession(false);
|
||||
}
|
||||
|
||||
public static void CreateSession(LoggedUserTO usr) {
|
||||
HttpSession ses = getSession();
|
||||
ses.setAttribute(SessionUtils.SESSION_VAR_USERNAME, usr.getName());
|
||||
@@ -36,10 +44,14 @@ public class SessionUtils {
|
||||
}
|
||||
|
||||
public static boolean isLogedIn() {
|
||||
if (getUserId() == "")
|
||||
return false;
|
||||
else
|
||||
return isLogedIn(getSession());
|
||||
}
|
||||
|
||||
public static boolean isLogedIn(HttpSession session) {
|
||||
if (session != null && session.getAttribute(SessionUtils.SESSION_VAR_USERID) != null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getUserName() {
|
||||
|
||||
@@ -48,11 +48,7 @@ public class LoginMBean extends ManagedBeanBase {
|
||||
|
||||
if (username != null && password != null) {
|
||||
try {
|
||||
Properties props = System.getProperties();
|
||||
Context ctx = new InitialContext(props);
|
||||
SystemAdminFacadeRemote remoteManager = (SystemAdminFacadeRemote) ctx.lookup("java:app/MyHealth.jar/SystemAdminFacadeBean!ejb.systemAdmin.SystemAdminFacadeRemote");
|
||||
|
||||
usr = remoteManager.login(username, password);
|
||||
usr = this.getRemoteManagerSystemAdmin().login(username, password);
|
||||
|
||||
if (usr != null) {
|
||||
loggedIn = true;
|
||||
|
||||
Reference in New Issue
Block a user