From 2daea0060d0c617d431540619611106ea881f875 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 12 Jul 2020 15:06:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=BD=93=E5=89=8D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=9B=B8=E5=85=B3=E7=9A=84=E4=BF=A1=E6=81=AF=E3=80=81?= =?UTF-8?q?=E6=9D=83=E9=99=90=E7=AD=89=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=20Passport=20=E6=A8=A1=E5=9D=97=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E5=8A=A0=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/framework/util/ValidationUtil.java | 15 ++- .../controller/admin/AdminController.java | 9 -- .../passport/AdminPassportController.http | 13 -- .../passport/AdminPassportController.java | 36 ------ .../passport/PassportController.http | 27 +++++ .../passport/PassportController.java | 61 ++++++++++ ...ortLoginDTO.java => PassportLoginDTO.java} | 2 +- .../passport/vo/AdminPassportVO.java | 50 -------- .../passport/vo/PassportAccessTokenVO.java | 22 ++++ .../vo/PassportAdminMenuTreeNodeVO.java} | 6 +- .../passport/vo/PassportAdminVO.java | 18 +++ .../permission/ResourceController.http | 10 -- .../permission/ResourceController.java | 16 --- .../passport/AdminPassportConvert.java | 15 ++- .../convert/permission/ResourceConvert.java | 4 +- .../passport/AdminPassportManager.java | 37 ------ .../manager/passport/PassportManager.java | 114 ++++++++++++++++++ .../manager/permission/ResourceManager.java | 60 +-------- .../dal/mysql/dataobject/admin/AdminDO.java | 4 + .../service/permission/ResourceService.java | 3 +- 20 files changed, 277 insertions(+), 245 deletions(-) delete mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http delete mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.http create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java rename management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/dto/{AdminPassportLoginDTO.java => PassportLoginDTO.java} (94%) delete mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/AdminPassportVO.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAccessTokenVO.java rename management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/{permission/vo/AdminMenuTreeNodeVO.java => passport/vo/PassportAdminMenuTreeNodeVO.java} (86%) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAdminVO.java delete mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/AdminPassportManager.java create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/PassportManager.java diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java index 9b76c92a4..ff1de11dd 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java @@ -1,10 +1,14 @@ package cn.iocoder.common.framework.util; +import java.util.regex.Pattern; + /** * 校验工具类 */ public class ValidationUtil { + private static Pattern PATTERN_URL = Pattern.compile("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); + public static boolean isMobile(String mobile) { if (mobile == null || mobile.length() != 11) { return false; @@ -13,4 +17,13 @@ public class ValidationUtil { return true; } -} \ No newline at end of file + public static boolean isURL(String url) { + return StringUtils.hasText(url) + && PATTERN_URL.matcher(url).matches(); + } + + public static void main(String[] args) { + System.out.println(isURL("http://www.iocoder.cn")); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java index 4332c56f7..e48a93abb 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/admin/AdminController.java @@ -8,7 +8,6 @@ import cn.iocoder.mall.managementweb.controller.admin.dto.AdminPageDTO; import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateInfoDTO; import cn.iocoder.mall.managementweb.controller.admin.dto.AdminUpdateStatusDTO; import cn.iocoder.mall.managementweb.controller.admin.vo.AdminPageItemVO; -import cn.iocoder.mall.managementweb.controller.admin.vo.AdminVO; import cn.iocoder.mall.managementweb.manager.admin.AdminManager; import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder; import cn.iocoder.security.annotations.RequiresPermissions; @@ -62,12 +61,4 @@ public class AdminController { return success(true); } - // =========== 当前管理员 API =========== - - @GetMapping("/info") - @ApiOperation(value = "更新管理员状态") - public CommonResult info() { - return success(adminManager.getAdmin(AdminSecurityContextHolder.getAdminId())); - } - } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http deleted file mode 100644 index dd15e0e1b..000000000 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.http +++ /dev/null @@ -1,13 +0,0 @@ -### /passport/login 成功 -POST {{baseUrl}}/passport/login -Content-Type: application/x-www-form-urlencoded - -username=admin&password=buzhidao - -### /passport/login 密码不正确 -POST {{baseUrl}}/passport/login -Content-Type: application/x-www-form-urlencoded - -username=admin&password=1024 - -### diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.java deleted file mode 100644 index 5332a23fd..000000000 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/AdminPassportController.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.mall.managementweb.controller.passport; - -import cn.iocoder.common.framework.util.HttpUtil; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.managementweb.controller.passport.dto.AdminPassportLoginDTO; -import cn.iocoder.mall.managementweb.controller.passport.vo.AdminPassportVO; -import cn.iocoder.mall.managementweb.manager.passport.AdminPassportManager; -import cn.iocoder.security.annotations.RequiresNone; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; - -import static cn.iocoder.common.framework.vo.CommonResult.success; - -@Api(tags = "管理员 Passport API") -@RestController -@RequestMapping("/passport") -public class AdminPassportController { - - @Autowired - private AdminPassportManager adminPassportManager; - - @ApiOperation("账号密码登陆") - @PostMapping("/login") - @RequiresNone - public CommonResult login(AdminPassportLoginDTO loginDTO, - HttpServletRequest request) { - return success(adminPassportManager.login(loginDTO, HttpUtil.getIp(request))); - } - -} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.http new file mode 100644 index 000000000..b5814450e --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.http @@ -0,0 +1,27 @@ +### /passport/login 成功 +POST {{baseUrl}}/passport/login +Content-Type: application/x-www-form-urlencoded + +username=admin&password=buzhidao + +### /passport/login 密码不正确 +POST {{baseUrl}}/passport/login +Content-Type: application/x-www-form-urlencoded + +username=admin&password=1024 + +### /passport/info 成功 +GET {{baseUrl}}/passport/info +Authorization: Bearer {{accessToken}} + +### /passport/tree-admin-menu 成功 +GET {{baseUrl}}/passport/tree-admin-menu +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +### /passport/list-admin-permission 成功 +GET {{baseUrl}}/passport/list-admin-permission +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{accessToken}} + +### diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java new file mode 100644 index 000000000..079c07219 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/PassportController.java @@ -0,0 +1,61 @@ +package cn.iocoder.mall.managementweb.controller.passport; + +import cn.iocoder.common.framework.util.HttpUtil; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.passport.dto.PassportLoginDTO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAccessTokenVO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminMenuTreeNodeVO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminVO; +import cn.iocoder.mall.managementweb.manager.passport.PassportManager; +import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder; +import cn.iocoder.security.annotations.RequiresNone; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +import java.util.List; +import java.util.Set; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@Api(tags = "管理员 Passport API") +@RestController +@RequestMapping("/passport") +public class PassportController { + + @Autowired + private PassportManager passportManager; + + @PostMapping("/login") + @ApiOperation("账号密码登陆") + @RequiresNone + public CommonResult login(PassportLoginDTO loginDTO, + HttpServletRequest request) { + return success(passportManager.login(loginDTO, HttpUtil.getIp(request))); + } + + @GetMapping("/info") + @ApiOperation(value = "获得当前管理员信息") + public CommonResult info() { + return success(passportManager.getAdmin(AdminSecurityContextHolder.getAdminId())); + } + + @GetMapping("/tree-admin-menu") + @ApiOperation("获得当前管理员的菜单树") + public CommonResult> treeAdminMenu() { + return success(passportManager.treeAdminMenu(AdminSecurityContextHolder.getAdminId())); + } + + @GetMapping("/list-admin-permission") + @ApiOperation("获得当前管理员的权限列表") + public CommonResult> listAdminPermission() { + return success(passportManager.listAdminPermission(AdminSecurityContextHolder.getAdminId())); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/dto/AdminPassportLoginDTO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/dto/PassportLoginDTO.java similarity index 94% rename from management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/dto/AdminPassportLoginDTO.java rename to management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/dto/PassportLoginDTO.java index fd5c301da..035bd6531 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/dto/AdminPassportLoginDTO.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/dto/PassportLoginDTO.java @@ -13,7 +13,7 @@ import java.io.Serializable; @ApiModel("管理登录 DTO") @Data @Accessors(chain = true) -public class AdminPassportLoginDTO implements Serializable { +public class PassportLoginDTO implements Serializable { @ApiModelProperty(value = "用户名", required = true, example = "yudaoyuanma") @NotEmpty(message = "登陆账号不能为空") diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/AdminPassportVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/AdminPassportVO.java deleted file mode 100644 index 854e1744e..000000000 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/AdminPassportVO.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.mall.managementweb.controller.passport.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -@ApiModel("管理员通信证信息 VO") -@Data -@Accessors(chain = true) -public class AdminPassportVO { - - @ApiModel("认证信息") - @Data - @Accessors(chain = true) - public static class Authentication { - - @ApiModelProperty(value = "访问令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50") - private String accessToken; - @ApiModelProperty(value = "刷新令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50") - private String refreshToken; - @ApiModelProperty(value = "过期时间", required = true) - private Date expiresTime; - - } - - @ApiModel("管理员信息") - @Data - @Accessors(chain = true) - public static class Admin { - - @ApiModelProperty(value = "用户编号", required = true, example = "1") - private Integer id; - @ApiModelProperty(value = "真实姓名", required = true, example = "小王") - private String name; - - } - - /** - * 管理员信息 - */ - private Admin admin; - /** - * 认证信息 - */ - private Authentication authorization; - -} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAccessTokenVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAccessTokenVO.java new file mode 100644 index 000000000..48c63dbcd --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAccessTokenVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.managementweb.controller.passport.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +@ApiModel("访问令牌信息 VO") +@Data +@Accessors(chain = true) +public class PassportAccessTokenVO { + + @ApiModelProperty(value = "访问令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50") + private String accessToken; + @ApiModelProperty(value = "刷新令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50") + private String refreshToken; + @ApiModelProperty(value = "过期时间", required = true) + private Date expiresTime; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/AdminMenuTreeNodeVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAdminMenuTreeNodeVO.java similarity index 86% rename from management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/AdminMenuTreeNodeVO.java rename to management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAdminMenuTreeNodeVO.java index 7ac663d40..35e50b1ad 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/AdminMenuTreeNodeVO.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAdminMenuTreeNodeVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.managementweb.controller.permission.vo; +package cn.iocoder.mall.managementweb.controller.passport.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -10,7 +10,7 @@ import java.util.List; @ApiModel(value = "管理员拥有的菜单树", description = "一般用于首页菜单") @Data @Accessors(chain = true) -public class AdminMenuTreeNodeVO { +public class PassportAdminMenuTreeNodeVO { @ApiModelProperty(value = "菜单编号", required = true, example = "1") private Integer id; @@ -28,6 +28,6 @@ public class AdminMenuTreeNodeVO { /** * 子节点数组 */ - private List children; + private List children; } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAdminVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAdminVO.java new file mode 100644 index 000000000..f2db78162 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/passport/vo/PassportAdminVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.mall.managementweb.controller.passport.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +@ApiModel("管理员信息 VO") +@Data +@Accessors(chain = true) +public class PassportAdminVO { + + @ApiModelProperty(value = "真实名字", required = true, example = "小王") + private String name; + @ApiModelProperty(value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg") + private String avatar; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.http index 44d32866e..4e23931c8 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.http +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.http @@ -34,14 +34,4 @@ GET {{baseUrl}}/resource/tree Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{accessToken}} -### /resource/tree-admin-menu 成功 -GET {{baseUrl}}/resource/tree-admin-menu -Content-Type: application/x-www-form-urlencoded -Authorization: Bearer {{accessToken}} - -### /resource/list-admin-permission 成功 -GET {{baseUrl}}/resource/list-admin-permission -Content-Type: application/x-www-form-urlencoded -Authorization: Bearer {{accessToken}} - ### diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java index 404163191..dba74edca 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/ResourceController.java @@ -3,7 +3,6 @@ package cn.iocoder.mall.managementweb.controller.permission; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO; import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO; -import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; import cn.iocoder.mall.managementweb.manager.permission.ResourceManager; @@ -17,7 +16,6 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; -import java.util.Set; import static cn.iocoder.common.framework.vo.CommonResult.success; @@ -73,18 +71,4 @@ public class ResourceController { return success(resourceManager.treeResource()); } - // =========== 当前管理员相关 API =========== - - @GetMapping("/tree-admin-menu") - @ApiOperation("获得当前登陆的管理员的菜单树") - public CommonResult> treeAdminMenu() { - return success(resourceManager.treeAdminMenu(AdminSecurityContextHolder.getAdminId())); - } - - @GetMapping("/list-admin-permission") - @ApiOperation("获得当前登陆的管理员的权限列表") - public CommonResult> listAdminPermission() { - return success(resourceManager.listAdminPermission(AdminSecurityContextHolder.getAdminId())); - } - } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/passport/AdminPassportConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/passport/AdminPassportConvert.java index ef04b1b39..fe9a6fc96 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/passport/AdminPassportConvert.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/passport/AdminPassportConvert.java @@ -1,7 +1,8 @@ package cn.iocoder.mall.managementweb.convert.passport; -import cn.iocoder.mall.managementweb.controller.passport.dto.AdminPassportLoginDTO; -import cn.iocoder.mall.managementweb.controller.passport.vo.AdminPassportVO; +import cn.iocoder.mall.managementweb.controller.passport.dto.PassportLoginDTO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAccessTokenVO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminVO; import cn.iocoder.mall.systemservice.rpc.admin.dto.AdminVerifyPasswordDTO; import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO; import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO; @@ -13,12 +14,10 @@ public interface AdminPassportConvert { AdminPassportConvert INSTANCE = Mappers.getMapper(AdminPassportConvert.class); - AdminVerifyPasswordDTO convert(AdminPassportLoginDTO loginDTO); + AdminVerifyPasswordDTO convert(PassportLoginDTO bean); - default AdminPassportVO convert(AdminVO adminVO, OAuth2AccessTokenVO accessTokenVO) { - return new AdminPassportVO().setAdmin(convert(adminVO)).setAuthorization(convert(accessTokenVO)); - } - AdminPassportVO.Admin convert(AdminVO adminVO); - AdminPassportVO.Authentication convert(OAuth2AccessTokenVO accessTokenVO); + PassportAccessTokenVO convert(OAuth2AccessTokenVO bean); + + PassportAdminVO convert(AdminVO bean); } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java index 758875828..c7eb3a096 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java @@ -1,6 +1,6 @@ package cn.iocoder.mall.managementweb.convert.permission; -import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminMenuTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; @@ -25,6 +25,6 @@ public interface ResourceConvert { ResourceTreeNodeVO convertTreeNode(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO bean); - List convert(List list); + List convert(List list); } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/AdminPassportManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/AdminPassportManager.java deleted file mode 100644 index 12df450c9..000000000 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/AdminPassportManager.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.mall.managementweb.manager.passport; - -import cn.iocoder.common.framework.enums.UserTypeEnum; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.managementweb.controller.passport.dto.AdminPassportLoginDTO; -import cn.iocoder.mall.managementweb.controller.passport.vo.AdminPassportVO; -import cn.iocoder.mall.managementweb.convert.passport.AdminPassportConvert; -import cn.iocoder.mall.systemservice.rpc.admin.AdminRpc; -import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO; -import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc; -import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenDTO; -import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO; -import org.apache.dubbo.config.annotation.Reference; -import org.springframework.stereotype.Service; - -@Service -public class AdminPassportManager { - - @Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false") - private AdminRpc adminRpc; - @Reference(version = "${dubbo.consumer.OAuth2Rpc.version}", validation = "false") - private OAuth2Rpc oauth2Rpc; - - public AdminPassportVO login(AdminPassportLoginDTO loginDTO, String ip) { - // 校验管理员密码 - CommonResult verifyPasswordResult = adminRpc.verifyPassword(AdminPassportConvert.INSTANCE.convert(loginDTO).setIp(ip)); - verifyPasswordResult.checkError(); - // 创建访问令牌 - CommonResult createAccessTokenResult = oauth2Rpc.createAccessToken( - new OAuth2CreateAccessTokenDTO().setUserId(verifyPasswordResult.getData().getId()) - .setUserType(UserTypeEnum.ADMIN.getValue()).setCreateIp(ip)); - createAccessTokenResult.checkError(); - // 返回 - return AdminPassportConvert.INSTANCE.convert(verifyPasswordResult.getData(), createAccessTokenResult.getData()); - } - -} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/PassportManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/PassportManager.java new file mode 100644 index 000000000..c7d1b923a --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/passport/PassportManager.java @@ -0,0 +1,114 @@ +package cn.iocoder.mall.managementweb.manager.passport; + +import cn.iocoder.common.framework.enums.UserTypeEnum; +import cn.iocoder.common.framework.util.CollectionUtils; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.managementweb.controller.passport.dto.PassportLoginDTO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAccessTokenVO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminMenuTreeNodeVO; +import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminVO; +import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceTreeNodeVO; +import cn.iocoder.mall.managementweb.convert.passport.AdminPassportConvert; +import cn.iocoder.mall.managementweb.convert.permission.ResourceConvert; +import cn.iocoder.mall.managementweb.manager.permission.ResourceManager; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; +import cn.iocoder.mall.systemservice.rpc.admin.AdminRpc; +import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO; +import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc; +import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenDTO; +import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO; +import cn.iocoder.mall.systemservice.rpc.permission.ResourceRpc; +import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc; +import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; +import org.apache.dubbo.config.annotation.Reference; +import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +@Service +public class PassportManager { + + @Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false") + private AdminRpc adminRpc; + @Reference(version = "${dubbo.consumer.OAuth2Rpc.version}", validation = "false") + private OAuth2Rpc oauth2Rpc; + @Reference(version = "${dubbo.consumer.RoleRpc.version}", validation = "false") + private RoleRpc roleRpc; + @Reference(version = "${dubbo.consumer.ResourceRpc.version}", validation = "false") + private ResourceRpc resourceRpc; + + public PassportAccessTokenVO login(PassportLoginDTO loginDTO, String ip) { + // 校验管理员密码 + CommonResult verifyPasswordResult = adminRpc.verifyPassword(AdminPassportConvert.INSTANCE.convert(loginDTO).setIp(ip)); + verifyPasswordResult.checkError(); + // 创建访问令牌 + CommonResult createAccessTokenResult = oauth2Rpc.createAccessToken( + new OAuth2CreateAccessTokenDTO().setUserId(verifyPasswordResult.getData().getId()) + .setUserType(UserTypeEnum.ADMIN.getValue()).setCreateIp(ip)); + createAccessTokenResult.checkError(); + // 返回 + return AdminPassportConvert.INSTANCE.convert(createAccessTokenResult.getData()); + } + + public PassportAdminVO getAdmin(Integer adminId) { + CommonResult getAdminResult = adminRpc.getAdmin(adminId); + getAdminResult.checkError(); + return AdminPassportConvert.INSTANCE.convert(getAdminResult.getData()); + } + + /** + * 获得指定管理员的权限列表 + * + * @param adminId 管理员编号 + * @return 权限列表 + */ + public Set listAdminPermission(Integer adminId) { + // 获得管理员拥有的角色编号列表 + CommonResult> listAdminRoleIdsResult = roleRpc.listAdminRoleIds(adminId); + listAdminRoleIdsResult.checkError(); + if (CollectionUtils.isEmpty(listAdminRoleIdsResult.getData())) { + return Collections.emptySet(); + } + // 获得角色拥有的资源列表 + CommonResult> resourceVOResult = resourceRpc.listRoleResource( + listAdminRoleIdsResult.getData(), null); + resourceVOResult.checkError(); + return CollectionUtils.convertSet(resourceVOResult.getData(), cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO::getPermission); + } + + /** + * 获得管理员的菜单树 + * + * @param adminId 管理员编号 + * @return 菜单树 + */ + public List treeAdminMenu(Integer adminId) { + // 获得管理员拥有的角色编号列表 + CommonResult> listAdminRoleIdsResult = roleRpc.listAdminRoleIds(adminId); + listAdminRoleIdsResult.checkError(); + if (CollectionUtils.isEmpty(listAdminRoleIdsResult.getData())) { + return Collections.emptyList(); + } + // 获得角色拥有的资源(菜单)列表 + CommonResult> resourceVOResult = resourceRpc.listRoleResource( + listAdminRoleIdsResult.getData(), ResourceTypeEnum.MENU.getType()); + resourceVOResult.checkError(); + // 构建菜单树 + return this.buildAdminMenuTree(resourceVOResult.getData()); + } + + /** + * 构建菜单树 + * + * @param resourceVOs 资源(都是菜单)列表 + * @return 菜单树 + */ + private List buildAdminMenuTree(List resourceVOs) { + List treeNodeVOS = ResourceManager.buildResourceTree(resourceVOs); + // 虽然多了一层转换,但是可维护性更好。 + return ResourceConvert.INSTANCE.convert(treeNodeVOS); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java index c9ad9e5b8..61a22a84d 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java @@ -1,15 +1,12 @@ package cn.iocoder.mall.managementweb.manager.permission; -import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO; import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO; -import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; import cn.iocoder.mall.managementweb.convert.permission.ResourceConvert; import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum; -import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; import cn.iocoder.mall.systemservice.rpc.permission.ResourceRpc; import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc; import lombok.extern.slf4j.Slf4j; @@ -97,40 +94,7 @@ public class ResourceManager { CommonResult> listResourceResult = resourceRpc.listResource(); listResourceResult.checkError(); // 构建菜单树 - return this.buildResourceTree(listResourceResult.getData()); - } - - /** - * 获得管理员的菜单树 - * - * @param adminId 管理员编号 - * @return 菜单树 - */ - public List treeAdminMenu(Integer adminId) { - // 获得管理员拥有的角色编号列表 - CommonResult> listAdminRoleIdsResult = roleRpc.listAdminRoleIds(adminId); - listAdminRoleIdsResult.checkError(); - if (CollectionUtils.isEmpty(listAdminRoleIdsResult.getData())) { - return Collections.emptyList(); - } - // 获得角色拥有的资源(菜单)列表 - CommonResult> resourceVOResult = resourceRpc.listRoleResource( - listAdminRoleIdsResult.getData(), ResourceTypeEnum.MENU.getType()); - resourceVOResult.checkError(); - // 构建菜单树 - return this.buildAdminMenuTree(resourceVOResult.getData()); - } - - /** - * 构建菜单树 - * - * @param resourceVOs 资源(都是菜单)列表 - * @return 菜单树 - */ - private List buildAdminMenuTree(List resourceVOs) { - List treeNodeVOS = this.buildResourceTree(resourceVOs); - // 虽然多了一层转换,但是可维护性更好。 - return ResourceConvert.INSTANCE.convert(treeNodeVOS); + return buildResourceTree(listResourceResult.getData()); } /** @@ -139,7 +103,7 @@ public class ResourceManager { * @param resourceVOs 资源列表 * @return 资源树 */ - private List buildResourceTree(List resourceVOs) { + public static List buildResourceTree(List resourceVOs) { // 排序,保证菜单的有序性 resourceVOs.sort(Comparator.comparing(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO::getSort)); // 构建菜单树 @@ -164,24 +128,4 @@ public class ResourceManager { return treeNodeMap.values().stream().filter(node -> node.getPid().equals(ResourceIdEnum.ROOT.getId())).collect(Collectors.toList()); } - /** - * 获得指定管理员的权限列表 - * - * @param adminId 管理员编号 - * @return 权限列表 - */ - public Set listAdminPermission(Integer adminId) { - // 获得管理员拥有的角色编号列表 - CommonResult> listAdminRoleIdsResult = roleRpc.listAdminRoleIds(adminId); - listAdminRoleIdsResult.checkError(); - if (CollectionUtils.isEmpty(listAdminRoleIdsResult.getData())) { - return Collections.emptySet(); - } - // 获得角色拥有的资源列表 - CommonResult> resourceVOResult = resourceRpc.listRoleResource( - listAdminRoleIdsResult.getData(), null); - resourceVOResult.checkError(); - return CollectionUtils.convertSet(resourceVOResult.getData(), cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO::getPermission); - } - } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/AdminDO.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/AdminDO.java index 294988355..56b904e4f 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/AdminDO.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/dataobject/admin/AdminDO.java @@ -26,6 +26,10 @@ public class AdminDO extends BaseDO { * 真实名字 */ private String name; + /** + * 头像 + */ + private String avatar; /** * 部门编号 * diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java index 4e2a29b71..19ca7e43d 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java @@ -217,10 +217,11 @@ public class ResourceService { * @param resource 资源 */ private void initResourceProperty(ResourceDO resource) { - // 初始化资源为按钮类型时,无需 route 和 icon 属性 + // 资源为按钮类型时,无需 route、icon、view 属性,进行置空 if (ResourceTypeEnum.BUTTON.getType().equals(resource.getType())) { resource.setRoute(null); resource.setIcon(null); + resource.setView(null); } }