From 92e340ae09192c05bce247a585907f5ef700fcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=B9=85=E5=93=A5?= <787952492@qq.com> Date: Mon, 13 Jun 2022 13:40:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/admin/auth/AuthController.java | 6 ++++++ .../module/system/service/auth/AdminAuthService.java | 11 +++++++++++ .../system/service/auth/AdminAuthServiceImpl.java | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java index 95d0a047..7a23992d 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java @@ -22,6 +22,7 @@ import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum; import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; import cn.iocoder.yudao.module.system.service.auth.AdminAuthService; +import cn.iocoder.yudao.module.system.service.auth.AdminAuthServiceImpl; import cn.iocoder.yudao.module.system.service.auth.UserSessionService; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.permission.RoleService; @@ -74,6 +75,9 @@ public class AuthController { @Resource private UserSessionService userSessionService; + @Resource + private AdminAuthServiceImpl adminAuthService; + @PostMapping("/login") @ApiOperation("使用账号密码登录") @@ -112,6 +116,8 @@ public class AuthController { } LoginUser login = AuthConvert.INSTANCE.convert(user); + //权限 + login.setRoleIds(adminAuthService.getUserRoleIds(login.getId())); String token = userSessionService.createUserSession(login, getClientIP(), getUserAgent()); log.info("TOKEN:::{}",token); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java index 36ef9797..759dd816 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; import javax.validation.Valid; +import java.util.Set; /** * 管理后台的认证 Service 接口 @@ -24,6 +25,16 @@ public interface AdminAuthService extends SecurityAuthFrameworkService { */ String login(@Valid AuthLoginReqVO reqVO, String userIp, String userAgent); + + + /** + * 获得 User 拥有的角色编号数组 + * + * @param userId 用户编号 + * @return 角色编号数组 + */ + Set getUserRoleIds(Long userId); + /** * 社交登录,使用 code 授权码 * diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java index 97f08d06..0b7d6e46 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java @@ -187,7 +187,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { * @param userId 用户编号 * @return 角色编号数组 */ - private Set getUserRoleIds(Long userId) { + public Set getUserRoleIds(Long userId) { return permissionService.getUserRoleIds(userId, singleton(CommonStatusEnum.ENABLE.getStatus())); }