浏览代码

权限系统直接数据库控制,不需要具体些方法

gaodm 6 年之前
父节点
当前提交
8db23a6326

+ 20 - 17
sql/sys-user.sql

@@ -2,17 +2,6 @@
 CREATE DATABASE  `sys-user` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
 
 use `sys-user`;
-
-DROP TABLE IF EXISTS `sys_role`;
-CREATE TABLE `sys_role` (
-  `id` bigint(20) NOT NULL AUTO_INCREMENT,
-  `name` varchar(255) NOT NULL,
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-
 -- ----------------------------
 -- Table structure for sys_user
 -- ----------------------------
@@ -25,6 +14,20 @@ CREATE TABLE `sys_user` (
   UNIQUE KEY `uk_username` (`username`)
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 
+-- ----------------------------
+-- Table structure for sys_role
+-- ----------------------------
+DROP TABLE IF EXISTS `sys_role`;
+CREATE TABLE `sys_role` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `name` varchar(255) NOT NULL,
+  `roleLevel` int(11) DEFAULT NULL,
+  `descritpion` varchar(255) DEFAULT NULL,
+  `menuItems` varchar(255) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
+
+
 -- ----------------------------
 -- Table structure for user_role
 -- ----------------------------
@@ -41,10 +44,9 @@ DROP TABLE IF EXISTS `sys_permission`;
 CREATE TABLE `sys_permission` (
   `id` bigint(20) NOT NULL AUTO_INCREMENT,
   `name` varchar(255) NOT NULL,
-  `descritpion` varchar(255) DEFAULT NULL,
-  `url` varchar(255) NOT NULL,
-  `pid` bigint(20) DEFAULT NULL,
+  `permissionUrl` varchar(255) NOT NULL,
   `method` varchar(255) NOT NULL,
+  `descritpion` varchar(255) DEFAULT NULL,
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
 
@@ -60,18 +62,16 @@ CREATE TABLE `sys_role_permission` (
 INSERT INTO `sys_user` VALUES ('1', '{bcrypt}$2a$10$rlM./Q4dh5qXYmxFxUqkRetMPf6JewV/Hj/s4qBg/6U1.mzcue2oK', 'guest');
 INSERT INTO `sys_user` VALUES ('2', '{bcrypt}$2a$10$rlM./Q4dh5qXYmxFxUqkRetMPf6JewV/Hj/s4qBg/6U1.mzcue2oK', 'admin');
 
-
-INSERT INTO `sys_role` VALUES ('1', 'ROLE_USER');
-INSERT INTO `sys_role` VALUES ('2', 'ROLE_ADMIN');
+INSERT INTO `sys_role` VALUES ('1', '普通用户', null, null, null);
+INSERT INTO `sys_role` VALUES ('2', '管理员', null, null, null);
 
 INSERT INTO `sys_user_role` VALUES ('1', '1');
 INSERT INTO `sys_user_role` VALUES ('2', '2');
 
-INSERT INTO `sys_permission` VALUES ('1', '根据用户名获取用户','根据用户名获取用户','/user/{username}',null,"ALL");
-INSERT INTO `sys_permission` VALUES ('2', '根据用户id获取用户信息','根据用户id获取用户信息','/user/getById',null,"ALL");
+INSERT INTO `sys_permission` VALUES ('1', '根据用户名获取用户', '/user/{username}', "ALL", '根据用户名获取用户');
+INSERT INTO `sys_permission` VALUES ('2', '根据用户id获取用户信息','/user/getById', "ALL", '根据用户id获取用户信息');
 
 
 INSERT INTO `sys_role_permission` VALUES ('1', '2');
 INSERT INTO `sys_role_permission` VALUES ('2', '1');
 INSERT INTO `sys_role_permission` VALUES ('2', '2');
-

+ 18 - 29
uaa-service/src/main/java/com/diagbot/entity/Permission.java

@@ -11,7 +11,7 @@ import java.io.Serializable;
  * </p>
  *
  * @author gaodm
- * @since 2018-08-22
+ * @since 2018-08-23
  */
 @TableName("sys_permission")
 public class Permission implements Serializable {
@@ -23,14 +23,12 @@ public class Permission implements Serializable {
 
     private String name;
 
-    private String descritpion;
-
-    private String url;
-
-    private Long pid;
+    private String permissionUrl;
 
     private String method;
 
+    private String descritpion;
+
 
     public Long getId() {
         return id;
@@ -48,28 +46,12 @@ public class Permission implements Serializable {
         this.name = name;
     }
 
-    public String getDescritpion() {
-        return descritpion;
-    }
-
-    public void setDescritpion(String descritpion) {
-        this.descritpion = descritpion;
+    public String getPermissionUrl() {
+        return permissionUrl;
     }
 
-    public String getUrl() {
-        return url;
-    }
-
-    public void setUrl(String url) {
-        this.url = url;
-    }
-
-    public Long getPid() {
-        return pid;
-    }
-
-    public void setPid(Long pid) {
-        this.pid = pid;
+    public void setPermissionUrl(String permissionUrl) {
+        this.permissionUrl = permissionUrl;
     }
 
     public String getMethod() {
@@ -80,15 +62,22 @@ public class Permission implements Serializable {
         this.method = method;
     }
 
+    public String getDescritpion() {
+        return descritpion;
+    }
+
+    public void setDescritpion(String descritpion) {
+        this.descritpion = descritpion;
+    }
+
     @Override
     public String toString() {
         return "Permission{" +
         ", id=" + id +
         ", name=" + name +
-        ", descritpion=" + descritpion +
-        ", url=" + url +
-        ", pid=" + pid +
+        ", permissionUrl=" + permissionUrl +
         ", method=" + method +
+        ", descritpion=" + descritpion +
         "}";
     }
 }

+ 34 - 1
uaa-service/src/main/java/com/diagbot/entity/Role.java

@@ -11,7 +11,7 @@ import java.io.Serializable;
  * </p>
  *
  * @author gaodm
- * @since 2018-08-22
+ * @since 2018-08-23
  */
 @TableName("sys_role")
 public class Role implements Serializable {
@@ -23,6 +23,12 @@ public class Role implements Serializable {
 
     private String name;
 
+    private Integer roleLevel;
+
+    private String descritpion;
+
+    private String menuItems;
+
 
     public Long getId() {
         return id;
@@ -40,11 +46,38 @@ public class Role implements Serializable {
         this.name = name;
     }
 
+    public Integer getRoleLevel() {
+        return roleLevel;
+    }
+
+    public void setRoleLevel(Integer roleLevel) {
+        this.roleLevel = roleLevel;
+    }
+
+    public String getDescritpion() {
+        return descritpion;
+    }
+
+    public void setDescritpion(String descritpion) {
+        this.descritpion = descritpion;
+    }
+
+    public String getMenuItems() {
+        return menuItems;
+    }
+
+    public void setMenuItems(String menuItems) {
+        this.menuItems = menuItems;
+    }
+
     @Override
     public String toString() {
         return "Role{" +
         ", id=" + id +
         ", name=" + name +
+        ", roleLevel=" + roleLevel +
+        ", descritpion=" + descritpion +
+        ", menuItems=" + menuItems +
         "}";
     }
 }

+ 1 - 1
uaa-service/src/main/java/com/diagbot/service/UrlGrantedAuthority.java

@@ -3,7 +3,7 @@ package com.diagbot.service;
 import org.springframework.security.core.GrantedAuthority;
 
 /**
- * @Description:
+ * @Description: 自定义权限信息
  * @author: gaodm
  * @time: 2018/8/23 14:09
  */

+ 1 - 1
uaa-service/src/main/java/com/diagbot/service/UrlUserService.java

@@ -34,7 +34,7 @@ public class UrlUserService implements UserDetailsService {
             List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
             for (Permission permission : permissions) {
                 if (permission != null && permission.getName()!=null) {
-                    GrantedAuthority grantedAuthority = new UrlGrantedAuthority(permission.getUrl(),permission.getMethod());
+                    GrantedAuthority grantedAuthority = new UrlGrantedAuthority(permission.getPermissionUrl(),permission.getMethod());
                     grantedAuthorities.add(grantedAuthority);
                 }
             }

+ 1 - 1
user-service/src/main/java/com/diagbot/config/security/UrlAccessDecisionManager.java

@@ -16,7 +16,7 @@ import java.util.List;
 
 
 /**
- * @Description:
+ * @Description: 自定义权限拦截
  * @author: gaodm
  * @time: 2018/8/23 13:46
  */

+ 1 - 1
user-service/src/main/java/com/diagbot/config/security/UrlConfigAttribute.java

@@ -5,7 +5,7 @@ import org.springframework.security.access.ConfigAttribute;
 import javax.servlet.http.HttpServletRequest;
 
 /**
- * @Description:
+ * @Description: 自定义权限拦截
  * @author: gaodm
  * @time: 2018/8/23 13:47
  */

+ 1 - 1
user-service/src/main/java/com/diagbot/config/security/UrlFilterSecurityInterceptor.java

@@ -17,7 +17,7 @@ import javax.servlet.ServletResponse;
 import java.io.IOException;
 
 /**
- * @Description:
+ * @Description: 自定义权限拦截
  * @author: gaodm
  * @time: 2018/8/23 13:47
  */

+ 1 - 1
user-service/src/main/java/com/diagbot/config/security/UrlMetadataSourceService.java

@@ -11,7 +11,7 @@ import java.util.HashSet;
 import java.util.Set;
 
 /**
- * @Description:
+ * @Description: 自定义权限拦截
  * @author: gaodm
  * @time: 2018/8/23 13:47
  */