package org.zttc.itat.auth.model; /** * 权限控制的关键类,这个类用来存储主体和资源之间的关系,用来确定主体能够对哪些资源进行哪些操作 */ public class ACL { private int id; /** * 主体类型 role user... */ private String ptype; /** * 资源类型 */ private String rtype; /** * 主体id */ private int pid; /** * 资源id */ private int rid; /** * 对方法的操作状态,存储的是一个4个字节的整数,其实就可以存储1-31为,共32个操作 * 0000000...1011 可以进行CREATE,READ,DELETE,无法进行UPDATE * 数据库中存储的是整数,11 */ private int aclState; public void setMenuType(){ this.rtype = MenuResource.RESOURCE_TYPE; } public void setControllerType(){ this.rtype = ControllerResource.RESOURCE_TYPE; } public void setUserType(){ this.ptype = User.PRINCIPAL_TYPE; } public void setRoleType(){ this.ptype = Role.PRINCIPAL_TYPE; } /** * 设置权限,在某个位置设置访问或无法访问 * @param index * @param permit */ public void setPermission(int index,boolean permit){ if(index<0 || index>21){ //throw new Exception("权限的位置只能在0-31直接"); } this.aclState = setBit(this.aclState,index,permit); } /** * 具体进行设置 * @param state * @param index * @param permit */ public int setBit(int state,int index,boolean permit){ int tmp = 1; tmp = tmp<<index; if(permit){ state = state | tmp; }else{ state = ~tmp & state; } return state; } /** * 在某一个位置是否可以访问 * @param index */ public boolean checkPermission(int index){ int tmp = 1; tmp = tmp<<index; int num = tmp & this.aclState; return num >0; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getPtype() { return ptype; } public void setPtype(String ptype) { this.ptype = ptype; } public String getRtype() { return rtype; } public void setRtype(String rtype) { this.rtype = rtype; } public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public int getRid() { return rid; } public void setRid(int rid) { this.rid = rid; } public int getAclState() { return aclState; } public void setAclState(int aclState) { this.aclState = aclState; } }
package org.zttc.itat.auth.model; /** * Controller资源的操作方法类,用来确定某个Controller资源的操作所对应的方法 * @author hfw2192 * */ //@Table //@Entity public class ControllerOper implements SystemResource{ /** * */ private int id; /** * 资源的标识,默认就通过ADD,DELETE,UPDATE,READ */ private String sn; /** * 资源的方法,一个操作默认会对应多个方法add|addInput * 在初始化的时候,可以根据方法的名称来确定,如add开头就是ADD,其他没有声明的都是READ(list,show..) */ private String methodName; /** * */ private String name; /** * 方法的索引位置 */ private int indexPos; /** * 所对应的资源id */ private int rid;//这里使用外键也可以,直接写一个ControllerResource /** * 资源sn */ private String rsn; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getSn() { return sn; } public void setSn(String sn) { this.sn = sn; } public String getMethodName() { return methodName; } public void setMethodName(String methodName) { //第一次添加 if(this.methodName == null || "".equals(this.methodName)){ this.methodName = methodName; }else{ if(this.methodName.indexOf(methodName) >= 0){ //原有的className已经包含了,就直接返回 return; } this.methodName += "\\|" + methodName; } } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getIndexPos() { return indexPos; } public void setIndexPos(int indexPos) { this.indexPos = indexPos; } public int getRid() { return rid; } public void setRid(int rid) { this.rid = rid; } public String getRsn() { return rsn; } public void setRsn(String rsn) { this.rsn = rsn; } }
package org.zttc.itat.auth.model; /** * 控制器资源 * @author hfw2192 * */ public class ControllerResource implements SystemResource{ public static final String RESOURCE_TYPE="controller"; /** * 资源的标识 */ private int id; /** * 资源的名称,中文名称:组织机构管理,用户管理 */ private String name;//资源名称 /** * 资源的唯一标识,在我们的系统中,默认使用类名进行标识 */ private String sn; /** * 资源的父类标识 */ private String psn; /** * 资源所对应的类名,有可能有多个类,所以通过|进行分隔 * Org.zttc.itat.sys...OrgController|....OrgTypeController */ private String className; /** * 资源的排序号 */ private int orderNum;//资源排序号 /** * 资源的父类,存在的主要意义是为了方便在授权的时候进行选择,通过树的方式 */ private ControllerResource parent; public void setClassName(String className){ //第一次添加 if(this.className == null || "".equals(this.className)){ this.className = className; }else{ if(this.className.indexOf(className) >= 0){ //原有的className已经包含了,就直接返回 return; } this.className += "\\|" + className; } } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSn() { return sn; } public void setSn(String sn) { this.sn = sn; } public String getPsn() { return psn; } public void setPsn(String psn) { this.psn = psn; } public String getClassName() { return className; } /*public void setClassName(String className) { this.className = className; }*/ public int getOrderNum() { return orderNum; } public void setOrderNum(int orderNum) { this.orderNum = orderNum; } public ControllerResource getParent() { return parent; } public void setParent(ControllerResource parent) { this.parent = parent; } }
package org.zttc.itat.auth.model; public enum MenuPos { NAV_LEFT("左边导航"),NAV_TOP("顶部菜单"),MODEL_NAV("模块导航"),MODEL_OPER("模块操作"); private MenuPos(String name) { this.name = name; } private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
package org.zttc.itat.auth.model; /** * 菜单资源 * @author hfw2192 * */ public class MenuResource implements SystemResource{ public static final String RESOURCE_TYPE = "menu"; /** * */ private int id; /** * 菜单的名称,中文名称 */ private String name; /** * 菜单的sn,不能重复,讲来要通过这个sn,自动生成页面的超链接,然后为超链接增加一个属性auth_sn, * 其属性值就是sn */ private String sn; /** * 菜单所在的位置 */ private MenuPos menuPos; /** * 菜单的超链接 */ private String href; /** * 菜单的图标 */ private String icon; /** * 菜单的排序号 */ private int orderNum; /** * 是否显示菜单,1表示显示,-1表示不显示 */ private int display; /** * 菜单的父类sn,方便初始化的时候做操作 */ private String psn; /** * 菜单的父类菜单,在授权的时候比较方便 */ private MenuResource parent; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSn() { return sn; } public void setSn(String sn) { this.sn = sn; } public MenuPos getMenuPos() { return menuPos; } public void setMenuPos(MenuPos menuPos) { this.menuPos = menuPos; } public String getHref() { return href; } public void setHref(String href) { this.href = href; } public String getIcon() { return icon; } public void setIcon(String icon) { this.icon = icon; } public int getOrderNum() { return orderNum; } public void setOrderNum(int orderNum) { this.orderNum = orderNum; } public String getPsn() { return psn; } public void setPsn(String psn) { this.psn = psn; } public int getDisplay() { return display; } public void setDisplay(int display) { this.display = display; } public MenuResource getParent() { return parent; } public void setParent(MenuResource parent) { this.parent = parent; } }
package org.zttc.itat.auth.model; /** * 声明式的接口,没有任何方法,实现了这个接口的所有 类都是权限控制的主体 * @author hfw2192 * */ public interface Principal { }
package org.zttc.itat.auth.model; public class Role implements Principal{ public static final String PRINCIPAL_TYPE="role"; private int id; private String name; private String sn; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSn() { return sn; } public void setSn(String sn) { this.sn = sn; } }
package org.zttc.itat.auth.model; public class ServiceController implements SystemResource{ }
package org.zttc.itat.auth.model; /** * 资源对象的声明式接口 * @author hfw2192 * */ public interface SystemResource { }
package org.zttc.itat.auth.model; /** * 用户主体 * @author hfw2192 * */ public class User implements Principal{ public static final String PRINCIPAL_TYPE="user"; private int id; private String username; private String password; private String nickname; private int state; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public int getState() { return state; } public void setState(int state) { this.state = state; } }
package org.zttc.itat.auth.model; /** * 用户和角色的关联表 * @author hfw2192 * */ public class UserRole { private int id; private User user; private Role role; public int getId() { return id; } public void setId(int id) { this.id = id; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Role getRole() { return role; } public void setRole(Role role) { this.role = role; } }
package org.zttc.itat.auth.model;
/**
* 菜单资源
* @author hfw2192
*
*/
public class MenuResource implements SystemResource{
public static final String RESOURCE_TYPE = "menu";
/**
*
*/
private int id;
/**
* 菜单的名称,中文名称
*/
private String name;
/**
* 菜单的sn,不能重复,讲来要通过这个sn,自动生成页面的超链接,然后为超链接增加一个属性auth_sn,
* 其属性值就是sn
*/
private String sn;
/**
* 菜单所在的位置
*/
private MenuPos menuPos;
/**
* 菜单的超链接
*/
private String href;
/**
* 菜单的图标
*/
private String icon;
/**
* 菜单的排序号
*/
private int orderNum;
/**
* 是否显示菜单,1表示显示,-1表示不显示
*/
private int display;
/**
* 菜单的父类sn,方便初始化的时候做操作
*/
private String psn;
/**
* 菜单的父类菜单,在授权的时候比较方便
*/
private MenuResource parent;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public MenuPos getMenuPos() {
return menuPos;
}
public void setMenuPos(MenuPos menuPos) {
this.menuPos = menuPos;
}
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public int getOrderNum() {
return orderNum;
}
public void setOrderNum(int orderNum) {
this.orderNum = orderNum;
}
public String getPsn() {
return psn;
}
public void setPsn(String psn) {
this.psn = psn;
}
public int getDisplay() {
return display;
}
public void setDisplay(int display) {
this.display = display;
}
public MenuResource getParent() {
return parent;
}
public void setParent(MenuResource parent) {
this.parent = parent;
}
}