BAMS 二次开发文档

角色、权限设计

发布时间 2015-01-14 08:54   浏览量()   收藏()

给人员分配账号之后,该账号还不能登录系统,还需要配置该人员的权限。

在“企业平台”模块中点击 系统设置 - 设置权限,可以为各个人员设置模块、功能菜单。你还可以使用“角色”这个概念来设置权限,在“企业平台”模块中点击 系统设置 - 角色管理。

BAMS中“角色”的绑定类型有4种,分别是用户、用户组、部门、岗位,可以根据实际的需求灵活配置。

如果为人员单独设置了权限,又在角色中设置了权限,那么该人员的权限是两者之和。所以有时配置权限后发现不起作用,请两边都检查一下。

BAMS的权限控制还是比较简单的,只控制到了模块、功能菜单,不涉及页面上的按钮和数据。这样的设计很灵活,但是也会带来更多的工作量。设计原则归结为:“系统只提供粗粒度的权限,细粒度的权限被认为是业务逻辑的职责”。

如果有人跳过功能菜单,直接访问jsp页面怎么办?BAMS中只需要在超级后台新建功能菜单的时候,填写”功能所设计到的页面“,即可防止这种非法操作,处理方式详见PermissionFilter过滤器代码:

public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain chain) throws IOException, ServletException {
	HttpServletRequest httpRequest = (HttpServletRequest) request;
	HttpServletResponse httpResponse = (HttpServletResponse) response;
	
	SessionUser sessionUser =  (SessionUser) LoginContext.getSessionValueByLogin(httpRequest);

	if(sessionUser == null){
		logger.info("系统尚未登录....");
		httpResponse.sendRedirect(httpRequest.getContextPath()+"/centerSend.jsp");
		return;
	}
	
	//获取当前访问的页面名称
	String tmpUrl = httpRequest.getRequestURL().toString();
	String page = StringTool.getPageName(tmpUrl);
	ServletContext context = httpRequest.getSession().getServletContext();
	WebApplicationContext webctx = WebApplicationContextUtils.getWebApplicationContext(context);
	DwrSysProcessService service = (DwrSysProcessService)webctx.getBean("dwrSysProcessService");
	//根据页面名称获取相关功能菜单
	List<SysMethodInfo> list = service.listSysmethodInfoByPage(context,httpRequest,page);
	
	boolean permissionFlag = false;
	
	//如果没有页面相关的功能菜单,可以访问。
	if(list.size() == 0){
		permissionFlag = true;
	}
	//如果用户有权限的功能菜单包含访问页面相关的功能菜单,可以访问。
	for (SysMethodInfo sysMethodInfo : list) {
		if(sessionUser.getUserMethodsSet().contains(sysMethodInfo.getPrimaryKey())){
			permissionFlag = true;
		}
	}

	if(permissionFlag){
		chain.doFilter(httpRequest, httpResponse);
	}else{
		logger.error("{},IP:{},访问页面:{},没有权限....",sessionUser.getEmployeeName(),request.getRemoteAddr(),page);
		httpResponse.sendRedirect(httpRequest.getContextPath()+"/error.jsp");
	}
	
}


广告会让浏览体验不好,可这是网站的唯一收入,请点击下面的百度广告,支持老高的开源行动吧!