页面树结构

版本比较

标识

  • 该行被添加。
  • 该行被删除。
  • 格式已经改变。

1 概述

需求:

 项目现场将系统部署到外网可访问,但是希望限制只能够是手机、Pad等移动设备可访问,通过PC不能访问。

 注意:本示例来源于实际项目,原始版本是V6,可作为参考性质,也许是不能运行的。将系统部署到外网后,移动端可以通过外网访问,但PC不能通过外网访问。

实现方案:

1,添加系统选项配置限制访问的地址,请见新增系统选项

2,使用过滤器拦截用户请求,如果发现请求的地址不是上面系统选项配置的,并且设备是PC,就重定向到一个提示页面,提示只能通过移动设备使用,过滤器的配置请见扩展插件开发基础(内含目录及配置文件介绍)中的插件生命文件extension中的插件声明文件extension.xm的说明l。xml的说明;

 

“限制访问的地址”项,设置为Smartbi部署所在的IP地址后,即可达到上述要求。

最终效果截图如下:

相应地址访问就会找不到该网址PC通过外网访问时,会显示下面的图片。

2 编写修改代码

2.1 在ItemLimitAddr.js文件中添加系统选项配置限制访问的地址js文件中添加系统选项配置限制访问的地址:

代码块
languagejs
linenumberstrue
var ItemLimitAddr = function() {
	this.itemName = "限制访问的地址";
	this.dbKey = "NEW_SYSTEM_CONFIG_ItemLimitAddr";
};
lang.extend(ItemLimitAddr, 'freequery.config.configitem.AbstractSystemConfigItem');
// 进行初始化化动作并返回一个 tr 元素
ItemLimitAddr.prototype.init = function() {
	this.tr = document.createElement("tr");
	this.tr.height = "30";
	this.td1 = document.createElement("td");
	this.td1.align = "left";
	this.td1.width = "200px";
	this.td1.innerHTML = this.itemName + ":";
	this.tr.appendChild(this.td1);
	this.td2 = document.createElement("td");
	this.td2.innerHTML = "<input type='text' name='newConfigItemLimitAddr' id='txt' class='_txt' style='width:100%'>";
	this.tr.appendChild(this.td2);
	this.txt = domutils.findElementByClassName([ this.tr ], "_txt");
	return this.tr;
}
// 检查配置信息是否合法
ItemLimitAddr.prototype.validate = function() {
	return true;
}
// 保存配置并返回是否保存成功 ,对于从系统配置表里的获取数据的配置项来说,返回一个对象
ItemLimitAddr.prototype.save = function() {
	debugger;
	if (!this.validate())
		return false;
	var obj = {
		key : this.dbKey,
		value : this.txt.value
	};
	return obj;
}
// 对于从系统配置表里的获取数据的配置项来说,需要在初始化后根据配置信息来显示
ItemLimitAddr.prototype.handleConfig = function(systemConfig) {
	debugger;
	for ( var i in systemConfig) {
		var config = systemConfig[i];
		if (config && config.key == this.dbKey) {
			
			this.txt.value = config.value;
			break;
		}
	}
};

2.2编写ConfigurationPatch2 编写ConfigurationPatch.js添加配置:

代码块
languagejs
linenumberstrue
var ConfigurationPatch = {
	extensionPoints : {
		SystemConfig : {
			configItem : [ {
				tabName : "公共设置",
				groupName : "公共设置",
				itemNumber : 99999,
				className : "bof.ext.configitems.ItemLimitAddr"
			} ]
		}
	}
};

 

2.3 编写过滤器拦截处理:

代码块
languagejava
linenumberstrue
@Override
 public void doFilter(ServletRequest servletRequest,    ServletResponse servletResponse, FilterChain filterChain)
   		throws IOException, ServletException {
  // TODO Auto-generated method stub
  System.out.println	LOG.debug("该url正在过滤。。。。。");
  	HttpServletRequest request = (HttpServletRequest) servletRequest;
  	HttpServletResponse response = (HttpServletResponse) servletResponse;
  	servletRequest.setCharacterEncoding("UTF-8");
  
  	// 获取系统选项的"限制访问的地址"的值
  	ConfigClientService cs = ConfigClientService.getInstance();
  	ISystemConfig sc = cs.getSystemConfig("NEW_SYSTEM_CONFIG_ItemLimitAddr");
  	String value = null;
 	if if(sc != null) {
  		value value= sc.getValue();
   	}
  
  	// 获取访问的ip地址
  	String ip = request.getLocalAddr();
  	LOG.infodebug("ip:" + ip + ",value:" + value);
  	if (ip.equals(value)) {
   		String requestHeader = request.getHeader("user-agent");
   		if (LimitAddrFilter.isMobileDevice(requestHeader)) {
    System.out.println			LOG.debug("使用手机浏览器");
    			filterChain.doFilter(servletRequest, servletResponse);
   		} else {
    System.out.println			LOG.debug("使用web浏览器");
    			response.sendRedirect(request.getContextPath() + "/404error/404error404.jsp");
    			return;
   		}
  	} else {
   		filterChain.doFilter(servletRequest, servletResponse);
  	}

}

3 相关资源(EPPR-8002)

这个示例代码,包含在示例该示例的示例代码,与限制用户登陆移动设备的数量,请前去下载。整合在一起,请前去下载。