我真的需要任何帮助。 我有一个运行在tomcat 6上的PrimeFaces的JSF应用程序。当另一台计算机登录时(另一台计算机)登录的更改
我以为我已经完成了应用程序,但是当测试它时,我发现了一个巨大的问题。 当我在计算机1中与用户(例如'admin')登录到应用程序中,然后用计算机2上的其他用户(例如'peter')登录时,computer1现在无法访问允许用户管理员访问的页面。如果我以后用管理员用户在计算机1中重新登录,现在在计算机2中,彼得可以访问允许管理的所有页面。
这就像我有一个会议的所有tomcat会议或类似的东西。
我搜索了一下我的应用程序,发现@applicationScoped什么都没有,我拥有所有@sessionScoped beans。
我不知道该怎么做。请帮忙。
我在这里附上我的自定义过滤器:
public abstract class AbstractLoginFilter implements javax.servlet.Filter {
protected ServletContext servletContext;
@Override
public void init(FilterConfig filterConfig) {
servletContext = filterConfig.getServletContext();
}
@Override
public void doFilter(
ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String pageReq = req.getRequestURL().toString();
HttpSession session = req.getSession(false);
String[] temp = pageReq.split("/faces", 2);
String url = temp[1];
resp.setCharacterEncoding("UTF-8");
req.setCharacterEncoding("UTF-8");
if ("/login.xhtml".equals(url)) {
continueExecution(chain, request, response);
} else {
if (session == null) {
//session timeout check.
if (req.getRequestedSessionId() != null && !req.isRequestedSessionIdValid()) {
System.out.println("La sesión ha expirado");
session = req.getSession(true);
//si es un ajax
if ("partial/ajax".equals(req.getHeader("Faces-Request"))) {
resp.setContentType("text/xml");
resp.getWriter().append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").printf("", "/Autorack/faces/login.xhtml");
} else {
resp.sendRedirect("/Autorack/faces/login.xhtml");
}
}
} else {
if (Global.getLoggedUser() == null) {
resp.sendRedirect("/Autorack/faces/login.xhtml");
} else {
if (isPublicPage(url) || isAuth(url)) {
continueExecution(chain, request, response);
} else {
resp.sendRedirect("/Autorack/faces/noAutorizacion.xhtml");
}
}
}
}
}
private void continueExecution(FilterChain chain, ServletRequest request, ServletResponse response) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
//when i make a BACK
if (!req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
resp.setHeader("Pragma", "no-cache"); // HTTP 1.0.
resp.setDateHeader("Expires", 0); // Proxies.
}
chain.doFilter(request, response);
}
private boolean isPublicPage(String url) {
List urlsPublicas = new ArrayList();
urlsPublicas.add("/inicio.xhtml");
urlsPublicas.add("/noAutorizacion.xhtml");
urlsPublicas.add("/usuario/CambioPassword.xhtml");
return urlsPublicas.contains(url);
}
@Override
public void destroy() {
}
/**
* logic to accept or reject access to the page, check log in status
* @return true when authentication is deemed valid
*/
protected abstract boolean isAuth(String reqPage);
}
这里是我的web.xml
Customizable Filter
customFilter
com.oriuken.autorack.security.LoginFilter
customFilter
*.xhtml
401
/noAutorizacion.xhtml?faces-redirect=true
javax.faces.PROJECT_STAGE
Production
Faces Servlet
javax.faces.webapp.FacesServlet
1
Faces Servlet
/faces/*
30
faces/index.xhtml
primefaces.THEME
casablanca
primefaces.PUSH_SERVER_URL
ws://localhost:8088
javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE
true
感谢您的任何线索!
2012-08-16
oriuken
+0
在这种情况下,'Global.getLoggedUser()'看起来像是一个'静态'方法,非常可怕。我认为这是整个罪魁祸首,您将登录用户存储为“静态”变量。 –
2012-08-16 02:37:25
+0
我只是注意到,你是一如既往的惊人的BalusC ......但我该怎么办? Global类有一个静态Hashmap,我在其中输入其他东西 - 登录的用户,这样我就可以在应用程序的任何地方访问他。我该如何取代? ...并再次感谢您的时间。 –
2012-08-16 02:57:31
+0
我将从会话bean中获取用户,我认为这是正确的方式,但是,我从数据库中获得的静态哈希映射中有其他内容,并且与应用中的所有人相同,如通用值(税收,一般信息等)。那个值,我可以把它留在那个静态散列表中,还是应该将它们移动到一个应用程序范围的bean中? –
2012-08-16 03:40:30