easyui Rights Management

Permissions tree

The so-called rights:

It is to allow different users can operate the system in different resources
directly point that different users can see different menu on the left


The so-called role:

It refers to a set of privileges in the system (each of which corresponds to a character set of permissions)

 

1, a star design rights (many-user rights)
? Performing database script
? Established entity classes
? Creating DAO
? Web layer created
? Change display menu tree

Realization of ideas: by account number and password query is to get id of the menu to get inside menuid can be loaded and the corresponding menu or submenu

2. Design Award permission (user rights-many)
? Performing database script SQL
? Modify the existing entity classes
? Established entity classes
? Create a dao method
? Write a set of permissions table method
method? The new webservlet
? Add login interface, the menu tree display jump corresponding to the front end of each set menu permissions

Realization of ideas: the user query data table has landed on behalf of (a method to check uid middle of the table) by uid found in the middle of the table has been registered to get a permission set corresponding to a plurality of data and then traverse uid found in the collection and then stitching each map collection the menuid (menuid this collection is that digital methods available with multiple sets of parent-child relationship in)

Permissions table:

 

 

user table:

 

 

Permissions middle of the table:

 

The first to write a login screen:

<form action="${pageContext.request.contextPath }/userAction.action?methodName=login" method="post">

uid:<input type="text" name="uid"><br>
upwd:<input type="text" name="upwd"><br>
<input type="submit" >
</form>

 

 

Configuration mvc.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<config>
	<!-- <action path="/regAction" type="test.RegAction">
		<forward name="failed" path="/reg.jsp" redirect="false" />
		<forward name="success" path="/login.jsp" redirect="true" />
	</action> -->
	
	<action path="/menuAction" type="com.chenjiahao.web.MenuAction">
			<forward name="index" path="/index.jsp" redirect="false" />
	</action>
	<action path="/userAction" type="com.chenjiahao.web.UserAction">
		<forward name="index" path="/index.jsp" redirect="false" />
	</action>
</config>

 Login Web

Determine whether the person

Return the man's authority

package com.chenjiahao.dao;

import java.util.List;
import java.util.Map;

import com.chenjiahao.util.JsonBaseDao;
import com.chenjiahao.util.JsonUtils;
import com.chenjiahao.util.PageBean;
com.chenjiahao.util.StringUtils amount;

public class UserDao extends JsonBaseDao {

	/**
	 * Login for user table
	 * 
	 * @param map
	 * @param pageBean
	 * @return
	 * @throws Exception
	 */

	public List<Map<String, Object>> list(Map<String, String[]> map, PageBean pageBean) throws Exception {

		String sql = "SELECT *FROM t_easyui_user_version2 WHERE TRUE";
		String uid = JsonUtils.getParamVal(map, "uid");
		String upwd = JsonUtils.getParamVal(map, "upwd");
		if (StringUtils.isNotBlank(uid)) {
			sql = sql + " and uid=" + uid;
		}
		if (StringUtils.isNotBlank(upwd)) {
			sql = sql + " and upwd=" + upwd;
		}

		return super.executeQuery(sql, null);
	}

	/**
	 * By mid-table query the user login corresponding permissions
	 * 
	 * @param string
	 * @param pageBean
	 * @return
	 * @throws Exception
	 */
	public List<Map<String, Object>> listMenu(String uid, PageBean pageBean) throws Exception {

		String sql = "SELECT*FROM t_easyui_usermenu WHERE TRUE";

		if (StringUtils.isNotBlank(uid)) {
			sql = sql + " and uid=" + uid;
		}

		return super.executeQuery(sql, null);
	}

}

  

Begin execution:

public class UserAction extends ActionSupport {

private UserDao userDao = new UserDao();

/**
* @param request
* @param response
* @return
* @throws Exception
*/
public String login(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<Map<String, Object>> list = this.userDao.list(request.getParameterMap(), null);
if (list != null && list.size() > 0) {
List<Map<String, Object>> listMenu = this.userDao.listMenu(request.getParameter("uid"), null);
StringBuilder sb = new StringBuilder();
for (Map<String, Object> map : listMenu) {
sb.append("," + map.get("menuId"));
}
request.setAttribute("menuHid", sb.substring(1));

} else {
return "login";
}
return "index";
}
}

  To obtain landing permission information after the spread Index.jsp

 

