防止用户直接访问框架URL的权限控制

使用过滤器可防止用户直接在浏览器中输入URL访问。

过滤器的内容如下:

	public void preProcess(WebContext context) {
		this.initParam();
		String URI = context.getRequest().getRequestURI();
		//获取父URL--用户直接输入URL,这个父URL是不存在的
		String parentURL = context.getRequest().getHeader("REFERER");  
		boolean illegalURLFlag = false; //非法URL标志
		Object userSession = context.getRequest().getSession().getAttribute(this.getSessionKey());
		if(null == userSession){//未登录,不使用该filter
			return;
		}
		if(null == parentURL || "".equals(parentURL)){//无父URL,非法访问
			illegalURLFlag = true;
		}
		// 非法访问URL
		if (illegalURLFlag){
			try {
				//强制用户重新登录
				context.getRequest().getSession().removeAttribute(this.getSessionKey());
				context.getResponse().sendRedirect(context.getRequest().getContextPath());
				log.info("common.filter.illegalURLfilter.preprocess.noright", URI);
			} catch (Exception e) {
				log.error(e, "common.filter.illegalURLfilter.preprocess.redirectErrorPage", new Object[]{URI, this.getMainPage()});
			}
		}
	}

 

过滤器的配置文件如下:

		<!-- 防止用户直接访问URL -->
		<tiny-filter id="illegalURLFilter" class="illegalURLFilter">
			<filter-mapping url-pattern=".*" ></filter-mapping>
			<!-- 登录后,非法URL访问跳转到此页面-->
			<init-param name="mainPage" value="/index.jsp"></init-param>
			<!-- 用户会话信息KEY -->
			<init-param name="sessionKey" value="commDtoSession"></init-param>
		</tiny-filter>

 

直接访问URL效果图如下:



 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值