From 173506fe3e6e6fcba92bed2606dcfa9f6ef955a2 Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:08:49 +0000 Subject: [PATCH 01/16] add README.md. --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e42c02 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +## jwt-spring security -spring boot \ No newline at end of file -- Gitee From 4e4103f14d63e34ff294a8192c4dc211a464138b Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:10:20 +0000 Subject: [PATCH 02/16] add LICENSE. --- LICENSE | 1 + 1 file changed, 1 insertion(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3e42c02 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +## jwt-spring security -spring boot \ No newline at end of file -- Gitee From 374a3110b414d25d9da6470d54e8d09670830fc5 Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:13:21 +0000 Subject: [PATCH 03/16] Remove README.md --- README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 3e42c02..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -## jwt-spring security -spring boot \ No newline at end of file -- Gitee From 93ce3a4c857764074f9678a4c68493ec19d0002a Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:13:31 +0000 Subject: [PATCH 04/16] Remove LICENSE --- LICENSE | 1 - 1 file changed, 1 deletion(-) delete mode 100644 LICENSE diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 3e42c02..0000000 --- a/LICENSE +++ /dev/null @@ -1 +0,0 @@ -## jwt-spring security -spring boot \ No newline at end of file -- Gitee From b45a08f54c8eb95b037941771db86e9b7c7f9996 Mon Sep 17 00:00:00 2001 From: yjiewei Date: Tue, 7 Sep 2021 21:57:02 +0800 Subject: [PATCH 05/16] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9README.md=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index dbbfc7d..a575ba4 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,26 @@ ## 个人运动管理平台 -> ### 技术栈 +### 后端技术栈 +> [项目地址](https://gitee.com/jaysony/java-sport) +1. *Springboot* -*Springboot* +2. *Jwt* -*Vue* +3. *Spring Security* -*Jwt* - -*Spring Security* - -*MySQL* - -*Redis* +4. *MySQL* +5. *Redis* +### 前端技术栈 +> [项目地址](https://gitee.com/jaysony/vue-sport) +1. *Vue* +2. *axios* +3. *VueX* +4. *Vue Router* docker 安装MySQL之后启动,解决客户端连接不上的问题,阿里云安全组开放3306端口 @@ -35,5 +38,3 @@ spring security使用步骤: 3. 无权限时返回策略 `com.jackson.config.security.handler.JwtAccessDeniedHandler` 4. 认证失败返回策略`com.jackson.config.security.handler.JwtAuthenticationEntryPoint` 5. 认证策略`com.jackson.config.security.handler.JwtAuthenticationFilter` - -## -- Gitee From 8d1d0877d52af62d30e52f3e0825c0e36ffe9b53 Mon Sep 17 00:00:00 2001 From: yjiewei Date: Sun, 5 Sep 2021 20:51:16 +0800 Subject: [PATCH 06/16] =?UTF-8?q?feat:=E4=B8=8A=E4=BC=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sport.sql | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 sport.sql diff --git a/sport.sql b/sport.sql new file mode 100644 index 0000000..f4c19e4 --- /dev/null +++ b/sport.sql @@ -0,0 +1,136 @@ +/* + Navicat Premium Data Transfer + + Source Server : MySQL + Source Server Type : MySQL + Source Server Version : 80022 + Source Host : localhost:3306 + Source Schema : sport + + Target Server Type : MySQL + Target Server Version : 80022 + File Encoding : 65001 + + Date: 05/09/2021 17:16:04 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for roles_menus +-- ---------------------------- +DROP TABLE IF EXISTS `roles_menus`; +CREATE TABLE `roles_menus` ( + `role_id` bigint NULL DEFAULT NULL COMMENT '角色id', + `menu_id` bigint NULL DEFAULT NULL COMMENT '菜单权限id' +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of roles_menus +-- ---------------------------- + +-- ---------------------------- +-- Table structure for roles_permissions +-- ---------------------------- +DROP TABLE IF EXISTS `roles_permissions`; +CREATE TABLE `roles_permissions` ( + `role_id` bigint NULL DEFAULT NULL COMMENT '角色id', + `permission_id` bigint NULL DEFAULT NULL COMMENT '数据权限id' +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of roles_permissions +-- ---------------------------- + +-- ---------------------------- +-- Table structure for sys_menu +-- ---------------------------- +DROP TABLE IF EXISTS `sys_menu`; +CREATE TABLE `sys_menu` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `path` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单路径', + `icon` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单图标', + `title` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单名称', + `component` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单组件', + `parent_id` bigint NULL DEFAULT NULL COMMENT '父级菜单', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of sys_menu +-- ---------------------------- +INSERT INTO `sys_menu` VALUES (1, '/', '', '系统管理', 'home', NULL); +INSERT INTO `sys_menu` VALUES (2, '/system/user', '', '用户管理', 'system/user', 1); +INSERT INTO `sys_menu` VALUES (3, '/system/role', '', '角色管理', 'system/role', 1); +INSERT INTO `sys_menu` VALUES (4, '/system/permission', '', '权限管理', 'system/permission', 1); +INSERT INTO `sys_menu` VALUES (5, '/system/menu', '', '菜单管理', 'system/menu', 1); + +-- ---------------------------- +-- Table structure for sys_permission +-- ---------------------------- +DROP TABLE IF EXISTS `sys_permission`; +CREATE TABLE `sys_permission` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `label` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '权限标签', + `code` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '权限标签值', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of sys_permission +-- ---------------------------- + +-- ---------------------------- +-- Table structure for sys_role +-- ---------------------------- +DROP TABLE IF EXISTS `sys_role`; +CREATE TABLE `sys_role` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `label` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '角色信息', + `code` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '角色对应的标签值', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of sys_role +-- ---------------------------- + +-- ---------------------------- +-- Table structure for sys_user +-- ---------------------------- +DROP TABLE IF EXISTS `sys_user`; +CREATE TABLE `sys_user` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', + `user_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '登录名', + `password` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码', + `nick_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '昵称', + `sex` tinyint(1) NULL DEFAULT NULL COMMENT '性别(0男,1女,2未知)', + `avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户头像', + `address` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '地址', + `open_id` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '微信小程序openid', + `status` tinyint(1) NULL DEFAULT NULL COMMENT '状态,是否禁用', + `admin` tinyint(1) NULL DEFAULT NULL COMMENT '是否为管理员', + `phone_number` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '手机号码', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of sys_user +-- ---------------------------- +INSERT INTO `sys_user` VALUES (1, 'admin', '$2a$10$aeXsm9Q6KlgrqlirwzA0Guh97ag1qagk3covN2jCdSktil9g8vA/C', '管理员', 0, '', '', '1', 1, 1, ''); + +-- ---------------------------- +-- Table structure for user_roles +-- ---------------------------- +DROP TABLE IF EXISTS `user_roles`; +CREATE TABLE `user_roles` ( + `user_id` bigint NULL DEFAULT NULL COMMENT '用户id', + `role_id` bigint NULL DEFAULT NULL COMMENT '角色id' +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of user_roles +-- ---------------------------- + +SET FOREIGN_KEY_CHECKS = 1; -- Gitee From 97319e9ca9cffa1087e6005439deff035d6c8922 Mon Sep 17 00:00:00 2001 From: JacksonMa19 <1101101037@qq.com> Date: Sun, 5 Sep 2021 22:50:09 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E6=B5=8B=E8=AF=95push=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jackson/controller/{testctrl.java => TestCtrl.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/jackson/controller/{testctrl.java => TestCtrl.java} (96%) diff --git a/src/main/java/com/jackson/controller/testctrl.java b/src/main/java/com/jackson/controller/TestCtrl.java similarity index 96% rename from src/main/java/com/jackson/controller/testctrl.java rename to src/main/java/com/jackson/controller/TestCtrl.java index 7257662..db1c6a1 100644 --- a/src/main/java/com/jackson/controller/testctrl.java +++ b/src/main/java/com/jackson/controller/TestCtrl.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController @Api(value = "测试接口") -public class testctrl { +public class TestCtrl { @ApiOperation(value = "测试test") -- Gitee From 237edf92ec8243e600dc48f9d8143f7436bf511d Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 21:09:28 +0800 Subject: [PATCH 08/16] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9/user/getInfo?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0README.md=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=95=B2=E4=BB=A3=E7=A0=81=E8=A6=81=E7=BB=86=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +++++++++++ .../config/security/SecurityConfig.java | 12 +++------- .../JwtAccessDeniedHandler.java | 2 +- .../JwtAuthenticationEntryPoint.java | 2 +- .../JwtAuthenticationFilter.java | 23 +++++++++++-------- .../jackson/exception/GlobalException.java | 4 ++-- .../java/com/jackson/util/TokenUtils.java | 4 ++-- src/main/resources/application.yml | 7 ++---- 8 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 README.md rename src/main/java/com/jackson/config/security/{headler => handler}/JwtAccessDeniedHandler.java (96%) rename src/main/java/com/jackson/config/security/{headler => handler}/JwtAuthenticationEntryPoint.java (96%) rename src/main/java/com/jackson/config/security/{headler => handler}/JwtAuthenticationFilter.java (72%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e0356f2 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +docker 安装MySQL之后启动,解决客户端连接不上的问题,阿里云安全组开放3306端口 +```text +docker run --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:8.0.16 +docker exec -it mysql /bin/bash +ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; +ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; +flush privileges; +``` +spring security使用步骤: +1. 引入依赖包 `spring-boot-starter-security` +2. 加入全局配置类 `com.jackson.config.security.SecurityConfig` +3. 无权限时返回策略 `com.jackson.config.security.handler.JwtAccessDeniedHandler` +4. 认证失败返回策略`com.jackson.config.security.handler.JwtAuthenticationEntryPoint` +5. 认证策略`com.jackson.config.security.handler.JwtAuthenticationFilter` diff --git a/src/main/java/com/jackson/config/security/SecurityConfig.java b/src/main/java/com/jackson/config/security/SecurityConfig.java index 5cb1953..72e1386 100644 --- a/src/main/java/com/jackson/config/security/SecurityConfig.java +++ b/src/main/java/com/jackson/config/security/SecurityConfig.java @@ -1,16 +1,13 @@ package com.jackson.config.security; import com.jackson.config.security.contents.SecurityContents; -import com.jackson.config.security.headler.JwtAccessDeniedHandler; -import com.jackson.config.security.headler.JwtAuthenticationEntryPoint; -import com.jackson.config.security.headler.JwtAuthenticationFilter; +import com.jackson.config.security.handler.JwtAccessDeniedHandler; +import com.jackson.config.security.handler.JwtAuthenticationEntryPoint; +import com.jackson.config.security.handler.JwtAuthenticationFilter; import com.jackson.config.security.service.UserDetailServiceImpl; -import com.jackson.entity.SysUser; -import com.jackson.service.SysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -18,8 +15,6 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @@ -82,7 +77,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { auth.userDetailsService(userDetailService).passwordEncoder(passwordEncoder()); } - @Bean //注入spring容器里面 public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); diff --git a/src/main/java/com/jackson/config/security/headler/JwtAccessDeniedHandler.java b/src/main/java/com/jackson/config/security/handler/JwtAccessDeniedHandler.java similarity index 96% rename from src/main/java/com/jackson/config/security/headler/JwtAccessDeniedHandler.java rename to src/main/java/com/jackson/config/security/handler/JwtAccessDeniedHandler.java index afd0749..47a64ed 100644 --- a/src/main/java/com/jackson/config/security/headler/JwtAccessDeniedHandler.java +++ b/src/main/java/com/jackson/config/security/handler/JwtAccessDeniedHandler.java @@ -1,4 +1,4 @@ -package com.jackson.config.security.headler; +package com.jackson.config.security.handler; import com.fasterxml.jackson.databind.ObjectMapper; import com.jackson.util.Result; diff --git a/src/main/java/com/jackson/config/security/headler/JwtAuthenticationEntryPoint.java b/src/main/java/com/jackson/config/security/handler/JwtAuthenticationEntryPoint.java similarity index 96% rename from src/main/java/com/jackson/config/security/headler/JwtAuthenticationEntryPoint.java rename to src/main/java/com/jackson/config/security/handler/JwtAuthenticationEntryPoint.java index 6eeac91..90eaf3b 100644 --- a/src/main/java/com/jackson/config/security/headler/JwtAuthenticationEntryPoint.java +++ b/src/main/java/com/jackson/config/security/handler/JwtAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package com.jackson.config.security.headler; +package com.jackson.config.security.handler; import com.fasterxml.jackson.databind.ObjectMapper; import com.jackson.util.Result; diff --git a/src/main/java/com/jackson/config/security/headler/JwtAuthenticationFilter.java b/src/main/java/com/jackson/config/security/handler/JwtAuthenticationFilter.java similarity index 72% rename from src/main/java/com/jackson/config/security/headler/JwtAuthenticationFilter.java rename to src/main/java/com/jackson/config/security/handler/JwtAuthenticationFilter.java index 421230c..77ca4ae 100644 --- a/src/main/java/com/jackson/config/security/headler/JwtAuthenticationFilter.java +++ b/src/main/java/com/jackson/config/security/handler/JwtAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.jackson.config.security.headler; +package com.jackson.config.security.handler; import com.jackson.config.security.service.UserDetailServiceImpl; import com.jackson.util.TokenUtils; @@ -51,10 +51,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { if (httpServletRequest.getHeader("Authorization") == null) { System.out.println("没有token"); } -// if (!httpServletRequest.getMethod().equals("OPTIONS")) { -// httpServletResponse.setStatus(HttpServletResponse.SC_OK); -// -// } + //1.获取token String header = httpServletRequest.getHeader(tokenHeader); //2.判断token是否存在 @@ -70,13 +67,19 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { System.out.println("能获取token,但是没有登录信息"); //没有登录信息 直接登录 UserDetails userDetails = userDetailsService.loadUserByUsername(username); - //判断token是否有效 - if (tokenUtils.isExpiration(token) && userDetails.equals(userDetails.getUsername())) { - System.out.println("能获取token,但是无效"); - //刷新security中的用户信息 + + /* + 判断token是否有效 感觉username.equals(userDetails.getUsername())这一步有点多余 + TODO:你写的代码没有!导致这段代码没有执行,并且username.equals这里你也写错了,写成了userDetails + */ + if ( !tokenUtils.isExpiration(token) && username.equals(userDetails.getUsername())) { + System.out.println("能获取token,且未过期"); + // ★刷新security中的用户信息 这三行代码很重要 + // 1. 这里其实已经认定你登录上了,但是如何让系统验证通过就得通过 authenticationToken ,三个参数分别是 用户信息,凭证,权限 UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userDetails,null, userDetails.getAuthorities()); + // 2. 这里把请求request放到认证token上了,不明觉厉,这个也不知道是什么SecurityContextHolder(估计是安全的全局配置啥的,存放登录信息,这样配置之后就不会去401) authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest)); - SecurityContextHolder.getContext().setAuthentication(authenticationToken); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); // TODO:猜测:如果没有执行这几行就会抛出 AuthenticationException ,进而执行 401那块代码 } } } diff --git a/src/main/java/com/jackson/exception/GlobalException.java b/src/main/java/com/jackson/exception/GlobalException.java index bc7f7cc..e37b057 100644 --- a/src/main/java/com/jackson/exception/GlobalException.java +++ b/src/main/java/com/jackson/exception/GlobalException.java @@ -24,14 +24,14 @@ public class GlobalException { @ExceptionHandler(value = RuntimeException.class) public Result exception(RuntimeException e) { e.printStackTrace(); - log.error("系统运行时异常", e.getMessage()); + log.error("系统运行时异常 {}", e.getMessage()); return Result.fail(e.getMessage()); } @ResponseStatus(HttpStatus.FORBIDDEN) @ExceptionHandler(value = AccessDeniedException.class) public Result exception(AccessDeniedException e) { - log.info("权限不足------>" ,e.getMessage()); + log.info("权限不足------>{}" ,e.getMessage()); return Result.fail("权限不足,请联系管理员"); } diff --git a/src/main/java/com/jackson/util/TokenUtils.java b/src/main/java/com/jackson/util/TokenUtils.java index e9f8d1d..f2173f0 100644 --- a/src/main/java/com/jackson/util/TokenUtils.java +++ b/src/main/java/com/jackson/util/TokenUtils.java @@ -70,10 +70,10 @@ public class TokenUtils { return (String ) this.getTokenBody(token).get("username"); } - /**name + /** * 根据token判断是否过期 * @param token - * @return + * @return true说明过期 */ public Boolean isExpiration(String token) { return this.getTokenBody(token).getExpiration().before(new Date()); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 35f7550..47fe2fe 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,10 +7,8 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver username: root - password: 145792 - url: jdbc:mysql://localhost:3306/sport?useUnicode=true&characterEncoding=UTF-8 - - + password: 123456 + url: jdbc:mysql://47.107.59.76:3306/sport?useUnicode=true&characterEncoding=UTF-8 mybatis: mapper-locations: classpath:mapper/*.xml @@ -20,7 +18,6 @@ mybatis: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl map-underscore-to-camel-case: true - jwt: tokenHeader: Authorization secret: jackson123456 -- Gitee From 13054971fbffba55440abe6a901c15394dc37155 Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:08:49 +0000 Subject: [PATCH 09/16] add README.md. --- README.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/README.md b/README.md index e0356f2..3e42c02 100644 --- a/README.md +++ b/README.md @@ -1,14 +1 @@ -docker 安装MySQL之后启动,解决客户端连接不上的问题,阿里云安全组开放3306端口 -```text -docker run --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:8.0.16 -docker exec -it mysql /bin/bash -ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; -ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; -flush privileges; -``` -spring security使用步骤: -1. 引入依赖包 `spring-boot-starter-security` -2. 加入全局配置类 `com.jackson.config.security.SecurityConfig` -3. 无权限时返回策略 `com.jackson.config.security.handler.JwtAccessDeniedHandler` -4. 认证失败返回策略`com.jackson.config.security.handler.JwtAuthenticationEntryPoint` -5. 认证策略`com.jackson.config.security.handler.JwtAuthenticationFilter` +## jwt-spring security -spring boot \ No newline at end of file -- Gitee From 2373e546707a7829f22c3a6c4aad87b6c03c8c6c Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:10:20 +0000 Subject: [PATCH 10/16] add LICENSE. --- LICENSE | 1 + 1 file changed, 1 insertion(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3e42c02 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +## jwt-spring security -spring boot \ No newline at end of file -- Gitee From 8622c1c0f4f98156871f1f99601d68d42d5ab019 Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:13:21 +0000 Subject: [PATCH 11/16] Remove README.md --- README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 3e42c02..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -## jwt-spring security -spring boot \ No newline at end of file -- Gitee From 160c1b9c69faea6c630b50e20ceffc66d2a5915c Mon Sep 17 00:00:00 2001 From: yjiewei Date: Mon, 6 Sep 2021 14:13:31 +0000 Subject: [PATCH 12/16] Remove LICENSE --- LICENSE | 1 - 1 file changed, 1 deletion(-) delete mode 100644 LICENSE diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 3e42c02..0000000 --- a/LICENSE +++ /dev/null @@ -1 +0,0 @@ -## jwt-spring security -spring boot \ No newline at end of file -- Gitee From 8c5a26376b71ed44bd4252ea6905efb67b0ef382 Mon Sep 17 00:00:00 2001 From: JacksonMa19 <1101101037@qq.com> Date: Tue, 7 Sep 2021 09:19:40 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/jackson/entity/SysRole.java | 2 -- src/main/java/com/jackson/entity/SysUser.java | 30 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/jackson/entity/SysRole.java b/src/main/java/com/jackson/entity/SysRole.java index 97b81e9..46808c1 100644 --- a/src/main/java/com/jackson/entity/SysRole.java +++ b/src/main/java/com/jackson/entity/SysRole.java @@ -10,7 +10,5 @@ public class SysRole { private String label; private String code; - private List menus; - private List permissions; } diff --git a/src/main/java/com/jackson/entity/SysUser.java b/src/main/java/com/jackson/entity/SysUser.java index 7190329..26f3278 100644 --- a/src/main/java/com/jackson/entity/SysUser.java +++ b/src/main/java/com/jackson/entity/SysUser.java @@ -1,5 +1,6 @@ package com.jackson.entity; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -12,18 +13,45 @@ import java.util.List; @Data public class SysUser implements UserDetails { + @ApiModelProperty(value = "主键") private long id; + + @ApiModelProperty(value = "用户名") private String userName; + + @ApiModelProperty(value = "登录密码") private String password; + + @ApiModelProperty(value = "性别") private Integer sex; + + @ApiModelProperty(value = "头像") private String avatar; + + @ApiModelProperty(value = "地址") private String address; + + @ApiModelProperty(value = "微信唯一id") private String openId; + + @ApiModelProperty(value = "当前状态") private boolean status; + + @ApiModelProperty(value = "是否管理员") private boolean admin; - private String SysRolePhoneNumber; + + @ApiModelProperty(value = "电话号码") + private String phoneNumber; + + @ApiModelProperty(value = "角色信息") private List roles; + @ApiModelProperty(value = "用户对应的菜单列表") + private List menus; + + @ApiModelProperty(value = "用户的权限数据") + private List permissions; + /** * 权限数据 -- Gitee From 7093ad91fb40e66d64ef68345908f3e6f15e2d95 Mon Sep 17 00:00:00 2001 From: JacksonMa19 <1101101037@qq.com> Date: Tue, 7 Sep 2021 11:53:46 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9sql=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E8=AF=A2=E8=A7=92=E8=89=B2=E3=80=81=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E3=80=81=E6=9D=83=E9=99=90=20=E4=BF=AE=E6=94=B9menu?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/UserDetailServiceImpl.java | 6 +++ src/main/java/com/jackson/entity/SysMenu.java | 3 ++ .../com/jackson/entity/SysPermission.java | 3 ++ src/main/java/com/jackson/entity/SysUser.java | 4 +- .../com/jackson/mapper/SysUserMapper.java | 19 +++++++- src/main/resources/mapper/SysUserMapper.xml | 46 +++++++++++++++---- 6 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/jackson/config/security/service/UserDetailServiceImpl.java b/src/main/java/com/jackson/config/security/service/UserDetailServiceImpl.java index e6f04ed..b366b7e 100644 --- a/src/main/java/com/jackson/config/security/service/UserDetailServiceImpl.java +++ b/src/main/java/com/jackson/config/security/service/UserDetailServiceImpl.java @@ -36,8 +36,14 @@ public class UserDetailServiceImpl implements UserDetailsService { role.setCode("admin"); list.add(role); user.setRoles(list); + user.setMenus(userMapper.findMenus(null)); + } else { + + //非管理员需要查询角色信息 user.setRoles(userMapper.findRoles(user.getId())); + user.setMenus(userMapper.findMenus(user.getId())); + user.setPermissions(userMapper.findPermissions(user.getId())); } return user; diff --git a/src/main/java/com/jackson/entity/SysMenu.java b/src/main/java/com/jackson/entity/SysMenu.java index 2392347..9c0bdf0 100644 --- a/src/main/java/com/jackson/entity/SysMenu.java +++ b/src/main/java/com/jackson/entity/SysMenu.java @@ -1,7 +1,10 @@ package com.jackson.entity; +import lombok.Data; + import java.util.List; +@Data public class SysMenu { private long id; /** diff --git a/src/main/java/com/jackson/entity/SysPermission.java b/src/main/java/com/jackson/entity/SysPermission.java index 9ade9df..70f357a 100644 --- a/src/main/java/com/jackson/entity/SysPermission.java +++ b/src/main/java/com/jackson/entity/SysPermission.java @@ -1,5 +1,8 @@ package com.jackson.entity; +import lombok.Data; + +@Data public class SysPermission { private long id; private String label; diff --git a/src/main/java/com/jackson/entity/SysUser.java b/src/main/java/com/jackson/entity/SysUser.java index 26f3278..adac396 100644 --- a/src/main/java/com/jackson/entity/SysUser.java +++ b/src/main/java/com/jackson/entity/SysUser.java @@ -1,16 +1,16 @@ package com.jackson.entity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @Data +//@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class SysUser implements UserDetails { @ApiModelProperty(value = "主键") diff --git a/src/main/java/com/jackson/mapper/SysUserMapper.java b/src/main/java/com/jackson/mapper/SysUserMapper.java index 1109297..813d0fb 100644 --- a/src/main/java/com/jackson/mapper/SysUserMapper.java +++ b/src/main/java/com/jackson/mapper/SysUserMapper.java @@ -1,7 +1,10 @@ package com.jackson.mapper; +import com.jackson.entity.SysMenu; +import com.jackson.entity.SysPermission; import com.jackson.entity.SysRole; import com.jackson.entity.SysUser; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; import java.util.List; @@ -26,5 +29,19 @@ public interface SysUserMapper { * @param userId * @return */ - List findRoles(Long userId); + List findRoles(@Param("userId") Long userId); + + /** + * 据id查询菜单信息 + * @param userId + * @return + */ + List findMenus(@Param("userId") Long userId); + + /** + * 据id查询权限数据 + * @param userId + * @return + */ + List findPermissions(@Param("userId") Long userId); } diff --git a/src/main/resources/mapper/SysUserMapper.xml b/src/main/resources/mapper/SysUserMapper.xml index 8606320..8dc9963 100644 --- a/src/main/resources/mapper/SysUserMapper.xml +++ b/src/main/resources/mapper/SysUserMapper.xml @@ -29,8 +29,7 @@ - - + @@ -39,7 +38,7 @@ - + @@ -57,20 +56,49 @@ - + SELECT * FROM sys_permission + + WHERE + id IN ( + SELECT + permission_id + FROM + roles_permissions + WHERE role_id IN ( + SELECT + id + FROM + user_roles + WHERE user_id = #{userId})) + + - + \ No newline at end of file -- Gitee From 1d914da493ea7ff3dd39a9c86e9dbcd627aa9cd6 Mon Sep 17 00:00:00 2001 From: JacksonMa19 <1101101037@qq.com> Date: Tue, 7 Sep 2021 19:48:11 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9md=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=3D=3D=3D=3D>=20=E5=A2=9E=E5=8A=A0=E6=8A=80=E6=9C=AF=E6=A0=88?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..41286b9 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +## 个人运动管理平台 + +> ### 技术栈 + +*Springboot* + +*Vue* + +*Jwt* + +*Spring Security* + +*MySQL* + +*Redis* + + + + + + + +docker 安装MySQL之后启动,解决客户端连接不上的问题,阿里云安全组开放3306端口 + +```text +docker run --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:8.0.16 +docker exec -it mysql /bin/bash +ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; +ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; +flush privileges; +``` +spring security使用步骤: +1. 引入依赖包 `spring-boot-starter-security` +2. 加入全局配置类 `com.jackson.config.security.SecurityConfig` +3. 无权限时返回策略 `com.jackson.config.security.handler.JwtAccessDeniedHandler` +4. 认证失败返回策略`com.jackson.config.security.handler.JwtAuthenticationEntryPoint` +5. 认证策略`com.jackson.config.security.handler.JwtAuthenticationFilter` -- Gitee From 9367b670d1b8db66d69b7c1c7552230ccbc6d670 Mon Sep 17 00:00:00 2001 From: yjiewei Date: Tue, 7 Sep 2021 21:57:02 +0800 Subject: [PATCH 16/16] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9README.md=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 41286b9..a575ba4 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,26 @@ ## 个人运动管理平台 -> ### 技术栈 +### 后端技术栈 +> [项目地址](https://gitee.com/jaysony/java-sport) +1. *Springboot* -*Springboot* +2. *Jwt* -*Vue* +3. *Spring Security* -*Jwt* - -*Spring Security* - -*MySQL* - -*Redis* +4. *MySQL* +5. *Redis* +### 前端技术栈 +> [项目地址](https://gitee.com/jaysony/vue-sport) +1. *Vue* +2. *axios* +3. *VueX* +4. *Vue Router* docker 安装MySQL之后启动,解决客户端连接不上的问题,阿里云安全组开放3306端口 -- Gitee