使用filter验证session用户和页面缓存问题处理
2010-12-02 15:05
393 查看
WEB的信息安全隐患之一:
未授权用户通过直接在IE中输入URL直接登录系统
解决办法:
通过配置filter过滤无效用户的连接请求.
WEB的信息安全隐患之二:
合法用户"注销"后,在未关闭浏览器的情况下,点击浏览器"后退"按钮,可从与本地页面缓存中读取数据,绕过了服务端filter过滤.
解决办法:
在必要的页面(包含敏感信息) 设定页面缓存限制.
也可以把上面两步组合在一个,通过同一个filter实现.具体如下:
1.配置filter(web.xml)
......
<filter>
<filter-name>Authentication</filter-name> <!-- Authentication过滤器别名 -->
<filter-class>com.mycompany.myweb.management.util.AuthenticationFilter</filter-class> <!-- 过滤器Authentication指向的具体类 -->
<init-param>
<param-name>onError</param-name> <!-- 过滤器初始化参数配置 -->
<param-value>/Logon.do</param-value> <!-- 这里指定无效用户跳转方向 -->
</init-param>
</filter>
<filter-mapping>
<filter-name>Authentication</filter-name>
<url-pattern>/management/*</url-pattern> <!-- management/*是要过滤的文件的位置,表示过滤management文件夹下的所内容。 -->
</filter-mapping>
<filter-mapping>
<filter-name>Authentication</filter-name>
<url-pattern>/Main.do</url-pattern> <!-- Main.do/*是要过滤的请求,表示过滤此请求指定的页面的所内容。 -->
</filter-mapping>
......
AuthenticationFilter过滤器实现类:
package com.mycompany.myweb.management.util;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.struts.Globals;
import org.apache.struts.action.*;
public class AuthenticationFilter implements Filter {//一定要使用Filter接口
private FilterConfig filterConfig;
private String onErrorUrl;
public void init(FilterConfig config) throws ServletException {
filterConfig = config;
onErrorUrl = filterConfig.getInitParameter("onError");
if (onErrorUrl == null || "".equals(onErrorUrl)) {
onErrorUrl = "onError";
}
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain next) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpSession httpSession = httpRequest.getSession();
/**
* @author justin ray
* @see 页面缓存设定
* <br>确保浏览器不缓存页面数据
*/
httpResponse.setHeader("Cache-Control","no-cache");
httpResponse.setHeader("Cache-Control","no-store");
httpResponse.setDateHeader("Expires", 0);
httpResponse.setHeader("Pragma","no-cache");
/**
* @author justin ray
* @see 过滤未登录用户无效请求
* <br>未登录用户请求跳转到/Logon.do
*/
if (httpSession.getAttribute("ePAccountInfo") == null) {
ActionErrors errors = new ActionErrors();
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("没有登录"));
httpRequest.setAttribute(Globals.ERROR_KEY, errors);
httpRequest.getRequestDispatcher(onErrorUrl).forward(httpRequest,
httpResponse);
} else
next.doFilter(request, response);
}
public void destroy() {
}
}
其他方式,如:在一个JSP里实现用户登录验证,其他JSP页面通过include引入验证
未授权用户通过直接在IE中输入URL直接登录系统
解决办法:
通过配置filter过滤无效用户的连接请求.
WEB的信息安全隐患之二:
合法用户"注销"后,在未关闭浏览器的情况下,点击浏览器"后退"按钮,可从与本地页面缓存中读取数据,绕过了服务端filter过滤.
解决办法:
在必要的页面(包含敏感信息) 设定页面缓存限制.
也可以把上面两步组合在一个,通过同一个filter实现.具体如下:
1.配置filter(web.xml)
......
<filter>
<filter-name>Authentication</filter-name> <!-- Authentication过滤器别名 -->
<filter-class>com.mycompany.myweb.management.util.AuthenticationFilter</filter-class> <!-- 过滤器Authentication指向的具体类 -->
<init-param>
<param-name>onError</param-name> <!-- 过滤器初始化参数配置 -->
<param-value>/Logon.do</param-value> <!-- 这里指定无效用户跳转方向 -->
</init-param>
</filter>
<filter-mapping>
<filter-name>Authentication</filter-name>
<url-pattern>/management/*</url-pattern> <!-- management/*是要过滤的文件的位置,表示过滤management文件夹下的所内容。 -->
</filter-mapping>
<filter-mapping>
<filter-name>Authentication</filter-name>
<url-pattern>/Main.do</url-pattern> <!-- Main.do/*是要过滤的请求,表示过滤此请求指定的页面的所内容。 -->
</filter-mapping>
......
AuthenticationFilter过滤器实现类:
package com.mycompany.myweb.management.util;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.struts.Globals;
import org.apache.struts.action.*;
public class AuthenticationFilter implements Filter {//一定要使用Filter接口
private FilterConfig filterConfig;
private String onErrorUrl;
public void init(FilterConfig config) throws ServletException {
filterConfig = config;
onErrorUrl = filterConfig.getInitParameter("onError");
if (onErrorUrl == null || "".equals(onErrorUrl)) {
onErrorUrl = "onError";
}
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain next) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpSession httpSession = httpRequest.getSession();
/**
* @author justin ray
* @see 页面缓存设定
* <br>确保浏览器不缓存页面数据
*/
httpResponse.setHeader("Cache-Control","no-cache");
httpResponse.setHeader("Cache-Control","no-store");
httpResponse.setDateHeader("Expires", 0);
httpResponse.setHeader("Pragma","no-cache");
/**
* @author justin ray
* @see 过滤未登录用户无效请求
* <br>未登录用户请求跳转到/Logon.do
*/
if (httpSession.getAttribute("ePAccountInfo") == null) {
ActionErrors errors = new ActionErrors();
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("没有登录"));
httpRequest.setAttribute(Globals.ERROR_KEY, errors);
httpRequest.getRequestDispatcher(onErrorUrl).forward(httpRequest,
httpResponse);
} else
next.doFilter(request, response);
}
public void destroy() {
}
}
其他方式,如:在一个JSP里实现用户登录验证,其他JSP页面通过include引入验证
相关文章推荐
- JAVA Web 安全机制----使用filter验证session用户和页面缓存问题处理
- Asp.net开发心得点滴[动态加载的用户控件使用事件委托,交给页面处理的事件无效问题]
- 使用filter使session失效的用户,重新跳转到登录页面
- 使用Ajax时处理用户session失效问题的解决方法
- 使用Ajax时处理用户session失效的问题
- 实现页面session验证,非法用户将弹出提示框并跳转页面
- 使用CInternetSession获取utf-8页面中文乱码问题解决方法
- .NET进期综合---缓存/关于跨页面值传递/页面设置CSS/用户自定义控件/fileupload的路径问题/dropdown二级联动的数据库设计
- Filter的原理与使用(对用户进行统一验证)
- ASP.NET jQuery 实例11 通过使用jQuery validation插件简单实现用户登录页面验证功能
- 使用 Filter 过滤器 处理中文 乱码问题
- (转贴)一套.net窗体身份验证方案(解决了防止用户重复登陆,session超时等问题)
- “请求的操作无法在使用用户映射区域打开的文件上执行”问题处理
- 使用Filter验证用户是否登陆,完整示例
- Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题
- java实现验证码生成,解决在页面验证时候session获得的总是前一次值的问题
- 3ff8 使用spring-session管理session时,针对flash上传组件丢失session的问题处理
- 设置HtmlUnitDriver代理及处理用户验证问题
- 使用MVC框架中要注意的问题:如何在页面和用户控件之间传递数据
- Session超时跳转到指定页面(filter实现)解决了图片被过滤问题