├── privilege-api-server ├── src │ ├── main │ │ ├── resources │ │ │ ├── config.properties │ │ │ ├── log4j.xml │ │ │ ├── applicationContext-dubbo.xml │ │ │ └── applicationContext.xml │ │ ├── webapp │ │ │ ├── index.jsp │ │ │ └── WEB-INF │ │ │ │ └── web.xml │ │ └── java │ │ │ └── com │ │ │ └── cl │ │ │ └── privilege │ │ │ ├── utils │ │ │ └── SpringContextHolder.java │ │ │ └── api │ │ │ └── impl │ │ │ └── PrivilegeBaseApiServiceImpl.java │ └── test │ │ ├── resources │ │ ├── config.properties │ │ └── applicationContext-test.xml │ │ └── java │ │ └── com │ │ └── cl │ │ └── privilege │ │ └── api │ │ └── impl │ │ └── test │ │ └── PrivilegeBaseApiServiceImplTest.java └── pom.xml ├── privilege-server ├── src │ └── main │ │ ├── webapp │ │ ├── index.html │ │ ├── WEB-INF │ │ │ ├── ftl │ │ │ │ ├── footer.ftl │ │ │ │ ├── sidebar.ftl │ │ │ │ ├── role │ │ │ │ │ ├── assignform.ftl │ │ │ │ │ ├── addform.ftl │ │ │ │ │ └── updateform.ftl │ │ │ │ ├── user │ │ │ │ │ ├── assignform.ftl │ │ │ │ │ ├── addform.ftl │ │ │ │ │ └── updateform.ftl │ │ │ │ ├── header.ftl │ │ │ │ ├── modifypasswordform.ftl │ │ │ │ └── main.ftl │ │ │ ├── springmvc-servlet.xml │ │ │ └── web.xml │ │ └── scripts │ │ │ └── custom │ │ │ └── cl.js │ │ ├── resources │ │ ├── config.properties │ │ ├── cas-privilege.xml │ │ ├── applicationContext-dubbo.xml │ │ ├── log4j.xml │ │ ├── applicationContext.xml │ │ └── log4j.dtd │ │ └── java │ │ └── com │ │ └── cl │ │ └── privilege │ │ ├── utils │ │ ├── ConstantUtil.java │ │ ├── ConfigUtil.java │ │ ├── SessionUtil.java │ │ ├── SpringContextHolder.java │ │ └── JsonUtil.java │ │ ├── biz │ │ ├── IModuleService.java │ │ ├── impl │ │ │ ├── ModuleServiceImpl.java │ │ │ ├── UserServiceImpl.java │ │ │ ├── RoleServiceImpl.java │ │ │ └── ResourceServiceImpl.java │ │ ├── IDepartmentService.java │ │ ├── IResourceService.java │ │ ├── IUserService.java │ │ └── IRoleService.java │ │ ├── interceptor │ │ └── PrivilegeInterceptor.java │ │ └── controller │ │ ├── IndexController.java │ │ ├── DepartmentController.java │ │ ├── ResourceController.java │ │ ├── RoleController.java │ │ └── UserController.java └── pom.xml ├── privilege-model ├── src │ └── main │ │ └── java │ │ └── com │ │ └── cl │ │ └── privilege │ │ └── model │ │ ├── PrivilegeModelConstant.java │ │ ├── UserRole.java │ │ ├── RoleModule.java │ │ ├── RoleResource.java │ │ ├── RoleSearchModel.java │ │ ├── UserSearchModel.java │ │ ├── Role.java │ │ ├── Module.java │ │ ├── Department.java │ │ ├── Resource.java │ │ └── User.java └── pom.xml ├── privilege-data ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── cl │ │ │ └── privilege │ │ │ └── mapper │ │ │ ├── UserRoleMapper.java │ │ │ ├── RoleModuleMapper.java │ │ │ ├── RoleResourceMapper.java │ │ │ ├── DepartmentMapper.java │ │ │ ├── ModuleMapper.java │ │ │ ├── ResourceMapper.java │ │ │ ├── UserMapper.java │ │ │ └── RoleMapper.java │ │ └── resources │ │ └── com │ │ └── cl │ │ └── privilege │ │ └── mapper │ │ ├── UserRoleMapper.xml │ │ ├── RoleModuleMapper.xml │ │ ├── RoleResourceMapper.xml │ │ ├── ModuleMapper.xml │ │ ├── DepartmentMapper.xml │ │ └── RoleMapper.xml └── pom.xml ├── privilege-api ├── src │ └── main │ │ └── java │ │ └── com │ │ └── cl │ │ └── privilege │ │ └── api │ │ └── IPrivilegeBaseApiService.java └── pom.xml ├── .gitignore ├── pom.xml ├── README.md └── config_privilege.xml /privilege-api-server/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=127.0.0.1:2181 3 | dubbo.registry.address.client=127.0.0.1:2181 -------------------------------------------------------------------------------- /privilege-api-server/src/test/resources/config.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=127.0.0.1:2181 3 | dubbo.registry.address.client=127.0.0.1:2181 -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/PrivilegeModelConstant.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | public class PrivilegeModelConstant { 4 | 5 | /** 6 | * 分页,每页记录数 7 | */ 8 | public static final Integer PageSize = 20; 9 | } 10 | -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/UserRoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import com.cl.privilege.model.UserRole; 4 | 5 | public interface UserRoleMapper { 6 | int insert(UserRole record); 7 | 8 | int insertSelective(UserRole record); 9 | } -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/RoleModuleMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import com.cl.privilege.model.RoleModule; 4 | 5 | public interface RoleModuleMapper { 6 | int insert(RoleModule record); 7 | 8 | int insertSelective(RoleModule record); 9 | } -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/RoleResourceMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import com.cl.privilege.model.RoleResource; 4 | 5 | public interface RoleResourceMapper { 6 | int insert(RoleResource record); 7 | 8 | int insertSelective(RoleResource record); 9 | } -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/footer.ftl: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /privilege-api/src/main/java/com/cl/privilege/api/IPrivilegeBaseApiService.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.api; 2 | 3 | import com.cl.privilege.model.User; 4 | 5 | public interface IPrivilegeBaseApiService { 6 | 7 | User getUserByUsername(String username); 8 | 9 | String getModuleTree(Integer userId,String visitedModule,String visitedResource); 10 | 11 | Integer updateUserById(User user); 12 | } 13 | -------------------------------------------------------------------------------- /privilege-server/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | #CAS authentication address 2 | cas.server.url=http://127.0.0.1:8080/cas 3 | cas.service.url=http://127.0.0.1:10002/privilege-server 4 | 5 | #Base Path 6 | web.basepath=http://127.0.0.1:10002/privilege-server 7 | #Inc File Path 8 | inc.basepath=http://127.0.0.1/privilege_inc 9 | 10 | #ZooKeeper 11 | dubbo.registry.address=127.0.0.1:2181 12 | dubbo.registry.address.client=127.0.0.1:2181 -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/utils/ConstantUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.utils; 2 | 3 | public class ConstantUtil { 4 | 5 | public static final String Fail = "fail"; 6 | 7 | public static final String Success = "success"; 8 | 9 | public static final String Exists = "exists"; 10 | 11 | public static final String EmptyJsonObject = "{}"; 12 | 13 | public static final String DefaultMd5Password = "63a9f0ea7bb98050796b649e85481845"; //root 14 | } 15 | -------------------------------------------------------------------------------- /privilege-model/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | cl 5 | privilege 6 | 1.0.0-SNAPSHOT 7 | 8 | privilege-model 9 | privilege-model 10 | jar 11 | -------------------------------------------------------------------------------- /privilege-api-server/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=GB2312" %> 2 | <%@page import="com.cl.privilege.utils.SpringContextHolder"%> 3 | <%@page import="com.cl.privilege.api.IPrivilegeBaseApiService"%> 4 | <%@page import="com.cl.privilege.api.impl.PrivilegeBaseApiServiceImpl"%> 5 | 6 | 7 | 8 | 9 | <% 10 | //测试MyBatis:Success 11 | IPrivilegeBaseApiService us = SpringContextHolder.getBean(IPrivilegeBaseApiService.class); 12 | out.print(us.getModuleTree(0,"p","")); 13 | %> 14 | 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # Ignore all logfiles and tempfiles. 15 | .project 16 | /*/.project 17 | 18 | .classpath 19 | /*/.classpath 20 | 21 | .settings 22 | /*/.settings 23 | /*/.settings/* 24 | 25 | target 26 | /*/target 27 | /*/target/* 28 | 29 | .DS_Store 30 | 31 | .svn 32 | .svn/* 33 | 34 | .idea 35 | .idea/* 36 | 37 | Thumbs.db 38 | 39 | *.log 40 | *.out 41 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/UserRole.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class UserRole implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private Integer userId; 10 | 11 | private Integer roleId; 12 | 13 | public Integer getUserId() { 14 | return userId; 15 | } 16 | 17 | public void setUserId(Integer userId) { 18 | this.userId = userId; 19 | } 20 | 21 | public Integer getRoleId() { 22 | return roleId; 23 | } 24 | 25 | public void setRoleId(Integer roleId) { 26 | this.roleId = roleId; 27 | } 28 | } -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/RoleModule.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class RoleModule implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private Integer roleId; 10 | 11 | private Integer moduleId; 12 | 13 | public Integer getRoleId() { 14 | return roleId; 15 | } 16 | 17 | public void setRoleId(Integer roleId) { 18 | this.roleId = roleId; 19 | } 20 | 21 | public Integer getModuleId() { 22 | return moduleId; 23 | } 24 | 25 | public void setModuleId(Integer moduleId) { 26 | this.moduleId = moduleId; 27 | } 28 | } -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/RoleResource.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class RoleResource implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private Integer roleId; 10 | 11 | private Integer resourceId; 12 | 13 | public Integer getRoleId() { 14 | return roleId; 15 | } 16 | 17 | public void setRoleId(Integer roleId) { 18 | this.roleId = roleId; 19 | } 20 | 21 | public Integer getResourceId() { 22 | return resourceId; 23 | } 24 | 25 | public void setResourceId(Integer resourceId) { 26 | this.resourceId = resourceId; 27 | } 28 | } -------------------------------------------------------------------------------- /privilege-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | cl 7 | privilege 8 | 1.0.0-SNAPSHOT 9 | 10 | privilege-api 11 | privilege-api 12 | jar 13 | 14 | 15 | 16 | 17 | cl 18 | privilege-model 19 | 1.0.0-SNAPSHOT 20 | 21 | 22 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/IModuleService.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz; 2 | 3 | import java.util.List; 4 | 5 | import com.cl.privilege.model.Module; 6 | 7 | /** 8 | * 模块表相关操作 9 | */ 10 | public interface IModuleService { 11 | 12 | /** 13 | * 获取所有Module 14 | * @return 15 | */ 16 | List getModuleList(); 17 | 18 | /** 19 | * 根据flag获取Module 20 | * @param flag 21 | * @return 22 | */ 23 | List getModuleListByFlag(String flag); 24 | 25 | /** 26 | * 查询roleId具有权限的模块列表 27 | * @param roleId 28 | * @return 29 | */ 30 | List getModuleListByRoleId(Integer roleId); 31 | 32 | /** 33 | * 查询userId具有权限的模块列表 34 | * @param userId 35 | * @return 36 | */ 37 | List getModuleListByUserId(Integer userId); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/sidebar.ftl: -------------------------------------------------------------------------------- 1 | 2 |
3 | 24 |
25 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/utils/ConfigUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.utils; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class ConfigUtil { 8 | 9 | private @Value("${cas.server.url}")String casServerUrl; 10 | private @Value("${cas.service.url}")String casServiceUrl; 11 | private @Value("${web.basepath}")String basePath; 12 | private @Value("${inc.basepath}")String incBasePath; 13 | 14 | public String getCasServerUrl() { 15 | return casServerUrl; 16 | } 17 | 18 | public String getCasServiceUrl() { 19 | return casServiceUrl; 20 | } 21 | 22 | public String getBasePath() { 23 | return basePath; 24 | } 25 | 26 | public String getIncBasePath() { 27 | return incBasePath; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/role/assignform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 16 | 17 | 22 | 23 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/RoleSearchModel.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 角色查询SearchModel 7 | */ 8 | public class RoleSearchModel implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Integer pageNo = 1; 13 | private Integer pageSize = PrivilegeModelConstant.PageSize; 14 | //角色名称 15 | private String name; 16 | 17 | public Integer getPageNo() { 18 | return pageNo; 19 | } 20 | public void setPageNo(Integer pageNo) { 21 | this.pageNo = pageNo; 22 | } 23 | public Integer getPageSize() { 24 | return pageSize; 25 | } 26 | public void setPageSize(Integer pageSize) { 27 | this.pageSize = pageSize; 28 | } 29 | public String getName() { 30 | return name; 31 | } 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/utils/SessionUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.utils; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpSession; 5 | 6 | import com.cl.privilege.model.User; 7 | 8 | 9 | public class SessionUtil { 10 | 11 | /** 12 | * 系统登录用户名 13 | */ 14 | public static final String SessionSystemLoginUserName = "SessionSystemLoginUserName"; 15 | 16 | /** 17 | * 清空session 18 | */ 19 | public static final void clearSession(HttpServletRequest request) 20 | { 21 | HttpSession session = request.getSession(); 22 | 23 | session.removeAttribute(SessionUtil.SessionSystemLoginUserName); 24 | 25 | session.invalidate();//非必须,单点登出接收到服务器消息时,会自动销毁session 26 | } 27 | 28 | /** 29 | * 返回session中的用户对象 30 | * @param request 31 | * @return 32 | */ 33 | public static final User getSessionUser(HttpServletRequest request) 34 | { 35 | return (User) request.getSession().getAttribute(SessionUtil.SessionSystemLoginUserName); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/DepartmentMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.cl.privilege.model.Department; 8 | 9 | public interface DepartmentMapper { 10 | int deleteByPrimaryKey(Integer id); 11 | 12 | int insert(Department record); 13 | 14 | int insertSelective(Department record); 15 | 16 | Department selectByPrimaryKey(Integer id); 17 | 18 | int updateByPrimaryKeySelective(Department record); 19 | 20 | int updateByPrimaryKey(Department record); 21 | 22 | // 以上是为了节约开发时间,使用MyBatisGenerator生成的代码 23 | // 以下是针对不足功能,添加的代码 24 | 25 | /** 26 | * 查询所有Department对象 27 | * @return 28 | */ 29 | List getDepartmentList(); 30 | /** 31 | * 查询所有Department对象 32 | * @return 33 | */ 34 | List getDepartmentListByParentId(@Param("parentId")Integer parentId); 35 | /** 36 | * 部门是否被用户使用 37 | * @param departmentId 38 | */ 39 | Boolean isUsedByUser(Integer departmentId); 40 | } -------------------------------------------------------------------------------- /privilege-data/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | cl 5 | privilege 6 | 1.0.0-SNAPSHOT 7 | 8 | privilege-data 9 | privilege-data 10 | jar 11 | 12 | 13 | 14 | 15 | cl 16 | privilege-model 17 | 1.0.0-SNAPSHOT 18 | 19 | 20 | 21 | org.mybatis 22 | mybatis 23 | 3.2.3 24 | 25 | 26 | org.mybatis 27 | mybatis-spring 28 | 1.2.0 29 | 30 | 31 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/UserSearchModel.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 用户查询SearchModel 7 | */ 8 | public class UserSearchModel implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Integer pageNo = 1; 13 | private Integer pageSize = PrivilegeModelConstant.PageSize; 14 | 15 | //登录用户名 16 | private String username; 17 | //真实姓名 18 | private String fullname; 19 | 20 | public Integer getPageNo() { 21 | return pageNo; 22 | } 23 | public void setPageNo(Integer pageNo) { 24 | this.pageNo = pageNo; 25 | } 26 | public Integer getPageSize() { 27 | return pageSize; 28 | } 29 | public void setPageSize(Integer pageSize) { 30 | this.pageSize = pageSize; 31 | } 32 | public String getUsername() { 33 | return username; 34 | } 35 | public void setUsername(String username) { 36 | this.username = username; 37 | } 38 | public String getFullname() { 39 | return fullname; 40 | } 41 | public void setFullname(String fullname) { 42 | this.fullname = fullname; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/impl/ModuleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.cl.privilege.biz.IModuleService; 9 | import com.cl.privilege.mapper.ModuleMapper; 10 | import com.cl.privilege.model.Module; 11 | 12 | @Service 13 | public class ModuleServiceImpl implements IModuleService { 14 | 15 | @Autowired 16 | private ModuleMapper moduleMapper; 17 | 18 | @Override 19 | public List getModuleList() 20 | { 21 | return moduleMapper.getModuleList(); 22 | } 23 | 24 | @Override 25 | public List getModuleListByFlag(String flag) 26 | { 27 | return moduleMapper.getModuleListByFlag(flag); 28 | } 29 | 30 | @Override 31 | public List getModuleListByRoleId(Integer roleId) 32 | { 33 | return moduleMapper.getModuleListByRoleId(roleId); 34 | } 35 | 36 | @Override 37 | public List getModuleListByUserId(Integer userId) 38 | { 39 | return moduleMapper.getModuleListByUserId(userId); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/ModuleMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.cl.privilege.model.Module; 8 | 9 | public interface ModuleMapper { 10 | int deleteByPrimaryKey(Integer id); 11 | 12 | int insert(Module record); 13 | 14 | int insertSelective(Module record); 15 | 16 | Module selectByPrimaryKey(Integer id); 17 | 18 | int updateByPrimaryKeySelective(Module record); 19 | 20 | int updateByPrimaryKey(Module record); 21 | 22 | // 以上是为了节约开发时间,使用MyBatisGenerator生成的代码 23 | // 以下是针对不足功能,添加的代码 24 | 25 | /** 26 | * 获取所有Module 27 | * @return 28 | */ 29 | List getModuleList(); 30 | 31 | /** 32 | * 根据flag获取Module 33 | * @param flag 34 | * @return 35 | */ 36 | List getModuleListByFlag(@Param("flag")String flag); 37 | 38 | /** 39 | * 查询roleId具有权限的模块列表 40 | * @param roleId 41 | * @return 42 | */ 43 | List getModuleListByRoleId(Integer roleId); 44 | 45 | /** 46 | * 查询userId具有权限的模块列表 47 | * @param userId 48 | * @return 49 | */ 50 | List getModuleListByUserId(Integer userId); 51 | } -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/user/assignform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 22 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /privilege-api-server/src/test/java/com/cl/privilege/api/impl/test/PrivilegeBaseApiServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.api.impl.test; 2 | 3 | import org.junit.After; 4 | import org.junit.Before; 5 | import org.junit.BeforeClass; 6 | import org.junit.Test; 7 | import org.springframework.context.support.ClassPathXmlApplicationContext; 8 | 9 | import com.cl.privilege.api.impl.PrivilegeBaseApiServiceImpl; 10 | import com.cl.privilege.model.User; 11 | 12 | 13 | 14 | public class PrivilegeBaseApiServiceImplTest { 15 | 16 | private static PrivilegeBaseApiServiceImpl service; 17 | 18 | @BeforeClass 19 | public static void setUpBeforeClass() throws Exception { 20 | ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-test.xml"); 21 | service = (PrivilegeBaseApiServiceImpl)ctx.getBean("privilegeBaseApiServiceImpl"); 22 | ctx.close(); 23 | } 24 | 25 | @Before 26 | public void setUp() throws Exception { 27 | } 28 | 29 | @After 30 | public void tearDown() throws Exception { 31 | } 32 | 33 | @Test 34 | public void getUserByUsername() { 35 | User user = service.getUserByUsername("root"); 36 | if(user == null) 37 | { 38 | System.out.println("user is null"); 39 | } else { 40 | System.out.println("user is not null"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /privilege-server/src/main/resources/cas-privilege.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /privilege-server/src/main/resources/applicationContext-dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Dubbo provider配置 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | -------------------------------------------------------------------------------- /privilege-api-server/src/main/java/com/cl/privilege/utils/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.utils; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.ApplicationContextAware; 5 | 6 | public class SpringContextHolder implements ApplicationContextAware { 7 | 8 | private static ApplicationContext applicationContext; 9 | 10 | public void setApplicationContext(ApplicationContext ac) 11 | { 12 | applicationContext = ac; 13 | } 14 | 15 | public static ApplicationContext getApplicationContext() 16 | { 17 | checkApplicationContext(); 18 | return applicationContext; 19 | } 20 | 21 | @SuppressWarnings("unchecked") 22 | public static T getBean(String name) 23 | { 24 | checkApplicationContext(); 25 | return (T) applicationContext.getBean(name); 26 | } 27 | 28 | public static T getBean(Class requiredType) 29 | { 30 | checkApplicationContext(); 31 | return applicationContext.getBean(requiredType); 32 | } 33 | 34 | public static void cleanApplicationContext() 35 | { 36 | applicationContext = null; 37 | } 38 | 39 | private static void checkApplicationContext() { 40 | if (applicationContext == null) 41 | throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder"); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/utils/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.utils; 2 | 3 | 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | 7 | public class SpringContextHolder implements ApplicationContextAware { 8 | 9 | private static ApplicationContext applicationContext; 10 | 11 | public void setApplicationContext(ApplicationContext ac) 12 | { 13 | applicationContext = ac; 14 | } 15 | 16 | public static ApplicationContext getApplicationContext() 17 | { 18 | checkApplicationContext(); 19 | return applicationContext; 20 | } 21 | 22 | @SuppressWarnings("unchecked") 23 | public static T getBean(String name) 24 | { 25 | checkApplicationContext(); 26 | return (T) applicationContext.getBean(name); 27 | } 28 | 29 | public static T getBean(Class requiredType) 30 | { 31 | checkApplicationContext(); 32 | return applicationContext.getBean(requiredType); 33 | } 34 | 35 | public static void cleanApplicationContext() 36 | { 37 | applicationContext = null; 38 | } 39 | 40 | private static void checkApplicationContext() { 41 | if (applicationContext == null) 42 | throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder"); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | cl 4 | privilege 5 | 1.0.0-SNAPSHOT 6 | pom 7 | privilege 8 | http://maven.apache.org 9 | 10 | 11 | privilege-model 12 | privilege-data 13 | privilege-api 14 | privilege-server 15 | privilege-api-server 16 | 17 | 18 | 19 | 20 | junit 21 | junit 22 | 4.11 23 | test 24 | 25 | 26 | 27 | 28 | 29 | releases 30 | Cl Releases 31 | http://192.168.1.11:8081/nexus/content/repositories/releases 32 | 33 | 34 | snapshots 35 | Cl Snapshots 36 | http://192.168.1.11:8081/nexus/content/repositories/snapshots 37 | 38 | 39 | -------------------------------------------------------------------------------- /privilege-data/src/main/resources/com/cl/privilege/mapper/UserRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | insert into p_user_role (user_id, role_id) 10 | values (#{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}) 11 | 12 | 13 | insert into p_user_role 14 | 15 | 16 | user_id, 17 | 18 | 19 | role_id, 20 | 21 | 22 | 23 | 24 | #{userId,jdbcType=INTEGER}, 25 | 26 | 27 | #{roleId,jdbcType=INTEGER}, 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /privilege-data/src/main/resources/com/cl/privilege/mapper/RoleModuleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | insert into p_role_module (role_id, module_id) 10 | values (#{roleId,jdbcType=INTEGER}, #{moduleId,jdbcType=INTEGER}) 11 | 12 | 13 | insert into p_role_module 14 | 15 | 16 | role_id, 17 | 18 | 19 | module_id, 20 | 21 | 22 | 23 | 24 | #{roleId,jdbcType=INTEGER}, 25 | 26 | 27 | #{moduleId,jdbcType=INTEGER}, 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /privilege-data/src/main/resources/com/cl/privilege/mapper/RoleResourceMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | insert into p_role_resource (role_id, resource_id) 10 | values (#{roleId,jdbcType=INTEGER}, #{resourceId,jdbcType=INTEGER}) 11 | 12 | 13 | insert into p_role_resource 14 | 15 | 16 | role_id, 17 | 18 | 19 | resource_id, 20 | 21 | 22 | 23 | 24 | #{roleId,jdbcType=INTEGER}, 25 | 26 | 27 | #{resourceId,jdbcType=INTEGER}, 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/IDepartmentService.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz; 2 | 3 | import java.util.List; 4 | 5 | import com.cl.privilege.model.Department; 6 | import com.cl.privilege.model.User; 7 | 8 | 9 | /** 10 | * 部门表相关操作 11 | */ 12 | public interface IDepartmentService { 13 | 14 | /** 15 | * 查询所有Department对象 16 | * @return 17 | */ 18 | List getDepartmentList(); 19 | 20 | /** 21 | * 根据id获取Department对象 22 | * @param id 23 | * @return 24 | */ 25 | Department getDepartmentById(Integer id); 26 | 27 | /** 28 | * 新增记录 29 | * @param department 30 | * @param user 31 | * @return 32 | */ 33 | Integer createDepartment(Department department,User user); 34 | 35 | /** 36 | * 根据id修改一条记录 37 | * @param department 38 | * @param user 39 | * @return 40 | */ 41 | Integer updateDepartmentById(Department department,User user); 42 | 43 | /** 44 | * 根据id删除一条记录 45 | * @param id 46 | * @return 47 | */ 48 | Integer deleteDepartmentById(Integer id); 49 | 50 | /** 51 | * 部门是否被用户使用 52 | * @param departmentId 53 | */ 54 | Boolean isUsedByUser(Integer departmentId); 55 | 56 | /** 57 | * 获取部门树 58 | * @return 59 | */ 60 | String getDepartmentTree(); 61 | 62 | /** 63 | * 获取Select控件中Options需要的List 64 | * @return 65 | */ 66 | List getDepartmentListForOption(); 67 | } 68 | -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/ResourceMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.cl.privilege.model.Resource; 8 | 9 | public interface ResourceMapper { 10 | int deleteByPrimaryKey(Integer id); 11 | 12 | int insert(Resource record); 13 | 14 | int insertSelective(Resource record); 15 | 16 | Resource selectByPrimaryKey(Integer id); 17 | 18 | int updateByPrimaryKeySelective(Resource record); 19 | 20 | int updateByPrimaryKey(Resource record); 21 | 22 | // 以上是为了节约开发时间,使用MyBatisGenerator生成的代码 23 | // 以下是针对不足功能,添加的代码 24 | 25 | /** 26 | * 获取所有resource 27 | * @return 28 | */ 29 | List getResourceList(); 30 | 31 | /** 32 | * 根据所属模块获取资源 33 | * @return 34 | */ 35 | List getResourceListByModuleFlag(@Param("moduleFlags")List moduleFlags,@Param("userId")Integer userId); 36 | 37 | /** 38 | * 根据资源id判断是否被角色使用 39 | * @param resourceId 40 | * @return 41 | */ 42 | Boolean isUsedByRole(@Param("resourceId") Integer resourceId); 43 | 44 | /** 45 | * 给定角色具有权限的资源列表 46 | * @param roleId 47 | * @return 48 | */ 49 | List getResourceListByRoleId(Integer roleId); 50 | 51 | /** 52 | * 根据parentId获取资源 53 | * @param parentId 54 | * @return 55 | */ 56 | List getResourceListByParentId(@Param("parentId")Integer parentId); 57 | } -------------------------------------------------------------------------------- /privilege-server/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /privilege-api-server/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.session.RowBounds; 7 | 8 | import com.cl.privilege.model.User; 9 | import com.cl.privilege.model.UserSearchModel; 10 | 11 | 12 | public interface UserMapper { 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(User record); 16 | 17 | int insertSelective(User record); 18 | 19 | User selectByPrimaryKey(Integer id); 20 | 21 | int updateByPrimaryKeySelective(User record); 22 | 23 | int updateByPrimaryKey(User record); 24 | 25 | // 以上是为了节约开发时间,使用MyBatisGenerator生成的代码 26 | // 以下是针对不足功能,添加的代码 27 | 28 | /** 29 | * 根据用户名查询用户 30 | * @param username 31 | * @return 32 | */ 33 | User getUserByUsername(@Param("username")String username); 34 | 35 | /** 36 | * 根据条件查询用户总数 37 | * @param searchModel 38 | * @return 39 | */ 40 | Integer getUserTotalBySearch(UserSearchModel searchModel); 41 | 42 | /** 43 | * 根据条件查询用户List 44 | * @param searchModel 45 | * @return 46 | */ 47 | List getUserListBySearch(UserSearchModel searchModel,RowBounds rowBounds); 48 | 49 | /** 50 | * 根据id删除用户关联的角色 51 | * @param id 52 | * @return 53 | */ 54 | Integer deleteUserRoleById(Integer id); 55 | 56 | /** 57 | * 对用户赋予角色 58 | * @param roleIds 59 | * @param userId 60 | */ 61 | void assignRoles(@Param("roleIds")List roleIds,@Param("userId")Integer userId); 62 | } -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/role/addform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 36 | 37 | 41 | 42 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/role/updateform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 36 | 37 | 41 | 42 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/IResourceService.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz; 2 | 3 | import java.util.List; 4 | 5 | import com.cl.privilege.model.Resource; 6 | import com.cl.privilege.model.User; 7 | 8 | public interface IResourceService { 9 | 10 | /** 11 | * 获取所有Resource 12 | * @return 13 | */ 14 | List getResourceList(); 15 | 16 | /** 17 | * 根据所属模块获取资源 18 | * @return 19 | */ 20 | List getResourceListByModuleFlag(List moduleFlags,Integer userId); 21 | 22 | /** 23 | * 根据id获取Resource对象 24 | * @param id 25 | * @return 26 | */ 27 | Resource getResourceById(Integer id); 28 | 29 | /** 30 | * 新增记录 31 | * @param resource 32 | * @param user 33 | * @return 34 | */ 35 | Integer createResource(Resource resource,User user); 36 | 37 | /** 38 | * 根据id修改一条记录 39 | * @param resource 40 | * @param user 41 | * @return 42 | */ 43 | Integer updateResourceById(Resource resource,User user); 44 | 45 | /** 46 | * 根据id删除一条resource 47 | * @param id 48 | * @return 49 | */ 50 | Integer deleteResourceById(Integer id); 51 | 52 | /** 53 | * 根据资源id判断是否被角色使用 54 | * @param resourceId 55 | * @return 56 | */ 57 | Boolean isUsedByRole(Integer resourceId); 58 | 59 | /** 60 | * 给定角色具有权限的资源列表 61 | * @param roleId 62 | * @return 63 | */ 64 | List getResourceListByRoleId(Integer roleId); 65 | 66 | /** 67 | * 获取菜单资源树 68 | * @param roleId 如果传入roleId,则对此roleId用户的相关模块和菜单资源选中 69 | * @return 70 | */ 71 | String getResourceTree(Integer roleId); 72 | } 73 | -------------------------------------------------------------------------------- /privilege-api-server/src/main/resources/applicationContext-dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | Dubbo provider配置 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/Role.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Role implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Integer id; 11 | 12 | private String name; 13 | 14 | private String remark; 15 | 16 | private String createPerson; 17 | 18 | private Date createDate; 19 | 20 | private String updatePerson; 21 | 22 | private Date updateDate; 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getRemark() { 41 | return remark; 42 | } 43 | 44 | public void setRemark(String remark) { 45 | this.remark = remark; 46 | } 47 | 48 | public String getCreatePerson() { 49 | return createPerson; 50 | } 51 | 52 | public void setCreatePerson(String createPerson) { 53 | this.createPerson = createPerson; 54 | } 55 | 56 | public Date getCreateDate() { 57 | return createDate; 58 | } 59 | 60 | public void setCreateDate(Date createDate) { 61 | this.createDate = createDate; 62 | } 63 | 64 | public String getUpdatePerson() { 65 | return updatePerson; 66 | } 67 | 68 | public void setUpdatePerson(String updatePerson) { 69 | this.updatePerson = updatePerson; 70 | } 71 | 72 | public Date getUpdateDate() { 73 | return updateDate; 74 | } 75 | 76 | public void setUpdateDate(Date updateDate) { 77 | this.updateDate = updateDate; 78 | } 79 | } -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz; 2 | 3 | import java.util.List; 4 | 5 | import com.cl.privilege.model.User; 6 | import com.cl.privilege.model.UserSearchModel; 7 | 8 | 9 | 10 | /** 11 | * 用户表相关操作 12 | */ 13 | public interface IUserService { 14 | 15 | /** 16 | * 根据用户名查询用户 17 | * @param username 18 | * @return 19 | */ 20 | User getUserByUsername(String username); 21 | 22 | /** 23 | * 根据id查询用户 24 | * @param id 25 | * @return 26 | */ 27 | User getUserById(Integer id); 28 | 29 | /** 30 | * 根据条件查询用户总数 31 | * @param searchModel 32 | * @return 33 | */ 34 | Integer getUserTotalBySearch(UserSearchModel searchModel); 35 | 36 | /** 37 | * 根据条件查询用户List 38 | * @param searchModel 39 | * @return 40 | */ 41 | List getUserListBySearch(UserSearchModel searchModel); 42 | 43 | /** 44 | * 新增用户 45 | * @param user 46 | * @param operator 47 | * @return 48 | */ 49 | Integer createUser(User user,User operator); 50 | 51 | /** 52 | * 根据id更新用户 53 | * @param user 54 | * @param operator 55 | * @return 56 | */ 57 | Integer updateUserById(User user,User operator); 58 | 59 | /** 60 | * 根据id删除用户 61 | * @param id 62 | * @return 63 | */ 64 | Integer deleteUserById(Integer id,User operator); 65 | 66 | /** 67 | * 用户赋予角色 68 | * @param id 69 | * @param selectedStr 70 | * @return 71 | */ 72 | String assignRole(Integer id,String selectedStr); 73 | 74 | /** 75 | * 根据查询条件,返回DataTables控件需要的Json数据格式 76 | * @param searchModel 77 | * @return 78 | */ 79 | String getUserDataTables(UserSearchModel searchModel); 80 | 81 | /** 82 | * 返回DataTables控件需要的一行Json数据格式 83 | * @param id 84 | * @return 85 | */ 86 | String getUserDataRow(Integer id); 87 | } 88 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/interceptor/PrivilegeInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.interceptor; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.jasig.cas.client.util.AssertionHolder; 7 | import org.jasig.cas.client.validation.Assertion; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 10 | 11 | import com.cl.privilege.api.IPrivilegeBaseApiService; 12 | import com.cl.privilege.model.User; 13 | import com.cl.privilege.utils.ConfigUtil; 14 | import com.cl.privilege.utils.SessionUtil; 15 | 16 | 17 | /** 18 | * 拦截指定path,进行权限验证,及用户的本地session过期后,重新进行赋值 19 | */ 20 | public class PrivilegeInterceptor extends HandlerInterceptorAdapter { 21 | 22 | @Autowired 23 | private ConfigUtil configUtil; 24 | @Autowired 25 | private IPrivilegeBaseApiService privilegeBaseApiService; 26 | 27 | @Override 28 | public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception { 29 | 30 | Assertion assertion=AssertionHolder.getAssertion(); 31 | 32 | //实际cas-client-core中org.jasig.cas.client.authentication.AuthenticationFilter已经进行了单点登录认证,这里主要是为了获得用户信息 33 | if(assertion==null 34 | || assertion.getPrincipal()==null 35 | || assertion.getPrincipal().getName()==null) 36 | { 37 | //没有登录,跳转到没有登录页面 38 | response.sendRedirect(configUtil.getCasServerUrl()); 39 | return false; 40 | } 41 | 42 | User user = SessionUtil.getSessionUser(request); 43 | 44 | if(user == null) 45 | { 46 | //存储Session:用户登录名 47 | user = privilegeBaseApiService.getUserByUsername(assertion.getPrincipal().getName()); 48 | request.getSession().setAttribute(SessionUtil.SessionSystemLoginUserName,user); 49 | } 50 | 51 | //判断权限,没有权限,进入没有权限页面 52 | 53 | return true; 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/header.ftl: -------------------------------------------------------------------------------- 1 | 2 | 50 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/modifypasswordform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 49 | 50 | 54 | 55 | -------------------------------------------------------------------------------- /privilege-data/src/main/java/com/cl/privilege/mapper/RoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.session.RowBounds; 7 | 8 | import com.cl.privilege.model.Role; 9 | import com.cl.privilege.model.RoleSearchModel; 10 | 11 | 12 | public interface RoleMapper { 13 | int deleteByPrimaryKey(Integer id); 14 | 15 | int insert(Role record); 16 | 17 | int insertSelective(Role record); 18 | 19 | Role selectByPrimaryKey(Integer id); 20 | 21 | int updateByPrimaryKeySelective(Role record); 22 | 23 | int updateByPrimaryKey(Role record); 24 | 25 | // 以上是为了节约开发时间,使用MyBatisGenerator生成的代码 26 | // 以下是针对不足功能,添加的代码 27 | 28 | /** 29 | * 根据id删除角色 30 | * @param id 31 | * @return 32 | */ 33 | Integer deleteRoleById(Integer id); 34 | 35 | /** 36 | * 根据id删除角色模块关联关系 37 | * @param roleId 38 | * @return 39 | */ 40 | Integer deleteRoleModuleById(Integer roleId); 41 | 42 | /** 43 | * 根据id删除角色资源关联关系 44 | * @param roleId 45 | * @return 46 | */ 47 | Integer deleteRoleResourceById(Integer roleId); 48 | 49 | /** 50 | * 根据条件查询角色列表总数 51 | * @param searchModel 52 | * @return 53 | */ 54 | Integer getRoleTotalBySearch(RoleSearchModel searchModel); 55 | 56 | /** 57 | * 根据条件查询用户List 58 | * @param searchModel 59 | * @return 60 | */ 61 | List getRoleListBySearch(RoleSearchModel searchModel,RowBounds rowBounds); 62 | 63 | /** 64 | * 角色是否被用户使用 65 | * @param roleId 66 | * @return 67 | */ 68 | Boolean isUsedByUser(Integer roleId); 69 | 70 | /** 71 | * 分配角色关联模块 72 | * @param moduleIds 73 | * @param roleId 74 | */ 75 | void assignModules(@Param("moduleIds")List moduleIds,@Param("roleId")Integer roleId); 76 | 77 | /** 78 | * 分配角色关联资源 79 | * @param resourceIds 80 | * @param roleId 81 | */ 82 | void assignResources(@Param("resourceIds")List resourceIds,@Param("roleId")Integer roleId); 83 | 84 | /** 85 | * 根据userId获取关联的权限列表 86 | * @param userId 87 | * @return 88 | */ 89 | List getRoleListByUserId(@Param("userId")Integer userId); 90 | 91 | /** 92 | * 所有角色列表 93 | * @return 94 | */ 95 | List getRoleList(); 96 | } -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/utils/JsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.Collection; 5 | 6 | 7 | public class JsonUtil { 8 | 9 | public static StringBuffer convertObj2json(Collection cs) { 10 | 11 | StringBuffer sbf = new StringBuffer(); 12 | 13 | if (null == cs || 0 == cs.toArray().length){ 14 | 15 | return sbf.append("[").append("]"); 16 | } 17 | 18 | Object[] ls = cs.toArray(); 19 | int size = ls.length; 20 | 21 | sbf.append("["); 22 | if (0 == size) 23 | return new StringBuffer("[]"); 24 | for (int k = 0; k < size; k++) { 25 | Object o = ls[k]; 26 | 27 | sbf.append(convertObj2json(o)); 28 | 29 | if (k < size - 1) 30 | sbf.append(", "); 31 | } 32 | 33 | return sbf.append("]"); 34 | 35 | } 36 | 37 | public static StringBuffer convertObj2json(Object o) { 38 | 39 | StringBuffer sbf = new StringBuffer(); 40 | if (null == o) 41 | return sbf; 42 | 43 | sbf.append("{"); 44 | Class classType = o.getClass(); 45 | Field[] fields = classType.getDeclaredFields(); 46 | 47 | int length = fields.length; 48 | 49 | for (int i = 0; i < length; i++) { 50 | 51 | String fieldName = fields[i].getName(); 52 | Class clazzType = fields[i].getType(); 53 | Package package1 = clazzType.getPackage(); 54 | Object fo = ReflectionUtil.getFieldValue(o, fieldName); 55 | 56 | if (!(fo instanceof Collection) 57 | && (clazzType.isPrimitive() || null == package1 58 | || package1.getName().equals("java.lang") || package1 59 | .getName().equals("java.util"))) { 60 | sbf.append("\"").append(fieldName).append("\":\"").append(fo) 61 | .append("\""); 62 | } else if (!(fo instanceof Collection)) { 63 | sbf.append("\"").append(fieldName).append("\":").append( 64 | convertObj2json(fo)); 65 | } 66 | 67 | if (fo instanceof Collection) { 68 | 69 | sbf.append("\"").append(fieldName).append("\":").append( 70 | convertObj2json((Collection) fo)); 71 | 72 | } 73 | 74 | if (i < length - 1) 75 | sbf.append(", "); 76 | 77 | } 78 | 79 | return sbf.append("}"); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/Module.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Module implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Integer id; 11 | 12 | private String name; 13 | 14 | private String flag; 15 | 16 | private String url; 17 | 18 | private Integer sortNo; 19 | 20 | private String createPerson; 21 | 22 | private Date createDate; 23 | 24 | private String updatePerson; 25 | 26 | private Date updateDate; 27 | 28 | public Integer getId() { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) { 33 | this.id = id; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | 44 | public String getFlag() { 45 | return flag; 46 | } 47 | 48 | public void setFlag(String flag) { 49 | this.flag = flag; 50 | } 51 | 52 | public String getUrl() { 53 | return url; 54 | } 55 | 56 | public void setUrl(String url) { 57 | this.url = url; 58 | } 59 | 60 | public Integer getSortNo() { 61 | return sortNo; 62 | } 63 | 64 | public void setSortNo(Integer sortNo) { 65 | this.sortNo = sortNo; 66 | } 67 | 68 | public String getCreatePerson() { 69 | return createPerson; 70 | } 71 | 72 | public void setCreatePerson(String createPerson) { 73 | this.createPerson = createPerson; 74 | } 75 | 76 | public Date getCreateDate() { 77 | return createDate; 78 | } 79 | 80 | public void setCreateDate(Date createDate) { 81 | this.createDate = createDate; 82 | } 83 | 84 | public String getUpdatePerson() { 85 | return updatePerson; 86 | } 87 | 88 | public void setUpdatePerson(String updatePerson) { 89 | this.updatePerson = updatePerson; 90 | } 91 | 92 | public Date getUpdateDate() { 93 | return updateDate; 94 | } 95 | 96 | public void setUpdateDate(Date updateDate) { 97 | this.updateDate = updateDate; 98 | } 99 | } -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/IRoleService.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz; 2 | 3 | import java.util.List; 4 | 5 | import com.cl.privilege.model.Role; 6 | import com.cl.privilege.model.RoleSearchModel; 7 | import com.cl.privilege.model.User; 8 | 9 | /** 10 | * 角色表相关操作 11 | */ 12 | public interface IRoleService { 13 | /** 14 | * 根据id获取Role对象 15 | * @param id 16 | * @return 17 | */ 18 | Role getRoleById(Integer id); 19 | 20 | /** 21 | * 新增记录 22 | * @param role 23 | * @param user 24 | * @return 25 | */ 26 | Integer createRole(Role role,User user); 27 | 28 | /** 29 | * 根据id修改一条记录 30 | * @param role 31 | * @return 32 | */ 33 | Integer updateRoleById(Role role,User user); 34 | 35 | /** 36 | * 根据id删除角色 37 | * @param id 38 | * @return 39 | */ 40 | Integer deleteRoleById(Integer id); 41 | 42 | /** 43 | * 根据条件查询角色列表总数 44 | * @return 45 | */ 46 | Integer getRoleTotalBySearch(RoleSearchModel searchModel); 47 | 48 | /** 49 | * 根据条件查询角色列表 50 | * @return 51 | */ 52 | List getRoleListBySearch(RoleSearchModel searchModel); 53 | 54 | /** 55 | * 角色是否被用户使用 56 | * @param roleId 57 | * @return 58 | */ 59 | Boolean isUsedByUser(Integer roleId); 60 | 61 | /** 62 | * 根据选择的字符串(,分割),对角色赋予模块和资源 63 | * @param roleId 64 | * @param checkedStr 65 | */ 66 | String assignModuleAndResource(Integer roleId,String checkedStr); 67 | 68 | /** 69 | * 根据userId获取关联的权限列表 70 | * @param userId 71 | * @return 72 | */ 73 | List getRoleListByUserId(Integer userId); 74 | 75 | /** 76 | * 所有角色列表 77 | * @return 78 | */ 79 | List getRoleList(); 80 | 81 | /** 82 | * 根据查询条件,返回DataTables控件需要的Json数据格式 83 | * @param searchModel 84 | * @return 85 | */ 86 | String getRoleDataTables(RoleSearchModel searchModel); 87 | 88 | /** 89 | * 返回DataTables控件需要的一行Json数据格式 90 | * @param id 91 | * @return 92 | */ 93 | String getRoleDataRow(Integer id); 94 | 95 | /** 96 | * 返回jquery-multi-select需要的options数据 97 | * @param userId 98 | * @return 99 | */ 100 | String getRoleForOptions(Integer userId); 101 | } 102 | -------------------------------------------------------------------------------- /privilege-api-server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | Cl Privilege Manage App Server 7 | 8 | webAppRootKey 9 | privilege-api-server.root 10 | 11 | 12 | contextConfigLocation 13 | 14 | classpath*:/applicationContext*.xml 15 | classpath*:/cas-authority.xml 16 | 17 | 18 | 19 | log4jConfigLocation 20 | /WEB-INF/classes/log4j.xml 21 | 22 | 23 | spring.profiles.default 24 | dev 25 | 26 | 27 | 28 | 29 | encodingFilter 30 | org.springframework.web.filter.CharacterEncodingFilter 31 | 32 | encoding 33 | UTF-8 34 | 35 | 36 | forceEncoding 37 | true 38 | 39 | 40 | 41 | encodingFilter 42 | *.do 43 | 44 | 45 | 46 | 47 | org.springframework.web.context.ContextLoaderListener 48 | 49 | 50 | 51 | 52 | dubbo 53 | com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet 54 | 1 55 | 56 | 57 | dubbo 58 | /hessian/* 59 | 60 | 61 | 62 | csv 63 | application/octet-stream 64 | 65 | 66 | 67 | index.html 68 | index.jsp 69 | 70 | 71 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/Department.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Department implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Integer id; 11 | 12 | private String name; 13 | 14 | private String remark; 15 | 16 | private Integer parentId; 17 | 18 | private String structure; 19 | 20 | private Integer sortNo; 21 | 22 | private String createPerson; 23 | 24 | private Date createDate; 25 | 26 | private String updatePerson; 27 | 28 | private Date updateDate; 29 | 30 | public Integer getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Integer id) { 35 | this.id = id; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public String getRemark() { 47 | return remark; 48 | } 49 | 50 | public void setRemark(String remark) { 51 | this.remark = remark; 52 | } 53 | 54 | public Integer getParentId() { 55 | return parentId; 56 | } 57 | 58 | public void setParentId(Integer parentId) { 59 | this.parentId = parentId; 60 | } 61 | 62 | public String getStructure() { 63 | return structure; 64 | } 65 | 66 | public void setStructure(String structure) { 67 | this.structure = structure; 68 | } 69 | 70 | public Integer getSortNo() { 71 | return sortNo; 72 | } 73 | 74 | public void setSortNo(Integer sortNo) { 75 | this.sortNo = sortNo; 76 | } 77 | 78 | public String getCreatePerson() { 79 | return createPerson; 80 | } 81 | 82 | public void setCreatePerson(String createPerson) { 83 | this.createPerson = createPerson; 84 | } 85 | 86 | public Date getCreateDate() { 87 | return createDate; 88 | } 89 | 90 | public void setCreateDate(Date createDate) { 91 | this.createDate = createDate; 92 | } 93 | 94 | public String getUpdatePerson() { 95 | return updatePerson; 96 | } 97 | 98 | public void setUpdatePerson(String updatePerson) { 99 | this.updatePerson = updatePerson; 100 | } 101 | 102 | public Date getUpdateDate() { 103 | return updateDate; 104 | } 105 | 106 | public void setUpdateDate(Date updateDate) { 107 | this.updateDate = updateDate; 108 | } 109 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cl-privilege 2 | ================== 3 | 4 | 通用权限管理系统 5 | 6 | 7 | 一、mybatis-generator 8 | 9 | ORM框架采用MyBatis,为了提高开发效率,先根据数据库表单结构自动生成Model和MyBatis相关类,生成命令如下: 10 | 11 | java -jar mybatis-generator-core-1.3.1.jar -configfile config_privilege.xml -overwrite 12 | 13 | 生成时需要把mybatis-generator-core-1.3.1.jar、mysql-connector-java-5.1.24-bin.jar、config_privilege.xml放到一个目录下,生成的相关类和XML会放置到CreateResult文件夹下面。 14 | 15 | 参考网址: 16 | http://www.mybatis.org/generator/ 17 | http://pan.baidu.com/s/1qW98L0C 18 | http://qiuguo0205.iteye.com/blog/819100 19 | http://jadethao.iteye.com/blog/1726115 20 | 21 | 二、Dubbo 22 | 23 | 客户端、服务器端通讯框架采用Dubbo,Dubbo官网:http://alibaba.github.io/dubbo-doc-static/Home-zh.htm 24 | 25 | 三、Jasig CAS 26 | 27 | 对于身份认证,采用单点登录系统:Jasig CAS,官网:http://www.jasig.org/cas 28 | 29 | 我对jasig server和client的jar进行了修改,达到目的: 30 | 31 | 1、对服务器的界面进行了修改,使用MetroNic这套模板;对服务器的认证方式做了更改,采用MySQL进行身份验证。 32 | 33 | 代码位置:https://github.com/pumadong/cas-server-3.5.2 34 | 35 | 2、对客户端进行了小调整,让登陆之后自动返回到登陆之前的页面 36 | 37 | 代码位置:https://github.com/pumadong/cas-client-3.2.1 38 | 39 | 四、Redis 40 | 41 | 对于服务器端,菜单树调用较为频繁,可以采用Redis缓存提高性能。当前暂无使用,在用做生产时可以考虑加上。 42 | 43 | 五、界面 44 | 45 | 采用了MetroNic2.0.2这套模板,官网:http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469 46 | 47 | 如果商用的话,这套模板是需要购买的,25美元。 48 | 49 | 因为MetroNic的assets目录中都是的静态资源文件,我没有把它放入权限相关项目,而是单独配置了一个Nginx访问地址:http://127.0.0.1/privilege_inc/assets/ 50 | 51 | assets的内容,可以到这里下载:http://pan.baidu.com/s/1qW98L0C 52 | 53 | 由于我们另配了assets地址,所以一些文件里面对于资源文件的地址要从相对路径改为绝对路径,比如:assets/scripts/core/app.js 54 | 55 | 六、Jquery插件 56 | 57 | jsTree : http://www.jstree.com/ 58 | 59 | jquery.validate : http://bassistance.de/jquery-plugins/jquery-plugin-validation http://docs.jquery.com/Plugins/Validation 60 | 61 | DataTables : http://datatables.net/ 62 | 63 | Bootstram Modals : http://www.w3cschool.cc/bootstrap/bootstrap-v2-modal-plugin.html 64 | 65 | 注意,在这个插件的使用过程中,用了Ajax,是不能跨域的,即使从localhost,调用127.0.0.1的页面也是不行的。 66 | 67 | colorbox : http://www.jacklmoore.com/colorbox/,用于弹出窗体,本系统使用的是MetroNic模板本身提供的模式(Bootstrap Modals)对话框,colorbox也是一种选择,这两种弹窗插件都比较好。 68 | 69 | jquery-multi-select : http://loudev.com/ 70 | 71 | 七、业务逻辑 72 | 73 | 对于模块,维护极少,不提供管理界面,手工操作数据库; 74 | 75 | 当前对于权限,仅控制到菜单级别,对于大多数系统来说,是适合的,如果需要更细致的权限级别,比如菜单里面的:CRUD,可以开发功能管理,实现步骤如下: 76 | 77 | a.当需要一个控制时,管理员根据名称、意义,定制一个权限号,根据业务要求分配给某些角色 78 | 79 | b.把权限号告知使用者,使用者根据此权限号,在程序中增加控制 80 | 81 | 八、其他 82 | 83 | 在datatable.js中,使用bootstrap_full_number分页方式,页码导航条宽度变得太高的问题,解决办法:bootstrap.min.css中,对于.pagination .li 去掉float:left之后,就好了。 84 | 85 | 在datatable.js中,对fnServerData段进行调整,用于向服务器端传递分页、查询等参数,同时也调整显示的提示文本内容。 86 | 87 | jqueyr.validate.js和jquery.validte.min.js中,调整提示文本显示。。 -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/springmvc-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | text/plain;charset=UTF-8 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/Resource.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Resource implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Integer id; 11 | 12 | private String name; 13 | 14 | private String url; 15 | 16 | private String remark; 17 | 18 | private Integer parentId; 19 | 20 | private String structure; 21 | 22 | private Integer sortNo; 23 | 24 | private String moduleFlag; 25 | 26 | private String createPerson; 27 | 28 | private Date createDate; 29 | 30 | private String updatePerson; 31 | 32 | private Date updateDate; 33 | 34 | public Integer getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Integer id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public String getUrl() { 51 | return url; 52 | } 53 | 54 | public void setUrl(String url) { 55 | this.url = url; 56 | } 57 | 58 | public String getRemark() { 59 | return remark; 60 | } 61 | 62 | public void setRemark(String remark) { 63 | this.remark = remark; 64 | } 65 | 66 | public Integer getParentId() { 67 | return parentId; 68 | } 69 | 70 | public void setParentId(Integer parentId) { 71 | this.parentId = parentId; 72 | } 73 | 74 | public String getStructure() { 75 | return structure; 76 | } 77 | 78 | public void setStructure(String structure) { 79 | this.structure = structure; 80 | } 81 | 82 | public Integer getSortNo() { 83 | return sortNo; 84 | } 85 | 86 | public void setSortNo(Integer sortNo) { 87 | this.sortNo = sortNo; 88 | } 89 | 90 | public String getModuleFlag() { 91 | return moduleFlag; 92 | } 93 | 94 | public void setModuleFlag(String moduleFlag) { 95 | this.moduleFlag = moduleFlag; 96 | } 97 | 98 | public String getCreatePerson() { 99 | return createPerson; 100 | } 101 | 102 | public void setCreatePerson(String createPerson) { 103 | this.createPerson = createPerson; 104 | } 105 | 106 | public Date getCreateDate() { 107 | return createDate; 108 | } 109 | 110 | public void setCreateDate(Date createDate) { 111 | this.createDate = createDate; 112 | } 113 | 114 | public String getUpdatePerson() { 115 | return updatePerson; 116 | } 117 | 118 | public void setUpdatePerson(String updatePerson) { 119 | this.updatePerson = updatePerson; 120 | } 121 | 122 | public Date getUpdateDate() { 123 | return updateDate; 124 | } 125 | 126 | public void setUpdateDate(Date updateDate) { 127 | this.updateDate = updateDate; 128 | } 129 | } -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.controller; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.ui.ModelMap; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | import com.cl.privilege.api.IPrivilegeBaseApiService; 15 | import com.cl.privilege.biz.IUserService; 16 | import com.cl.privilege.model.User; 17 | import com.cl.privilege.utils.ConfigUtil; 18 | import com.cl.privilege.utils.ConstantUtil; 19 | import com.cl.privilege.utils.SessionUtil; 20 | import com.cl.privilege.utils.StringUtil; 21 | 22 | 23 | 24 | /** 25 | *主界面及登录验证相关的控制器 26 | */ 27 | 28 | @Controller 29 | @RequestMapping("/controller") 30 | public class IndexController { 31 | 32 | @Autowired 33 | private IPrivilegeBaseApiService privilegeBaseApiService; 34 | @Autowired 35 | private ConfigUtil configUtil; 36 | @Autowired 37 | private IUserService userService; 38 | 39 | @RequestMapping("/main") 40 | public String main(String visitedModule,HttpServletRequest request,ModelMap map) { 41 | 42 | visitedModule = "p"; 43 | 44 | //初始化用户、菜单 45 | User user = SessionUtil.getSessionUser(request); 46 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,""); 47 | map.put("user", user); 48 | map.put("menus", menus); 49 | 50 | int hours = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); 51 | map.put("hours", hours); 52 | 53 | return "main.ftl"; 54 | } 55 | 56 | @RequestMapping("/logout") 57 | public String logout(HttpServletRequest request) throws Exception 58 | { 59 | SessionUtil.clearSession(request); 60 | //被拦截器拦截处理 61 | return "redirect:" + configUtil.getCasServerUrl()+"/logout?service=" + configUtil.getCasServiceUrl(); 62 | } 63 | 64 | @RequestMapping("/modifypasswordform") 65 | public String modifypasswordform(HttpServletRequest request) throws Exception 66 | { 67 | return "modifypasswordform.ftl"; 68 | } 69 | 70 | @ResponseBody 71 | @RequestMapping("/modifypassword") 72 | public String modifypassword(String oldpassword,String password,HttpServletRequest request) throws Exception 73 | { 74 | if(StringUtil.isStrEmpty(oldpassword) || StringUtil.isStrEmpty(password)) return ConstantUtil.Fail; 75 | //初始化用户、菜单 76 | User user = SessionUtil.getSessionUser(request); 77 | if(!user.getPassword().equals(StringUtil.makeMD5(oldpassword))) return ConstantUtil.Fail; 78 | User newUser = new User(); 79 | newUser.setId(user.getId()); 80 | newUser.setPassword(StringUtil.makeMD5(password)); 81 | newUser.setUpdateDate(new Date()); 82 | newUser.setUpdatePerson(user.getUsername()); 83 | privilegeBaseApiService.updateUserById(newUser); 84 | 85 | //更新session 86 | user.setPassword(newUser.getPassword()); 87 | request.getSession().setAttribute(SessionUtil.SessionSystemLoginUserName,user); 88 | 89 | return ConstantUtil.Success; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /privilege-model/src/main/java/com/cl/privilege/model/User.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class User implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Integer id; 11 | 12 | private String username; 13 | 14 | private String password; 15 | 16 | private String fullname; 17 | 18 | private Boolean gender; 19 | 20 | private Boolean isAdmin; 21 | 22 | private Integer departmentId; 23 | 24 | private String departmentName; 25 | 26 | private Boolean isLock; 27 | 28 | private Boolean isDelete; 29 | 30 | private String createPerson; 31 | 32 | private Date createDate; 33 | 34 | private String updatePerson; 35 | 36 | private Date updateDate; 37 | 38 | public Integer getId() { 39 | return id; 40 | } 41 | 42 | public void setId(Integer id) { 43 | this.id = id; 44 | } 45 | 46 | public String getUsername() { 47 | return username; 48 | } 49 | 50 | public void setUsername(String username) { 51 | this.username = username; 52 | } 53 | 54 | public String getPassword() { 55 | return password; 56 | } 57 | 58 | public void setPassword(String password) { 59 | this.password = password; 60 | } 61 | 62 | public String getFullname() { 63 | return fullname; 64 | } 65 | 66 | public void setFullname(String fullname) { 67 | this.fullname = fullname; 68 | } 69 | 70 | public Boolean getGender() { 71 | return gender; 72 | } 73 | 74 | public void setGender(Boolean gender) { 75 | this.gender = gender; 76 | } 77 | 78 | public Boolean getIsAdmin() { 79 | return isAdmin; 80 | } 81 | 82 | public void setIsAdmin(Boolean isAdmin) { 83 | this.isAdmin = isAdmin; 84 | } 85 | 86 | public Integer getDepartmentId() { 87 | return departmentId; 88 | } 89 | 90 | public void setDepartmentId(Integer departmentId) { 91 | this.departmentId = departmentId; 92 | } 93 | 94 | public String getDepartmentName() { 95 | return departmentName; 96 | } 97 | 98 | public void setDepartmentName(String departmentName) { 99 | this.departmentName = departmentName; 100 | } 101 | 102 | public Boolean getIsLock() { 103 | return isLock; 104 | } 105 | 106 | public void setIsLock(Boolean isLock) { 107 | this.isLock = isLock; 108 | } 109 | 110 | public Boolean getIsDelete() { 111 | return isDelete; 112 | } 113 | 114 | public void setIsDelete(Boolean isDelete) { 115 | this.isDelete = isDelete; 116 | } 117 | 118 | public String getCreatePerson() { 119 | return createPerson; 120 | } 121 | 122 | public void setCreatePerson(String createPerson) { 123 | this.createPerson = createPerson; 124 | } 125 | 126 | public Date getCreateDate() { 127 | return createDate; 128 | } 129 | 130 | public void setCreateDate(Date createDate) { 131 | this.createDate = createDate; 132 | } 133 | 134 | public String getUpdatePerson() { 135 | return updatePerson; 136 | } 137 | 138 | public void setUpdatePerson(String updatePerson) { 139 | this.updatePerson = updatePerson; 140 | } 141 | 142 | public Date getUpdateDate() { 143 | return updateDate; 144 | } 145 | 146 | public void setUpdateDate(Date updateDate) { 147 | this.updateDate = updateDate; 148 | } 149 | } -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/controller/DepartmentController.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.controller; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.ModelMap; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestParam; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | import com.cl.privilege.api.IPrivilegeBaseApiService; 15 | import com.cl.privilege.biz.IDepartmentService; 16 | import com.cl.privilege.model.Department; 17 | import com.cl.privilege.model.User; 18 | import com.cl.privilege.utils.ConfigUtil; 19 | import com.cl.privilege.utils.ConstantUtil; 20 | import com.cl.privilege.utils.JsonUtil; 21 | import com.cl.privilege.utils.SessionUtil; 22 | 23 | 24 | 25 | /** 26 | *部门管理相关的控制器 27 | */ 28 | 29 | @Controller 30 | @RequestMapping("/controller/department") 31 | public class DepartmentController { 32 | 33 | @Autowired 34 | private IPrivilegeBaseApiService privilegeBaseApiService; 35 | @Autowired 36 | private ConfigUtil configUtil; 37 | @Autowired 38 | private IDepartmentService departmentService; 39 | 40 | @RequestMapping("/list") 41 | public String main(String visitedModule,String visitedResource,HttpServletRequest request,ModelMap map) { 42 | 43 | //初始化用户、菜单 44 | User user = SessionUtil.getSessionUser(request); 45 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,visitedResource); 46 | map.put("user", user); 47 | map.put("menus", menus); 48 | 49 | return "department/list.ftl"; 50 | } 51 | 52 | @ResponseBody 53 | @RequestMapping("/getDepartmentTree") 54 | public String getDepartmentTree(HttpServletResponse response,ModelMap map) { 55 | 56 | //这是为了jstree插件使用,这个插件只对Content-Type为json和html的内容进行处理 57 | response.setContentType("application/json;charset=UTF-8"); 58 | 59 | return departmentService.getDepartmentTree(); 60 | } 61 | 62 | @ResponseBody 63 | @RequestMapping("/get") 64 | public String get(Integer id,ModelMap map) { 65 | 66 | Department department = departmentService.getDepartmentById(id); 67 | return JsonUtil.convertObj2json(department).toString(); 68 | } 69 | 70 | @ResponseBody 71 | @RequestMapping("/add") 72 | public String add(@ModelAttribute("department")Department department,HttpServletRequest request) { 73 | 74 | //从session取出User对象 75 | User user = SessionUtil.getSessionUser(request); 76 | //生成节点 77 | departmentService.createDepartment(department,user); 78 | return JsonUtil.convertObj2json(department).toString(); 79 | } 80 | 81 | @ResponseBody 82 | @RequestMapping("/update") 83 | public String update(@ModelAttribute("department") Department department,HttpServletRequest request) { 84 | //从session取出User对象 85 | User user = SessionUtil.getSessionUser(request); 86 | 87 | //生成节点积累 88 | departmentService.updateDepartmentById(department,user); 89 | 90 | return JsonUtil.convertObj2json(department).toString(); 91 | } 92 | 93 | @ResponseBody 94 | @RequestMapping("/delete") 95 | public String delete(@RequestParam("id") Integer id) throws Exception{ 96 | 97 | //判断节点是否被用户关联 98 | if(departmentService.isUsedByUser(id)) 99 | { 100 | return ConstantUtil.Fail; 101 | } 102 | 103 | departmentService.deleteDepartmentById(id); 104 | 105 | return ConstantUtil.Success; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/user/addform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 104 | 105 | 109 | 110 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/controller/ResourceController.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.controller; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.ModelMap; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestParam; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | import com.cl.privilege.api.IPrivilegeBaseApiService; 15 | import com.cl.privilege.biz.IResourceService; 16 | import com.cl.privilege.model.Resource; 17 | import com.cl.privilege.model.User; 18 | import com.cl.privilege.utils.ConfigUtil; 19 | import com.cl.privilege.utils.ConstantUtil; 20 | import com.cl.privilege.utils.JsonUtil; 21 | import com.cl.privilege.utils.SessionUtil; 22 | 23 | 24 | 25 | /** 26 | *菜单资源管理相关的控制器 27 | */ 28 | 29 | @Controller 30 | @RequestMapping("/controller/resource") 31 | public class ResourceController { 32 | 33 | @Autowired 34 | private IPrivilegeBaseApiService privilegeBaseApiService; 35 | @Autowired 36 | private ConfigUtil configUtil; 37 | @Autowired 38 | private IResourceService resourceService; 39 | 40 | @RequestMapping("/list") 41 | public String main(String visitedModule,String visitedResource,HttpServletRequest request,ModelMap map) { 42 | 43 | //初始化用户、菜单 44 | User user = SessionUtil.getSessionUser(request); 45 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,visitedResource); 46 | map.put("user", user); 47 | map.put("menus", menus); 48 | 49 | return "resource/list.ftl"; 50 | } 51 | 52 | @ResponseBody 53 | @RequestMapping("/getResourceTree") 54 | public String getResourceTree(HttpServletRequest request,HttpServletResponse response,ModelMap map) { 55 | 56 | //这是为了jstree插件使用,这个插件只对Content-Type为json和html的内容进行处理 57 | response.setContentType("application/json;charset=UTF-8"); 58 | 59 | return resourceService.getResourceTree(0); 60 | } 61 | 62 | @ResponseBody 63 | @RequestMapping("/getResourceTreeWithChecked") 64 | public String getResourceTreeWithChecked(Integer roleId,HttpServletRequest request,HttpServletResponse response,ModelMap map) { 65 | 66 | //这是为了jstree插件使用,这个插件只对Content-Type为json和html的内容进行处理 67 | response.setContentType("application/json;charset=UTF-8"); 68 | 69 | return resourceService.getResourceTree(roleId); 70 | } 71 | 72 | @ResponseBody 73 | @RequestMapping("/get") 74 | public String get(Integer id,ModelMap map) { 75 | 76 | Resource resource = resourceService.getResourceById(id); 77 | return JsonUtil.convertObj2json(resource).toString(); 78 | } 79 | 80 | @ResponseBody 81 | @RequestMapping("/add") 82 | public String add(@ModelAttribute("resource")Resource resource,HttpServletRequest request) { 83 | 84 | //从session取出User对象 85 | User user = SessionUtil.getSessionUser(request); 86 | //生成节点 87 | resourceService.createResource(resource, user); 88 | return JsonUtil.convertObj2json(resource).toString(); 89 | } 90 | 91 | @ResponseBody 92 | @RequestMapping("/update") 93 | public String update(@ModelAttribute("resource") Resource resource,HttpServletRequest request) { 94 | //从session取出User对象 95 | User user = SessionUtil.getSessionUser(request); 96 | 97 | //生成节点积累 98 | resourceService.updateResourceById(resource, user); 99 | 100 | return JsonUtil.convertObj2json(resource).toString(); 101 | } 102 | 103 | @ResponseBody 104 | @RequestMapping("/delete") 105 | public String delete(@RequestParam("id") Integer id) throws Exception{ 106 | 107 | //判断节点是否被用户关联 108 | if(resourceService.isUsedByRole(id)) 109 | { 110 | return ConstantUtil.Fail; 111 | } 112 | 113 | resourceService.deleteResourceById(id); 114 | 115 | return ConstantUtil.Success; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /privilege-api-server/src/test/resources/applicationContext-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | Spring公共配置 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | classpath*:/config.properties 48 | 49 | file:/d:/conf/cl/privilege-api-server/*.properties 50 | 51 | file:/etc/conf/cl/privilege-api-server/*.properties 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /config_privilege.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/user/updateform.ftl: -------------------------------------------------------------------------------- 1 | 5 | 6 | 104 | 105 | 109 | 110 | -------------------------------------------------------------------------------- /privilege-api-server/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | Spring公共配置 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | classpath*:/config.properties 48 | 49 | file:/d:/conf/cl/privilege-api-server/*.properties 50 | 51 | file:/etc/conf/cl/privilege-api-server/*.properties 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/controller/RoleController.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.controller; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.ModelMap; 7 | import org.springframework.web.bind.annotation.ModelAttribute; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import com.cl.privilege.api.IPrivilegeBaseApiService; 13 | import com.cl.privilege.biz.IRoleService; 14 | import com.cl.privilege.model.Role; 15 | import com.cl.privilege.model.RoleSearchModel; 16 | import com.cl.privilege.model.User; 17 | import com.cl.privilege.utils.ConfigUtil; 18 | import com.cl.privilege.utils.ConstantUtil; 19 | import com.cl.privilege.utils.JsonUtil; 20 | import com.cl.privilege.utils.SessionUtil; 21 | import com.cl.privilege.utils.StringUtil; 22 | 23 | 24 | 25 | /** 26 | *角色管理相关的控制器 27 | */ 28 | 29 | @Controller 30 | @RequestMapping("/controller/role") 31 | public class RoleController { 32 | 33 | @Autowired 34 | private IPrivilegeBaseApiService privilegeBaseApiService; 35 | @Autowired 36 | private ConfigUtil configUtil; 37 | @Autowired 38 | private IRoleService roleService; 39 | 40 | @RequestMapping("/list") 41 | public String main(String visitedModule,String visitedResource,HttpServletRequest request,ModelMap map) { 42 | 43 | //初始化用户、菜单 44 | User user = SessionUtil.getSessionUser(request); 45 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,visitedResource); 46 | map.put("user", user); 47 | map.put("menus", menus); 48 | 49 | return "role/list.ftl"; 50 | } 51 | 52 | @ResponseBody 53 | @RequestMapping("/getRoleDataTables") 54 | public String getRoleDataTables(RoleSearchModel searchModel,ModelMap map) { 55 | return roleService.getRoleDataTables(searchModel); 56 | } 57 | 58 | @ResponseBody 59 | @RequestMapping("/getRoleDataRow") 60 | public String getRoleDataRow(@RequestParam("id") Integer id) throws Exception{ 61 | return roleService.getRoleDataRow(id); 62 | } 63 | 64 | @ResponseBody 65 | @RequestMapping("/get") 66 | public String get(@RequestParam("id") Integer id) throws Exception{ 67 | Role role = roleService.getRoleById(id); 68 | return JsonUtil.convertObj2json(role).toString(); 69 | } 70 | 71 | @RequestMapping("/addform") 72 | public String addform() { 73 | return "role/addform.ftl"; 74 | } 75 | 76 | @ResponseBody 77 | @RequestMapping("/add") 78 | public String add(@ModelAttribute("role")Role role,HttpServletRequest request) { 79 | //从session取出User对象 80 | User user = SessionUtil.getSessionUser(request); 81 | //生成节点角色 82 | if(role.getRemark() == null) 83 | { 84 | role.setRemark(""); 85 | } 86 | roleService.createRole(role,user); 87 | return ConstantUtil.Success; 88 | } 89 | 90 | @RequestMapping("/updateform") 91 | public String updateform(Integer id,HttpServletRequest request,ModelMap map) { 92 | Role role = roleService.getRoleById(id); 93 | map.put("role", role); 94 | return "role/updateform.ftl"; 95 | } 96 | 97 | @ResponseBody 98 | @RequestMapping("/update") 99 | public String update(@ModelAttribute("role") Role role,HttpServletRequest request) { 100 | //从session取出User对象 101 | User user = SessionUtil.getSessionUser(request); 102 | //生成节点角色 103 | roleService.updateRoleById(role,user); 104 | 105 | return ConstantUtil.Success; 106 | } 107 | 108 | @ResponseBody 109 | @RequestMapping("/delete") 110 | public String delete(@RequestParam("id") Integer id) { 111 | 112 | //判断节点是否被用户关联 113 | if(roleService.isUsedByUser(id)) 114 | { 115 | return ConstantUtil.Fail; 116 | } 117 | 118 | roleService.deleteRoleById(id); 119 | 120 | return ConstantUtil.Success; 121 | } 122 | 123 | @RequestMapping("/assignform") 124 | public String assignform(String id,ModelMap map) 125 | { 126 | map.put("id", id); 127 | return "role/assignform.ftl"; 128 | } 129 | 130 | @ResponseBody 131 | @RequestMapping("/assign") 132 | public String assign(Integer id,String checkedStr) 133 | { 134 | if(id == null || StringUtil.isStrEmpty(id.toString()) || StringUtil.isStrEmpty(checkedStr)) 135 | { 136 | return ConstantUtil.Fail; 137 | } 138 | roleService.assignModuleAndResource(id, checkedStr); 139 | 140 | return ConstantUtil.Success; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /privilege-api-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | cl 7 | privilege 8 | 1.0.0-SNAPSHOT 9 | 10 | privilege-api-server 11 | privilege-api-server 12 | war 13 | 14 | 15 | UTF-8 16 | 4.0.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | cl 23 | privilege-data 24 | 1.0.0-SNAPSHOT 25 | 26 | 27 | cl 28 | privilege-api 29 | 1.0.0-SNAPSHOT 30 | 31 | 32 | 33 | org.jasig.cas.client 34 | cas-client-core 35 | 3.2.1-SNAPSHOT 36 | 37 | 38 | 39 | log4j 40 | log4j 41 | 1.2.16 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 1.6.1 47 | 48 | 49 | org.slf4j 50 | slf4j-log4j12 51 | 1.6.1 52 | 53 | 54 | 55 | org.springframework 56 | spring-core 57 | ${spring.version} 58 | 59 | 60 | org.springframework 61 | spring-beans 62 | ${spring.version} 63 | 64 | 65 | org.springframework 66 | spring-context 67 | ${spring.version} 68 | 69 | 70 | org.springframework 71 | spring-context-support 72 | ${spring.version} 73 | 74 | 75 | org.springframework 76 | spring-web 77 | ${spring.version} 78 | 79 | 80 | org.springframework 81 | spring-webmvc 82 | ${spring.version} 83 | 84 | 85 | org.springframework 86 | spring-aspects 87 | ${spring.version} 88 | 89 | 90 | org.springframework 91 | spring-jdbc 92 | ${spring.version} 93 | 94 | 95 | org.springframework.data 96 | spring-data-redis 97 | 1.3.1.RELEASE 98 | 99 | 100 | 101 | com.alibaba 102 | dubbo 103 | 2.5.3 104 | 105 | 106 | org.springframework 107 | spring 108 | 109 | 110 | netty 111 | org.jboss.netty 112 | 113 | 114 | 115 | 116 | com.github.sgroschupf 117 | zkclient 118 | 0.1 119 | 120 | 121 | 122 | com.caucho 123 | hessian 124 | 4.0.7 125 | 126 | 127 | 128 | mysql 129 | mysql-connector-java 130 | test 131 | 5.1.14 132 | 133 | 134 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | Cl Privilege Manage Server 7 | 8 | webAppRootKey 9 | privilege-server.root 10 | 11 | 12 | contextConfigLocation 13 | 14 | classpath*:/applicationContext*.xml 15 | classpath*:/cas-privilege.xml 16 | 17 | 18 | 19 | log4jConfigLocation 20 | /WEB-INF/classes/log4j.xml 21 | 22 | 23 | spring.profiles.default 24 | dev 25 | 26 | 27 | 28 | 29 | encodingFilter 30 | org.springframework.web.filter.CharacterEncodingFilter 31 | 32 | encoding 33 | UTF-8 34 | 35 | 36 | forceEncoding 37 | true 38 | 39 | 40 | 41 | encodingFilter 42 | *.do 43 | 44 | 45 | 46 | 47 | org.jasig.cas.client.session.SingleSignOutHttpSessionListener 48 | 49 | 50 | CAS Single Sign Out Filter 51 | org.jasig.cas.client.session.SingleSignOutFilter 52 | 53 | 54 | CAS Single Sign Out Filter 55 | /controller/* 56 | 57 | 58 | 59 | 60 | 61 | CAS Authentication Filter 62 | org.springframework.web.filter.DelegatingFilterProxy 63 | 64 | targetBeanName 65 | casAuthenticationFilter 66 | 67 | 68 | 69 | CAS Authentication Filter 70 | /controller/* 71 | 72 | 73 | CAS Validation Filter 74 | org.springframework.web.filter.DelegatingFilterProxy 75 | 76 | targetBeanName 77 | casTicketValidationFilter 78 | 79 | 80 | 81 | CAS Validation Filter 82 | /controller/* 83 | 84 | 85 | 86 | 87 | CAS Assertion Thread Local Filter 88 | org.jasig.cas.client.util.AssertionThreadLocalFilter 89 | 90 | 91 | CAS Assertion Thread Local Filter 92 | /controller/* 93 | 94 | 95 | 96 | 97 | 98 | org.springframework.web.context.ContextLoaderListener 99 | 100 | 101 | 102 | 103 | springmvc 104 | org.springframework.web.servlet.DispatcherServlet 105 | 1 106 | 107 | 108 | springmvc 109 | *.do 110 | 111 | 112 | 113 | csv 114 | application/octet-stream 115 | 116 | 117 | 118 | index.html 119 | index.jsp 120 | 121 | 122 | -------------------------------------------------------------------------------- /privilege-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | cl 7 | privilege 8 | 1.0.0-SNAPSHOT 9 | 10 | privilege-server 11 | privilege-server 12 | war 13 | 14 | 15 | UTF-8 16 | 4.0.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | cl 23 | privilege-data 24 | 1.0.0-SNAPSHOT 25 | 26 | 27 | cl 28 | privilege-api 29 | 1.0.0-SNAPSHOT 30 | 31 | 32 | 33 | org.jasig.cas.client 34 | cas-client-core 35 | 3.2.1-SNAPSHOT 36 | 37 | 38 | 39 | log4j 40 | log4j 41 | 1.2.16 42 | 43 | 44 | org.slf4j 45 | slf4j-api 46 | 1.6.1 47 | 48 | 49 | org.slf4j 50 | slf4j-log4j12 51 | 1.6.1 52 | 53 | 54 | 55 | org.springframework 56 | spring-core 57 | ${spring.version} 58 | 59 | 60 | org.springframework 61 | spring-beans 62 | ${spring.version} 63 | 64 | 65 | org.springframework 66 | spring-context 67 | ${spring.version} 68 | 69 | 70 | org.springframework 71 | spring-context-support 72 | ${spring.version} 73 | 74 | 75 | org.springframework 76 | spring-web 77 | ${spring.version} 78 | 79 | 80 | org.springframework 81 | spring-webmvc 82 | ${spring.version} 83 | 84 | 85 | org.springframework 86 | spring-aspects 87 | ${spring.version} 88 | 89 | 90 | org.springframework 91 | spring-jdbc 92 | ${spring.version} 93 | 94 | 95 | org.springframework.data 96 | spring-data-redis 97 | 1.3.1.RELEASE 98 | 99 | 100 | 101 | com.alibaba 102 | dubbo 103 | 2.5.3 104 | 105 | 106 | org.springframework 107 | spring 108 | 109 | 110 | netty 111 | org.jboss.netty 112 | 113 | 114 | 115 | 116 | com.github.sgroschupf 117 | zkclient 118 | 0.1 119 | 120 | 121 | 122 | com.caucho 123 | hessian 124 | 4.0.7 125 | 126 | 127 | 128 | org.freemarker 129 | freemarker 130 | 2.3.16 131 | 132 | 133 | 134 | javax.servlet 135 | servlet-api 136 | 2.5 137 | provided 138 | 139 | 140 | jstl 141 | jstl 142 | 1.1.2 143 | 144 | 145 | 146 | commons-beanutils 147 | commons-beanutils 148 | 1.8.3 149 | 150 | 151 | commons-lang 152 | commons-lang 153 | 2.5 154 | 155 | 156 | -------------------------------------------------------------------------------- /privilege-api-server/src/main/java/com/cl/privilege/api/impl/PrivilegeBaseApiServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.api.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import com.cl.privilege.api.IPrivilegeBaseApiService; 9 | import com.cl.privilege.mapper.ModuleMapper; 10 | import com.cl.privilege.mapper.ResourceMapper; 11 | import com.cl.privilege.mapper.UserMapper; 12 | import com.cl.privilege.model.Module; 13 | import com.cl.privilege.model.Resource; 14 | import com.cl.privilege.model.User; 15 | 16 | //注意:这个类不需要再加@Service标签了,因为在DUBBO里面已经定义了 17 | public class PrivilegeBaseApiServiceImpl implements IPrivilegeBaseApiService { 18 | 19 | @Autowired 20 | private UserMapper userMapper; 21 | @Autowired 22 | private ModuleMapper moduleMapper; 23 | @Autowired 24 | private ResourceMapper resourceMapper; 25 | 26 | @Override 27 | public User getUserByUsername(String username) { 28 | return userMapper.getUserByUsername(username); 29 | } 30 | 31 | @Override 32 | public String getModuleTree(Integer userId,String visitedModule,String visitedResource) 33 | { 34 | if(visitedModule == null) visitedModule = ""; 35 | if(visitedResource == null) visitedResource = ""; 36 | 37 | User user = userMapper.selectByPrimaryKey(userId); 38 | if(user == null) return ""; 39 | 40 | StringBuilder sb = new StringBuilder(); 41 | List moduleList; 42 | if(user.getIsAdmin()) 43 | { 44 | moduleList = moduleMapper.getModuleList(); 45 | } else { 46 | moduleList = moduleMapper.getModuleListByUserId(userId); 47 | } 48 | if(moduleList==null || moduleList.size()==0) return ""; 49 | List resourceList; 50 | if(user.getIsAdmin()) 51 | { 52 | resourceList = resourceMapper.getResourceList(); 53 | } else { 54 | List moduleFlags = new ArrayList(); 55 | for(Module m:moduleList) 56 | { 57 | moduleFlags.add(m.getFlag()); 58 | } 59 | resourceList = resourceMapper.getResourceListByModuleFlag(moduleFlags, userId); 60 | } 61 | 62 | //从前一页面传过来的ModuleFlag标记和visitedStructure标记 63 | //moduleFlag = "p"; 64 | //visitedStructure = "s-1-1-1"; 65 | 66 | String[] icons = "fa-gift、fa-cogs、fa-puzzle-piece、fa-sitemap、fa-table、fa-briefcase、fa-comments、fa-group、fa-globe、fa-th".split("、"); 67 | int iconsFlag = 0; 68 | 69 | for(Module m:moduleList) 70 | { 71 | if(m.getFlag().equals(visitedModule)) 72 | { 73 | sb.append("
  • "); 74 | } else { 75 | sb.append("
  • "); 76 | } 77 | sb.append(""); 78 | sb.append(""); 79 | sb.append(""); 80 | sb.append(" " + m.getName()); 81 | sb.append(""); 82 | sb.append(""); 83 | sb.append(""); 84 | sb.append(""); 85 | sb.append(buildResourceTree(m,resourceList,"s",visitedModule,visitedResource)); 86 | sb.append("
  • "); 87 | } 88 | 89 | return sb.toString(); 90 | } 91 | 92 | @Override 93 | public Integer updateUserById(User user) 94 | { 95 | return userMapper.updateByPrimaryKeySelective(user); 96 | } 97 | 98 | /** 99 | * 100 | * @param m:当前正在遍历的模块 101 | * @param resourceList:所有的资源列表 102 | * @param structure:要对其进行树形结构的资源,根是s 103 | * @param visitedModule:当前访问页面的Module 104 | * @param visitedResource:当前访问页面的Resource 105 | * @return 106 | */ 107 | private String buildResourceTree(Module m,List resourceList,String structure,String visitedModule,String visitedResource) 108 | { 109 | if(resourceList == null || resourceList.size()==0) 110 | { 111 | return ""; 112 | } 113 | int parentLength = structure.split("-").length; 114 | //计算一级子资源 115 | List sonList = new ArrayList(); 116 | for(Resource r:resourceList) 117 | { 118 | if(r.getStructure().split("-").length==parentLength+1 119 | && r.getStructure().contains(structure) 120 | && r.getModuleFlag().equals(m.getFlag())) 121 | { 122 | sonList.add(r); 123 | } 124 | } 125 | if(sonList.size()==0) 126 | { 127 | return ""; 128 | } 129 | 130 | StringBuilder sb = new StringBuilder(); 131 | sb.append(""); 174 | return sb.toString(); 175 | } 176 | 177 | } 178 | -------------------------------------------------------------------------------- /privilege-server/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | Spring公共配置 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | classpath*:/config.properties 48 | 49 | file:/d:/conf/cl/privilege-server/*.properties 50 | 51 | file:/etc/conf/cl/privilege-server/*.properties 52 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 62 | 63 | 64 | 0 65 | zh_CN 66 | UTF-8 67 | UTF-8 68 | rethrow 69 | #.## 70 | yyyy-MM-dd 71 | HH:mm:ss 72 | yyyy-MM-dd HH:mm:ss 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.controller; 2 | 3 | import java.util.List; 4 | import javax.servlet.http.HttpServletRequest; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.ModelMap; 8 | import org.springframework.web.bind.annotation.ModelAttribute; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | 13 | import com.cl.privilege.api.IPrivilegeBaseApiService; 14 | import com.cl.privilege.biz.IDepartmentService; 15 | import com.cl.privilege.biz.IRoleService; 16 | import com.cl.privilege.biz.IUserService; 17 | import com.cl.privilege.model.Department; 18 | import com.cl.privilege.model.User; 19 | import com.cl.privilege.model.UserSearchModel; 20 | import com.cl.privilege.utils.ConfigUtil; 21 | import com.cl.privilege.utils.ConstantUtil; 22 | import com.cl.privilege.utils.JsonUtil; 23 | import com.cl.privilege.utils.SessionUtil; 24 | import com.cl.privilege.utils.StringUtil; 25 | 26 | 27 | 28 | /** 29 | *用户管理相关的控制器 30 | */ 31 | 32 | @Controller 33 | @RequestMapping("/controller/user") 34 | public class UserController { 35 | 36 | @Autowired 37 | private IPrivilegeBaseApiService privilegeBaseApiService; 38 | @Autowired 39 | private ConfigUtil configUtil; 40 | @Autowired 41 | private IRoleService roleService; 42 | @Autowired 43 | private IUserService userService; 44 | @Autowired 45 | private IDepartmentService departmentService; 46 | 47 | @RequestMapping("/list") 48 | public String main(String visitedModule,String visitedResource,HttpServletRequest request,ModelMap map) { 49 | 50 | //初始化用户、菜单 51 | User user = SessionUtil.getSessionUser(request); 52 | String menus = privilegeBaseApiService.getModuleTree(user.getId(),visitedModule,visitedResource); 53 | map.put("user", user); 54 | map.put("menus", menus); 55 | 56 | return "user/list.ftl"; 57 | } 58 | 59 | @ResponseBody 60 | @RequestMapping("/getUserDataTables") 61 | public String getUserDataTables(UserSearchModel searchModel,ModelMap map) { 62 | return userService.getUserDataTables(searchModel); 63 | } 64 | 65 | @ResponseBody 66 | @RequestMapping("/getUserDataRow") 67 | public String getUserDataRow(@RequestParam("id") Integer id) throws Exception{ 68 | return userService.getUserDataRow(id); 69 | } 70 | 71 | @ResponseBody 72 | @RequestMapping("/get") 73 | public String get(@RequestParam("id") Integer id) throws Exception{ 74 | User user = userService.getUserById(id); 75 | return JsonUtil.convertObj2json(user).toString(); 76 | } 77 | 78 | @RequestMapping("/addform") 79 | public String addform(ModelMap map) { 80 | List departments = departmentService.getDepartmentListForOption(); 81 | map.put("departments", departments); 82 | return "user/addform.ftl"; 83 | } 84 | 85 | @ResponseBody 86 | @RequestMapping("/add") 87 | public String add(@ModelAttribute("user")User user,HttpServletRequest request) { 88 | //从session取出User对象 89 | User operator = SessionUtil.getSessionUser(request); 90 | userService.createUser(user, operator); 91 | return ConstantUtil.Success; 92 | } 93 | 94 | @RequestMapping("/updateform") 95 | public String updateform(Integer id,HttpServletRequest request,ModelMap map) { 96 | List departments = departmentService.getDepartmentListForOption(); 97 | User user = userService.getUserById(id); 98 | map.put("departments", departments); 99 | map.put("user", user); 100 | return "user/updateform.ftl"; 101 | } 102 | 103 | @ResponseBody 104 | @RequestMapping("/update") 105 | public String update(@ModelAttribute("user") User user,HttpServletRequest request) { 106 | //从session取出User对象 107 | User operator = SessionUtil.getSessionUser(request); 108 | 109 | userService.updateUserById(user,operator); 110 | 111 | return ConstantUtil.Success; 112 | } 113 | 114 | @ResponseBody 115 | @RequestMapping("/delete") 116 | public String delete(@RequestParam("id") Integer id,HttpServletRequest request){ 117 | 118 | //从session取出User对象 119 | User operator = SessionUtil.getSessionUser(request); 120 | 121 | User user = new User(); 122 | user.setId(id); 123 | user.setIsDelete(true); 124 | 125 | userService.updateUserById(user, operator); 126 | 127 | return ConstantUtil.Success; 128 | } 129 | 130 | @ResponseBody 131 | @RequestMapping("/resetpass") 132 | public String resetpass(@RequestParam("id") Integer id,HttpServletRequest request){ 133 | 134 | //从session取出User对象 135 | User operator = SessionUtil.getSessionUser(request); 136 | 137 | User user = new User(); 138 | user.setId(id); 139 | user.setPassword(ConstantUtil.DefaultMd5Password); 140 | 141 | userService.updateUserById(user, operator); 142 | 143 | return ConstantUtil.Success; 144 | } 145 | 146 | @ResponseBody 147 | @RequestMapping("/lock") 148 | public String lock(@RequestParam("id") Integer id,HttpServletRequest request){ 149 | 150 | //从session取出User对象 151 | User operator = SessionUtil.getSessionUser(request); 152 | 153 | User user = new User(); 154 | user.setId(id); 155 | user.setIsLock(true); 156 | 157 | userService.updateUserById(user, operator); 158 | 159 | return ConstantUtil.Success; 160 | } 161 | 162 | @ResponseBody 163 | @RequestMapping("/unlock") 164 | public String unlock(@RequestParam("id") Integer id,HttpServletRequest request){ 165 | 166 | //从session取出User对象 167 | User operator = SessionUtil.getSessionUser(request); 168 | 169 | User user = new User(); 170 | user.setId(id); 171 | user.setIsLock(false); 172 | 173 | userService.updateUserById(user, operator); 174 | 175 | return ConstantUtil.Success; 176 | } 177 | 178 | @RequestMapping("/assignform") 179 | public String assignform(Integer id,ModelMap map) { 180 | 181 | map.put("options", roleService.getRoleForOptions(id)); 182 | map.put("id", id); 183 | 184 | return "user/assignform.ftl"; 185 | } 186 | 187 | @ResponseBody 188 | @RequestMapping("/assign") 189 | public String assign(Integer id,String selectedStr) 190 | { 191 | if(id==null || StringUtil.isStrEmpty(id.toString()) || StringUtil.isStrEmpty(selectedStr)) 192 | { 193 | return ConstantUtil.Fail; 194 | } 195 | userService.assignRole(id, selectedStr); 196 | 197 | return ConstantUtil.Success; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | import org.apache.ibatis.session.RowBounds; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Transactional; 11 | import org.springframework.util.StringUtils; 12 | 13 | import com.cl.privilege.biz.IUserService; 14 | import com.cl.privilege.mapper.ModuleMapper; 15 | import com.cl.privilege.mapper.UserMapper; 16 | import com.cl.privilege.model.User; 17 | import com.cl.privilege.model.UserSearchModel; 18 | import com.cl.privilege.utils.ConstantUtil; 19 | import com.cl.privilege.utils.StringUtil; 20 | 21 | 22 | @Service 23 | public class UserServiceImpl implements IUserService { 24 | 25 | @Autowired 26 | private UserMapper userMapper; 27 | @Autowired 28 | private ModuleMapper moduleMapper; 29 | 30 | private void setPersonInsert(User user,User operator) 31 | { 32 | Date d = new Date(); 33 | user.setIsLock(false); 34 | user.setIsDelete(false); 35 | user.setCreatePerson(operator.getUsername()); 36 | user.setUpdatePerson(operator.getUsername()); 37 | user.setCreateDate(d); 38 | user.setUpdateDate(d); 39 | } 40 | private void setPersonUpdate(User user,User operator) 41 | { 42 | Date d = new Date(); 43 | user.setUpdatePerson(operator.getUsername()); 44 | user.setUpdateDate(d); 45 | } 46 | 47 | @Override 48 | public User getUserByUsername(String username) { 49 | return userMapper.getUserByUsername(username); 50 | 51 | } 52 | 53 | @Override 54 | public User getUserById(Integer id) 55 | { 56 | return userMapper.selectByPrimaryKey(id); 57 | } 58 | 59 | @Override 60 | public Integer getUserTotalBySearch(UserSearchModel searchModel) 61 | { 62 | return userMapper.getUserTotalBySearch(searchModel); 63 | } 64 | 65 | @Override 66 | public List getUserListBySearch(UserSearchModel searchModel) 67 | { 68 | return userMapper.getUserListBySearch(searchModel, 69 | new RowBounds((searchModel.getPageNo() - 1) * searchModel.getPageSize(), searchModel.getPageSize())); 70 | } 71 | 72 | @Override 73 | public Integer createUser(User user,User operator) 74 | { 75 | setPersonInsert(user,operator); 76 | user.setPassword(StringUtil.makeMD5(user.getPassword())); 77 | return userMapper.insertSelective(user); 78 | } 79 | 80 | @Override 81 | public Integer updateUserById(User user,User operator) 82 | { 83 | setPersonUpdate(user,operator); 84 | return userMapper.updateByPrimaryKeySelective(user); 85 | } 86 | 87 | @Override 88 | @Transactional 89 | public Integer deleteUserById(Integer id,User operator) 90 | { 91 | User user = getUserById(id); 92 | if(user==null) 93 | { 94 | return 0; 95 | } 96 | 97 | //本设计中,设置用户是不能物理删除的,保证了所有记录用户操作日志的地方,关联用户可以用inner join,提高效率 98 | userMapper.deleteUserRoleById(id); 99 | user.setIsDelete(true); 100 | setPersonUpdate(user,operator); 101 | return userMapper.updateByPrimaryKeySelective(user); 102 | } 103 | 104 | @Override 105 | @Transactional 106 | public String assignRole(Integer id,String selectedStr) 107 | { 108 | String[] selectedArr = selectedStr.split(","); 109 | List roleIds = new ArrayList(); 110 | 111 | for(String s:selectedArr) 112 | { 113 | if(StringUtils.hasText(s)) 114 | { 115 | roleIds.add(Integer.parseInt(s)); 116 | } 117 | } 118 | 119 | userMapper.deleteUserRoleById(id); 120 | if(roleIds.size()>0) 121 | { 122 | userMapper.assignRoles(roleIds, id); 123 | } 124 | 125 | return ConstantUtil.Success; 126 | } 127 | 128 | @Override 129 | public String getUserDataTables(UserSearchModel searchModel) 130 | { 131 | Integer total = getUserTotalBySearch(searchModel); 132 | List userList = getUserListBySearch(searchModel); 133 | if(userList==null || userList.size()==0) 134 | { 135 | return "{\"iTotalRecords\":0,\"iTotalDisplayRecords\":0,\"aaData\":[]}"; 136 | } 137 | 138 | StringBuilder sb = new StringBuilder(); 139 | sb.append(String.format("{\"iTotalRecords\":%d,\"iTotalDisplayRecords\":%d,\"aaData\":[",total,total)); 140 | int i= 0; 141 | for(User u:userList) 142 | { 143 | if(i != 0) sb.append(","); 144 | addDataRow(sb,u); 145 | i++; 146 | } 147 | sb.append("]}"); 148 | return sb.toString(); 149 | } 150 | 151 | @Override 152 | public String getUserDataRow(Integer id) 153 | { 154 | User u = getUserById(id); 155 | StringBuilder sb = new StringBuilder(); 156 | addDataRow(sb,u); 157 | return sb.toString(); 158 | } 159 | 160 | private void addDataRow(StringBuilder sb,User u) 161 | { 162 | sb.append("["); 163 | sb.append("\"\""); 164 | sb.append(",").append(u.getId()); 165 | sb.append(",\"").append(u.getUsername()).append("\""); 166 | sb.append(",\"").append(u.getFullname()).append("\""); 167 | sb.append(",\"").append(u.getGender()?"男":"女").append("\""); 168 | sb.append(",\"").append(u.getIsAdmin()?"管理员":"普通").append("\""); 169 | sb.append(",\"").append(u.getIsLock()?"是":"否").append("\""); 170 | sb.append(",\"").append(u.getDepartmentName()==null?"":u.getDepartmentName()).append("\""); 171 | sb.append(",\"").append(u.getUpdatePerson()).append("\""); 172 | sb.append(",\"").append(StringUtil.formatDate(u.getUpdateDate(),"yyyy-MM-dd HH:mm:ss")).append("\""); 173 | sb.append(",\"") 174 | .append(" 修改") 175 | .append("   ").append(u.getIsLock()?"解锁":"锁定").append("") 176 | .append("   删除") 177 | .append("   分配角色") 178 | .append("\""); 179 | sb.append("]"); 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/scripts/custom/cl.js: -------------------------------------------------------------------------------- 1 | var Cl = function() { 2 | return { 3 | action: "", 4 | selected: {}, 5 | tableName: "datatable_cl", 6 | modalName: "modal_cl", 7 | formName: "form_cl", 8 | treeName: "tree_cl", 9 | ajaxRequest: function (url,reqParam,callback) { 10 | $.ajax({ 11 | type: 'POST', 12 | url: url, 13 | data: reqParam, 14 | cache: false, 15 | success: callback 16 | }); 17 | }, 18 | refreshDataTable: function(name) { 19 | var oTable = $('#'+name).dataTable(); 20 | oTable.fnDraw(); 21 | }, 22 | updateDataRow: function(tableName,id,idindex,url) { 23 | var data={ 24 | "id":id 25 | }; 26 | Cl.ajaxRequest(url,data,function(result){ 27 | if(!result) return ; 28 | //result = result.replace(/(^\s*)|(\s*$)/g,''); 29 | var oTable = $('#'+tableName).dataTable(); 30 | var nNodes = oTable.fnGetNodes(); 31 | for(var i=0;i' + 61 | '
    ' + 62 | '
    ' + 63 | '
    ' + 64 | ''; 65 | $.fn.modalmanager.defaults.resize = true; 66 | $("
    ").appendTo($('body')); 67 | }, 68 | showModalWindow: function(modalName,url) { 69 | var $modal = $('#'+modalName); 70 | $('body').modalmanager('loading'); 71 | setTimeout(function(){ 72 | $modal.load(url, '', function(){ 73 | $modal.modal(); 74 | }); 75 | }, 1000); 76 | }, 77 | hideModalWindow: function(modalDiv) { 78 | var $modal = $('#'+modalDiv); 79 | $modal.modal("hide") 80 | }, 81 | initModifyPassword: function(url) 82 | { 83 | var handleValidation = function() { 84 | // for more info visit the official plugin documentation: 85 | // http://docs.jquery.com/Plugins/Validation 86 | var form1 = $('#form_cl_mp'); 87 | var error1 = $('.alert-danger', form1); 88 | var success1 = $('.alert-success', form1); 89 | form1.validate({ 90 | errorElement: 'span', //default input error message container 91 | errorClass: 'help-block', // default input error message class 92 | focusInvalid: false, // do not focus the last invalid input 93 | ignore: "", 94 | rules: { 95 | oldpassword: { 96 | minlength: 2, 97 | required: true 98 | }, 99 | password: { 100 | minlength: 2, 101 | required: true 102 | }, 103 | confirmpassword: { 104 | minlength: 2, 105 | required: true, 106 | equalTo: "#password" 107 | } 108 | }, 109 | invalidHandler: function (event, validator) { //display error alert on form submit 110 | success1.hide(); 111 | error1.show(); 112 | App.scrollTo(error1, -200); 113 | }, 114 | highlight: function (element) { // hightlight error inputs 115 | $(element) 116 | .closest('.form-group').addClass('has-error'); // set error class to the control group 117 | }, 118 | unhighlight: function (element) { // revert the change done by hightlight 119 | $(element) 120 | .closest('.form-group').removeClass('has-error'); // set error class to the control group 121 | }, 122 | success: function (label) { 123 | label 124 | .closest('.form-group').removeClass('has-error'); // set success class to the control group 125 | }, 126 | submitHandler: function (form) { 127 | modify(); 128 | } 129 | }); 130 | } 131 | var handleWysihtml5 = function() { 132 | if (!jQuery().wysihtml5) { 133 | return; 134 | } 135 | if ($('.wysihtml5').size() > 0) { 136 | $('.wysihtml5').wysihtml5({ 137 | "stylesheets": ["http://127.0.0.1/privilege_inc/assets/plugins/bootstrap-wysihtml5/wysiwyg-color.css"] 138 | }); 139 | } 140 | } 141 | var modify = function() { 142 | var data={ 143 | "oldpassword":$("#oldpassword").val(), 144 | "password": $("#password").val() 145 | }; 146 | Cl.ajaxRequest(url,data,function(result){ 147 | if(!result) return ; 148 | result = result.replace(/(^\s*)|(\s*$)/g,''); 149 | if(result == "success"){ 150 | alert("修改成功"); 151 | Cl.hideModalWindow(Cl.modalName); 152 | } else { 153 | alert("旧密码输入错误"); 154 | return ; 155 | } 156 | }); 157 | } 158 | 159 | handleWysihtml5(); 160 | handleValidation(); 161 | } 162 | }; 163 | }(); -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/impl/RoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import org.apache.ibatis.session.RowBounds; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | import com.cl.privilege.biz.IRoleService; 15 | import com.cl.privilege.mapper.RoleMapper; 16 | import com.cl.privilege.model.Role; 17 | import com.cl.privilege.model.RoleSearchModel; 18 | import com.cl.privilege.model.User; 19 | import com.cl.privilege.utils.ConstantUtil; 20 | import com.cl.privilege.utils.StringUtil; 21 | 22 | 23 | @Service 24 | public class RoleServiceImpl implements IRoleService { 25 | 26 | @Autowired 27 | private RoleMapper roleMapper; 28 | 29 | private void setPersonInsert(Role role,User user) 30 | { 31 | Date d = new Date(); 32 | role.setCreatePerson(user.getUsername()); 33 | role.setUpdatePerson(user.getUsername()); 34 | role.setCreateDate(d); 35 | role.setUpdateDate(d); 36 | } 37 | private void setPersonUpdate(Role role,User user) 38 | { 39 | Date d = new Date(); 40 | role.setUpdatePerson(user.getUsername()); 41 | role.setUpdateDate(d); 42 | } 43 | 44 | @Override 45 | public Role getRoleById(Integer id) { 46 | return roleMapper.selectByPrimaryKey(id); 47 | } 48 | 49 | @Override 50 | public Integer createRole(Role role,User user) { 51 | setPersonInsert(role,user); 52 | return roleMapper.insertSelective(role); 53 | } 54 | 55 | @Override 56 | public Integer updateRoleById(Role role,User user) { 57 | setPersonUpdate(role,user); 58 | return roleMapper.updateByPrimaryKeySelective(role); 59 | } 60 | 61 | @Override 62 | public Integer deleteRoleById(Integer id) 63 | { 64 | return roleMapper.deleteRoleById(id); 65 | } 66 | 67 | @Override 68 | public Integer getRoleTotalBySearch(RoleSearchModel searchModel) 69 | { 70 | return roleMapper.getRoleTotalBySearch(searchModel); 71 | } 72 | 73 | @Override 74 | public List getRoleListBySearch(RoleSearchModel searchModel) 75 | { 76 | return roleMapper.getRoleListBySearch(searchModel, 77 | new RowBounds((searchModel.getPageNo() - 1) * searchModel.getPageSize(), searchModel.getPageSize())); 78 | } 79 | 80 | @Override 81 | public Boolean isUsedByUser(Integer roleId) 82 | { 83 | return roleMapper.isUsedByUser(roleId); 84 | } 85 | 86 | @Override 87 | @Transactional 88 | public String assignModuleAndResource(Integer roleId,String checkedStr) 89 | { 90 | String[] checkedArr = checkedStr.split(","); 91 | List moduleIds = new ArrayList(); 92 | List resourceIds = new ArrayList(); 93 | for(String s:checkedArr) 94 | { 95 | if(s.startsWith("m_")) 96 | { 97 | moduleIds.add(Integer.parseInt(s.replace("m_", ""))); 98 | } else { 99 | resourceIds.add(Integer.parseInt(s)); 100 | } 101 | } 102 | 103 | roleMapper.deleteRoleModuleById(roleId); 104 | if(moduleIds.size()>0) 105 | { 106 | roleMapper.assignModules(moduleIds, roleId); 107 | } 108 | 109 | roleMapper.deleteRoleResourceById(roleId); 110 | if(resourceIds.size()>0) 111 | { 112 | roleMapper.assignResources(resourceIds, roleId); 113 | } 114 | 115 | return ConstantUtil.Success; 116 | } 117 | 118 | @Override 119 | public List getRoleListByUserId(Integer userId) 120 | { 121 | return roleMapper.getRoleListByUserId(userId); 122 | } 123 | 124 | @Override 125 | public List getRoleList() 126 | { 127 | return roleMapper.getRoleList(); 128 | } 129 | 130 | @Override 131 | public String getRoleDataTables(RoleSearchModel searchModel) 132 | { 133 | Integer total = getRoleTotalBySearch(searchModel); 134 | List roleList = getRoleListBySearch(searchModel); 135 | if(roleList==null || roleList.size()==0) 136 | { 137 | return "{\"iTotalRecords\":0,\"iTotalDisplayRecords\":0,\"aaData\":[]}"; 138 | } 139 | 140 | StringBuilder sb = new StringBuilder(); 141 | sb.append(String.format("{\"iTotalRecords\":%d,\"iTotalDisplayRecords\":%d,\"aaData\":[",total,total)); 142 | int i= 0; 143 | for(Role r:roleList) 144 | { 145 | if(i != 0) sb.append(","); 146 | addDataRow(sb,r); 147 | i++; 148 | } 149 | sb.append("]}"); 150 | return sb.toString(); 151 | } 152 | 153 | @Override 154 | public String getRoleDataRow(Integer id) 155 | { 156 | Role r = getRoleById(id); 157 | StringBuilder sb = new StringBuilder(); 158 | addDataRow(sb,r); 159 | return sb.toString(); 160 | } 161 | 162 | private void addDataRow(StringBuilder sb,Role r) 163 | { 164 | sb.append("["); 165 | sb.append("\"\""); 166 | sb.append(",").append(r.getId()); 167 | sb.append(",\"").append(r.getName()).append("\""); 168 | sb.append(",\"").append(r.getRemark()).append("\""); 169 | sb.append(",\"").append(r.getUpdatePerson()).append("\""); 170 | sb.append(",\"").append(StringUtil.formatDate(r.getUpdateDate(),"yyyy-MM-dd HH:mm:ss")).append("\""); 171 | sb.append(",\"") 172 | .append(" 修改") 173 | .append("   删除") 174 | .append("   分配权限") 175 | .append("\""); 176 | sb.append("]"); 177 | } 178 | 179 | @Override 180 | public String getRoleForOptions(Integer userId) 181 | { 182 | List assignRoles = getRoleListByUserId(userId); 183 | List allRoles = getRoleList(); 184 | 185 | Map hmAssignRoles = new HashMap(); 186 | for(Role r:assignRoles) 187 | { 188 | hmAssignRoles.put(r.getId(),r); 189 | } 190 | StringBuilder sb = new StringBuilder(); 191 | for(Role r:allRoles) 192 | { 193 | sb.append(""); 199 | } 200 | return sb.toString(); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /privilege-data/src/main/resources/com/cl/privilege/mapper/ModuleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | id, name, flag, url, sort_no, create_person, create_date, update_person, update_date 17 | 18 | 24 | 25 | delete from p_module 26 | where id = #{id,jdbcType=INTEGER} 27 | 28 | 29 | insert into p_module (id, name, flag, 30 | url, sort_no, create_person, 31 | create_date, update_person, update_date 32 | ) 33 | values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{flag,jdbcType=VARCHAR}, 34 | #{url,jdbcType=VARCHAR}, #{sortNo,jdbcType=INTEGER}, #{createPerson,jdbcType=VARCHAR}, 35 | #{createDate,jdbcType=TIMESTAMP}, #{updatePerson,jdbcType=VARCHAR}, #{updateDate,jdbcType=TIMESTAMP} 36 | ) 37 | 38 | 39 | insert into p_module 40 | 41 | 42 | id, 43 | 44 | 45 | name, 46 | 47 | 48 | flag, 49 | 50 | 51 | url, 52 | 53 | 54 | sort_no, 55 | 56 | 57 | create_person, 58 | 59 | 60 | create_date, 61 | 62 | 63 | update_person, 64 | 65 | 66 | update_date, 67 | 68 | 69 | 70 | 71 | #{id,jdbcType=INTEGER}, 72 | 73 | 74 | #{name,jdbcType=VARCHAR}, 75 | 76 | 77 | #{flag,jdbcType=VARCHAR}, 78 | 79 | 80 | #{url,jdbcType=VARCHAR}, 81 | 82 | 83 | #{sortNo,jdbcType=INTEGER}, 84 | 85 | 86 | #{createPerson,jdbcType=VARCHAR}, 87 | 88 | 89 | #{createDate,jdbcType=TIMESTAMP}, 90 | 91 | 92 | #{updatePerson,jdbcType=VARCHAR}, 93 | 94 | 95 | #{updateDate,jdbcType=TIMESTAMP}, 96 | 97 | 98 | 99 | 100 | update p_module 101 | 102 | 103 | name = #{name,jdbcType=VARCHAR}, 104 | 105 | 106 | flag = #{flag,jdbcType=VARCHAR}, 107 | 108 | 109 | url = #{url,jdbcType=VARCHAR}, 110 | 111 | 112 | sort_no = #{sortNo,jdbcType=INTEGER}, 113 | 114 | 115 | create_person = #{createPerson,jdbcType=VARCHAR}, 116 | 117 | 118 | create_date = #{createDate,jdbcType=TIMESTAMP}, 119 | 120 | 121 | update_person = #{updatePerson,jdbcType=VARCHAR}, 122 | 123 | 124 | update_date = #{updateDate,jdbcType=TIMESTAMP}, 125 | 126 | 127 | where id = #{id,jdbcType=INTEGER} 128 | 129 | 130 | update p_module 131 | set name = #{name,jdbcType=VARCHAR}, 132 | flag = #{flag,jdbcType=VARCHAR}, 133 | url = #{url,jdbcType=VARCHAR}, 134 | sort_no = #{sortNo,jdbcType=INTEGER}, 135 | create_person = #{createPerson,jdbcType=VARCHAR}, 136 | create_date = #{createDate,jdbcType=TIMESTAMP}, 137 | update_person = #{updatePerson,jdbcType=VARCHAR}, 138 | update_date = #{updateDate,jdbcType=TIMESTAMP} 139 | where id = #{id,jdbcType=INTEGER} 140 | 141 | 142 | 143 | 144 | 145 | 150 | 156 | 164 | 174 | -------------------------------------------------------------------------------- /privilege-server/src/main/webapp/WEB-INF/ftl/main.ftl: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 创力 | 配置中心 - 主页 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | <#include "header.ftl" > 48 | 49 |
    50 |
    51 | 52 | 53 |
    54 | 55 | <#include "sidebar.ftl" > 56 | 57 | 58 |
    59 |
    60 | 61 |
    62 |
    63 | 64 |

    65 | 配置中心 66 |

    67 | 81 | 82 |
    83 |
    84 | 85 | 86 |
    87 |
    88 |
    89 |
    90 |
    91 | 配置中心 92 |
    93 |
    94 |
    95 | <#if hours?? && (hours < 12 && hours >= 5 ) > 96 | 上午好! 97 | <#elseif hours?? && (hours >= 12 && hours < 18 )> 98 | 下午好! 99 | <#else> 100 | 晚上好! 101 | 102 | ${user.fullname?default("")} 103 |
    104 |
    105 |
    106 |
    107 | 108 |
    109 |
    110 | 111 |
    112 | 113 | 114 | <#include "footer.ftl" > 115 | 116 | 117 | 118 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /privilege-data/src/main/resources/com/cl/privilege/mapper/DepartmentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | id, name, remark, parent_id, structure, sort_no, create_person, create_date, update_person, 18 | update_date 19 | 20 | 26 | 27 | delete from p_department 28 | where id = #{id,jdbcType=INTEGER} 29 | 30 | 31 | 32 | insert into p_department (id, name, remark, 33 | parent_id, structure, sort_no, 34 | create_person, create_date, update_person, 35 | update_date) 36 | values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, 37 | #{parentId,jdbcType=INTEGER}, #{structure,jdbcType=VARCHAR}, #{sortNo,jdbcType=INTEGER}, 38 | #{createPerson,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, #{updatePerson,jdbcType=VARCHAR}, 39 | #{updateDate,jdbcType=TIMESTAMP}) 40 | 41 | 42 | insert into p_department 43 | 44 | 45 | id, 46 | 47 | 48 | name, 49 | 50 | 51 | remark, 52 | 53 | 54 | parent_id, 55 | 56 | 57 | structure, 58 | 59 | 60 | sort_no, 61 | 62 | 63 | create_person, 64 | 65 | 66 | create_date, 67 | 68 | 69 | update_person, 70 | 71 | 72 | update_date, 73 | 74 | 75 | 76 | 77 | #{id,jdbcType=INTEGER}, 78 | 79 | 80 | #{name,jdbcType=VARCHAR}, 81 | 82 | 83 | #{remark,jdbcType=VARCHAR}, 84 | 85 | 86 | #{parentId,jdbcType=INTEGER}, 87 | 88 | 89 | #{structure,jdbcType=VARCHAR}, 90 | 91 | 92 | #{sortNo,jdbcType=INTEGER}, 93 | 94 | 95 | #{createPerson,jdbcType=VARCHAR}, 96 | 97 | 98 | #{createDate,jdbcType=TIMESTAMP}, 99 | 100 | 101 | #{updatePerson,jdbcType=VARCHAR}, 102 | 103 | 104 | #{updateDate,jdbcType=TIMESTAMP}, 105 | 106 | 107 | 108 | 109 | update p_department 110 | 111 | 112 | name = #{name,jdbcType=VARCHAR}, 113 | 114 | 115 | remark = #{remark,jdbcType=VARCHAR}, 116 | 117 | 118 | parent_id = #{parentId,jdbcType=INTEGER}, 119 | 120 | 121 | structure = #{structure,jdbcType=VARCHAR}, 122 | 123 | 124 | sort_no = #{sortNo,jdbcType=INTEGER}, 125 | 126 | 127 | create_person = #{createPerson,jdbcType=VARCHAR}, 128 | 129 | 130 | create_date = #{createDate,jdbcType=TIMESTAMP}, 131 | 132 | 133 | update_person = #{updatePerson,jdbcType=VARCHAR}, 134 | 135 | 136 | update_date = #{updateDate,jdbcType=TIMESTAMP}, 137 | 138 | 139 | where id = #{id,jdbcType=INTEGER} 140 | 141 | 142 | update p_department 143 | set name = #{name,jdbcType=VARCHAR}, 144 | remark = #{remark,jdbcType=VARCHAR}, 145 | parent_id = #{parentId,jdbcType=INTEGER}, 146 | structure = #{structure,jdbcType=VARCHAR}, 147 | sort_no = #{sortNo,jdbcType=INTEGER}, 148 | create_person = #{createPerson,jdbcType=VARCHAR}, 149 | create_date = #{createDate,jdbcType=TIMESTAMP}, 150 | update_person = #{updatePerson,jdbcType=VARCHAR}, 151 | update_date = #{updateDate,jdbcType=TIMESTAMP} 152 | where id = #{id,jdbcType=INTEGER} 153 | 154 | 155 | 156 | 157 | 158 | 163 | 169 | 172 | -------------------------------------------------------------------------------- /privilege-data/src/main/resources/com/cl/privilege/mapper/RoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, name, remark, create_person, create_date, update_person, update_date 15 | 16 | 22 | 23 | delete from p_role 24 | where id = #{id,jdbcType=INTEGER} 25 | 26 | 27 | insert into p_role (id, name, remark, 28 | create_person, create_date, update_person, 29 | update_date) 30 | values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, 31 | #{createPerson,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, #{updatePerson,jdbcType=VARCHAR}, 32 | #{updateDate,jdbcType=TIMESTAMP}) 33 | 34 | 35 | insert into p_role 36 | 37 | 38 | id, 39 | 40 | 41 | name, 42 | 43 | 44 | remark, 45 | 46 | 47 | create_person, 48 | 49 | 50 | create_date, 51 | 52 | 53 | update_person, 54 | 55 | 56 | update_date, 57 | 58 | 59 | 60 | 61 | #{id,jdbcType=INTEGER}, 62 | 63 | 64 | #{name,jdbcType=VARCHAR}, 65 | 66 | 67 | #{remark,jdbcType=VARCHAR}, 68 | 69 | 70 | #{createPerson,jdbcType=VARCHAR}, 71 | 72 | 73 | #{createDate,jdbcType=TIMESTAMP}, 74 | 75 | 76 | #{updatePerson,jdbcType=VARCHAR}, 77 | 78 | 79 | #{updateDate,jdbcType=TIMESTAMP}, 80 | 81 | 82 | 83 | 84 | update p_role 85 | 86 | 87 | name = #{name,jdbcType=VARCHAR}, 88 | 89 | 90 | remark = #{remark,jdbcType=VARCHAR}, 91 | 92 | 93 | create_person = #{createPerson,jdbcType=VARCHAR}, 94 | 95 | 96 | create_date = #{createDate,jdbcType=TIMESTAMP}, 97 | 98 | 99 | update_person = #{updatePerson,jdbcType=VARCHAR}, 100 | 101 | 102 | update_date = #{updateDate,jdbcType=TIMESTAMP}, 103 | 104 | 105 | where id = #{id,jdbcType=INTEGER} 106 | 107 | 108 | update p_role 109 | set name = #{name,jdbcType=VARCHAR}, 110 | remark = #{remark,jdbcType=VARCHAR}, 111 | create_person = #{createPerson,jdbcType=VARCHAR}, 112 | create_date = #{createDate,jdbcType=TIMESTAMP}, 113 | update_person = #{updatePerson,jdbcType=VARCHAR}, 114 | update_date = #{updateDate,jdbcType=TIMESTAMP} 115 | where id = #{id,jdbcType=INTEGER} 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | and r.name like CONCAT(#{name},'%') 125 | 126 | 127 | 128 | 129 | order by r.id desc 130 | 131 | 132 | delete r,prm,prr 133 | from p_role r 134 | left join p_role_module prm on r.id=prm.role_id 135 | left join p_role_resource prr on r.id=prr.role_id 136 | where r.id=#{id}; 137 | 138 | 139 | delete from p_role_module where role_id=#{roleId}; 140 | 141 | 142 | delete from p_role_resource where role_id=#{roleId}; 143 | 144 | 149 | 150 | 157 | 160 | 161 | insert into p_role_module(role_id,module_id) 162 | values 163 | 164 | (#{roleId},#{item}) 165 | 166 | ; 167 | 168 | 169 | insert into p_role_resource(role_id,resource_id) 170 | values 171 | 172 | (#{roleId},#{item}) 173 | 174 | ; 175 | 176 | 183 | 188 | -------------------------------------------------------------------------------- /privilege-server/src/main/java/com/cl/privilege/biz/impl/ResourceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.cl.privilege.biz.impl; 2 | 3 | import java.util.Collections; 4 | import java.util.Comparator; 5 | import java.util.Date; 6 | import java.util.HashMap; 7 | import java.util.HashSet; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.Set; 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Service; 14 | 15 | import com.cl.privilege.biz.IResourceService; 16 | import com.cl.privilege.mapper.ModuleMapper; 17 | import com.cl.privilege.mapper.ResourceMapper; 18 | import com.cl.privilege.model.Module; 19 | import com.cl.privilege.model.Resource; 20 | import com.cl.privilege.model.User; 21 | import com.cl.privilege.utils.StringUtil; 22 | 23 | @Service 24 | public class ResourceServiceImpl implements IResourceService { 25 | 26 | @Autowired 27 | private ModuleMapper moduleMapper; 28 | @Autowired 29 | private ResourceMapper resourceMapper; 30 | 31 | private void setResourceInsert(Resource resource,User operator) 32 | { 33 | Date d = new Date(); 34 | resource.setCreatePerson(operator.getUsername()); 35 | resource.setUpdatePerson(operator.getUsername()); 36 | resource.setCreateDate(d); 37 | resource.setUpdateDate(d); 38 | } 39 | private void setResourceUpdate(Resource resource,User operator) 40 | { 41 | Date d = new Date(); 42 | resource.setUpdatePerson(operator.getUsername()); 43 | resource.setUpdateDate(d); 44 | } 45 | 46 | @Override 47 | public List getResourceList() 48 | { 49 | return resourceMapper.getResourceList(); 50 | } 51 | 52 | @Override 53 | public List getResourceListByModuleFlag(List moduleFlags,Integer userId) { 54 | return resourceMapper.getResourceListByModuleFlag(moduleFlags,userId); 55 | } 56 | 57 | @Override 58 | public Resource getResourceById(Integer id) 59 | { 60 | return resourceMapper.selectByPrimaryKey(id); 61 | } 62 | 63 | @Override 64 | public Integer createResource(Resource resource,User user) 65 | { 66 | //生成structure 67 | String structure = "1"; 68 | Resource parentResource = resourceMapper.selectByPrimaryKey(resource.getParentId()); 69 | List resources = resourceMapper.getResourceListByParentId(resource.getParentId()); 70 | if(resources==null || resources.size()==0) 71 | { 72 | structure = parentResource.getStructure()+"-1"; 73 | } else { 74 | Integer parentLevel = parentResource.getStructure().split("-").length; 75 | 76 | for(Resource r:resources) 77 | { 78 | String[] structures = r.getStructure().split("-"); 79 | if(structures.length == parentLevel + 1) 80 | { 81 | if(StringUtil.isNumber(structures[structures.length-1])&&StringUtil.compareTo(structures[structures.length-1], structure)>0) 82 | { 83 | structure = structures[structures.length-1]; 84 | } 85 | } 86 | } 87 | structure = String.valueOf(Integer.parseInt(structure) + 1); 88 | structure = parentResource.getStructure()+"-" + structure; 89 | } 90 | 91 | resource.setStructure(structure); 92 | 93 | setResourceInsert(resource,user); 94 | 95 | return resourceMapper.insertSelective(resource); 96 | 97 | } 98 | 99 | @Override 100 | public Integer updateResourceById(Resource resource,User user) 101 | { 102 | setResourceUpdate(resource,user); 103 | return resourceMapper.updateByPrimaryKeySelective(resource); 104 | } 105 | 106 | @Override 107 | public Integer deleteResourceById(Integer id) 108 | { 109 | return resourceMapper.deleteByPrimaryKey(id); 110 | } 111 | 112 | 113 | @Override 114 | public Boolean isUsedByRole(Integer resourceId) { 115 | return resourceMapper.isUsedByRole(resourceId); 116 | } 117 | 118 | @Override 119 | public List getResourceListByRoleId(Integer roleId) 120 | { 121 | return resourceMapper.getResourceListByRoleId(roleId); 122 | } 123 | 124 | @Override 125 | public String getResourceTree(Integer roleId) 126 | { 127 | Set setResource = new HashSet(); 128 | 129 | if(roleId != null) 130 | { 131 | List tempResourceList = resourceMapper.getResourceListByRoleId(roleId); 132 | if(tempResourceList!=null && tempResourceList.size()>0) 133 | { 134 | for(Resource r:tempResourceList) 135 | { 136 | setResource.add(r.getId()); 137 | } 138 | } 139 | } 140 | 141 | List moduleList = moduleMapper.getModuleList(); 142 | List resourceList = resourceMapper.getResourceList(); 143 | Collections.sort(moduleList,new ComparatorModule()); 144 | Collections.sort(resourceList,new ComparatorResource()); 145 | 146 | Set setParent = new HashSet(); 147 | for(Resource r:resourceList) 148 | { 149 | setParent.add(r.getParentId()); 150 | } 151 | 152 | StringBuilder sb = new StringBuilder(); 153 | Map mapModule = new HashMap(); 154 | sb.append("["); 155 | int i = 0; 156 | for(Module m:moduleList) 157 | { 158 | mapModule.put(m.getFlag(), m.getId()); 159 | if(i!=0) 160 | { 161 | sb.append(","); 162 | } 163 | i++; 164 | sb.append("{") 165 | .append("\"id\":\"").append("m_").append(m.getId()).append("\"") 166 | .append(",\"parent\":\"").append("#\"") 167 | .append(",\"text\":\"").append(m.getName()).append("\"") 168 | .append(",\"li_attr\":{\"flag\":\"").append(m.getFlag()).append("\"}"); 169 | //前两个级别默认打开 170 | sb.append(",\"state\":{"); 171 | sb.append("\"opened\":true"); 172 | sb.append("}"); 173 | sb.append("}"); 174 | } 175 | i = 0; 176 | for(Resource r:resourceList) 177 | { 178 | int level = r.getStructure().split("-").length; 179 | 180 | sb.append(","); 181 | 182 | i++; 183 | sb.append("{") 184 | .append("\"id\":\"").append(r.getId()).append("\"") 185 | .append(",\"parent\":\"").append(r.getParentId()==0?("m_"+mapModule.get(r.getModuleFlag())):r.getParentId()).append("\"") 186 | .append(",\"text\":\"").append(r.getName()).append("\"") 187 | .append(",\"li_attr\":{\"flag\":\"").append(r.getModuleFlag()) 188 | .append("\",\"sortNo\":").append(r.getSortNo()).append("}"); 189 | //前两个级别默认打开 190 | if(level <=2) 191 | { 192 | sb.append(",\"state\":{\"opened\":true"); 193 | if(setResource.contains(r.getId())) 194 | { 195 | sb.append(",\"selected\":true"); 196 | } 197 | sb.append("}"); 198 | } else { 199 | 200 | if(setResource.contains(r.getId())) 201 | { 202 | sb.append(",\"state\":{\"opened\":true}"); 203 | } 204 | } 205 | //最后一个级别换个绿色图标 206 | if(!setParent.contains(r.getId())) 207 | { 208 | sb.append(", \"icon\": \"fa fa-briefcase icon-success\""); 209 | } 210 | sb.append("}"); 211 | } 212 | sb.append("]"); 213 | return sb.toString(); 214 | } 215 | 216 | /** 217 | * Module排序器,保证jsTree可以按照SortNo字段显示 218 | */ 219 | class ComparatorModule implements Comparator { 220 | public int compare(Module r1, Module r2) { 221 | return r1.getSortNo().compareTo(r2.getSortNo()); 222 | } 223 | } 224 | 225 | /** 226 | * Resource排序器,保证jsTree可以按照SortNo字段显示 227 | */ 228 | class ComparatorResource implements Comparator { 229 | public int compare(Resource r1, Resource r2) { 230 | int l1 = r1.getStructure().length(); 231 | int l2 = r2.getStructure().length(); 232 | if(l1 == l2 ) 233 | { 234 | return r1.getSortNo().compareTo(r2.getSortNo()); 235 | } 236 | return l1>l2?1:-1; 237 | } 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /privilege-server/src/main/resources/log4j.dtd: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | 54 | 55 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | 69 | 70 | 71 | 74 | 78 | 79 | 80 | 83 | 84 | 85 | 88 | 89 | 90 | 91 | 92 | 93 | 96 | 97 | 98 | 99 | 100 | 103 | 104 | 105 | 109 | 110 | 111 | 112 | 113 | 117 | 118 | 119 | 120 | 124 | 125 | 126 | 127 | 128 | 129 | 134 | 135 | 136 | 137 | 138 | 143 | 144 | 145 | 146 | 148 | 149 | 150 | 152 | 153 | 154 | 157 | 158 | 159 | 160 | 164 | 165 | 166 | 169 | 170 | 171 | 174 | 175 | 176 | 180 | 181 | 182 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 203 | 204 | 205 | 206 | 208 | 209 | 210 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 230 | 231 | 232 | 233 | 234 | 238 | --------------------------------------------------------------------------------