我真的需要任何帮助。 我有一个运行在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("<partial-response><redirect url=\"%s\"></redirect></partial-response>", "/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<String> urlsPublicas = new ArrayList<String>();
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
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<description>Customizable Filter</description>
<filter-name>customFilter</filter-name>
<filter-class>com.oriuken.autorack.security.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>customFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
<error-page>
<error-code>401</error-code>
<location>/noAutorizacion.xhtml?faces-redirect=true</location>
</error-page>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>casablanca</param-value>
</context-param>
<context-param>
<param-name>primefaces.PUSH_SERVER_URL</param-name>
<param-value>ws://localhost:8088</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
感谢您的任何线索!
在这种情况下,'Global.getLoggedUser()'看起来像是一个'静态'方法,非常可怕。我认为这是整个罪魁祸首,您将登录用户存储为“静态”变量。 – BalusC 2012-08-16 02:37:25
我只是注意到,你是一如既往的惊人的BalusC ......但我该怎么办? Global类有一个静态Hashmap,我在其中输入其他东西 - 登录的用户,这样我就可以在应用程序的任何地方访问他。我该如何取代? ...并再次感谢您的时间。 – oriuken 2012-08-16 02:57:31
我将从会话bean中获取用户,我认为这是正确的方式,但是,我从数据库中获得的静态哈希映射中有其他内容,并且与应用中的所有人相同,如通用值(税收,一般信息等)。那个值,我可以把它留在那个静态散列表中,还是应该将它们移动到一个应用程序范围的bean中? – oriuken 2012-08-16 03:40:30