<body class="easyui-layout">
<input type="hidden" id="menuHid" value="${menuHid }">
	<div data-options="region:'north',border:false"
		style="height: 60px; background: #B3DFDA; padding: 10px">north
		region</div>
	<div data-options="region:'west',split:true,title:'West'"
		style="width: 150px; padding: 10px;">
		Admin interface menu
		<ul id="tt"></ul>
	</div>
	<div
		data-options="region:'east',split:true,collapsed:true,title:'East'"
		style="width: 100px; padding: 10px;">east region</div>
	<div data-options="region:'south',border:false"
		style="height: 50px; background: #A9FACD; padding: 10px;">south
		region</div>
	<div data-options="region:'center',title:'Center'">
	<div id="menuTabs" class="easyui-tabs" style="">   
    <div title="Tab1" style="padding:20px;display:none;">   
        tab1    
    </div>   
  
</div>  
	</div>
</body>

  It is to get the information, and then jump path

$(function() {
	$('#tt')
			.tree(
					{
						url : 'menuAction.action?methodName=treeMenu&&menuHid='+$("#menuHid").val(),
						onClick : function(node) {
							var content = '<iframe scrolling="no" frameborder="0" src="'
									+ node.attributes.menuURL
									+ '" width="99%" height="99%"></iframe>';
							if ($('#menuTabs').tabs('exists', node.text)) {
								$('#menuTabs').tabs('select', node.text)
							} else {
								$('#menuTabs').tabs('add', {
									title : node.text,
									content : content,
									closable : true,
									tools : [ {
										iconCls : 'icon-mini-refresh',
										handler : function() {
											alert('refresh');
										}
									} ]
								});
							}
						}
					});
})

  Menu query:

package com.chenjiahao.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.chenjiahao.entity.TreeNode;
import com.chenjiahao.util.JsonBaseDao;
import com.chenjiahao.util.JsonUtils;
import com.chenjiahao.util.PageBean;
com.chenjiahao.util.StringUtils amount;

public class MenuDao extends JsonBaseDao {

	private static final Map<String, String[]> TreeNode = null;

	/**
	 * 
	 * @param map
	 *            request.getParameterMap
	 * @param pageBean
	 * Page
	 * @return
	 * @throws SQLException
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 */
	public List<TreeNode> list(Map<String, String[]> map, PageBean pageBean) throws Exception {

		List<Map<String, Object>> listMenu = this.listMenuSet(map, pageBean);
		List<TreeNode> treeNodeList = new ArrayList<>();
		menu2TreeNodelist(listMenu, treeNodeList);

		return treeNodeList;
	}

	public List<Map<String, Object>> listMenuSet(Map<String, String[]> map, PageBean pageBean) throws Exception {
		String sql = "select * from t_easyui_menu where true";
		String id = JsonUtils.getParamVal(map, "menuHid");

		if (StringUtils.isNotBlank(id)) {
			sql = sql + " and menuid in (" + id + ")";

		} else {
			sql = sql + " and menuid=-1";
		}
   
		return super.executeQuery(sql, pageBean);
	}

	/**
	 * Data Query menu table
	 * 
	 * @param map
	 * @param pageBean
	 * @return
	 * @throws SQLException
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 */
	public List<Map<String, Object>> listMenu(Map<String, String[]> map, PageBean pageBean) throws Exception {
		String sql = "select * from t_easyui_menu where true";
		String id = JsonUtils.getParamVal(map, "id");
		if (StringUtils.isNotBlank(id)) {
			sql = sql + " and parentid=" + id;

		} else {
			sql = sql + " and parentid=-1";
		}

		return super.executeQuery(sql, pageBean);
	}

	/**
	 * Menu table data format does not conform to the format easyui tree display format needs to be converted can recognize easyui
	 * 
	 * @param map
	 * @param treeNode
	 * @throws SQLException
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 */
	private void menu2TreeNode(Map<String, Object> map, TreeNode treeNode) throws Exception {
		treeNode.setId(map.get("Menuid").toString());
		treeNode.setText(map.get("Menuname").toString());
		treeNode.setAttributes(map);
		// recursive
		Map<String, String[]> jspMap = new HashMap<>();
		jspMap.put("id", new String[] { treeNode.getId() });
		List<Map<String, Object>> listMenu = this.listMenu(jspMap, null);

		List<TreeNode> treeNodeList = new ArrayList<>();
		// loop data taken out
		menu2TreeNodelist(listMenu, treeNodeList);
		treeNode.setChildren(treeNodeList);

	}

	private void menu2TreeNodelist(List<Map<String, Object>> mapList, List<TreeNode> treeNodeList) throws Exception {
		TreeNode treeNode = null;
		for (Map<String, Object> map : mapList) {
			treeNode = new TreeNode();
			menu2TreeNode(map, treeNode);
			treeNodeList.add(treeNode);
		}

	}
}

  Renderings

Guess you like

Origin www.cnblogs.com/chenjiahao9527/p/11012727.html