diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index a223f0f3c..dab2bf879 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -12,12 +12,9 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginBody; -import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.framework.web.service.SysLoginService; import com.ruoyi.framework.web.service.SysPermissionService; -import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.service.ISysMenuService; /** @@ -37,9 +34,6 @@ public class SysLoginController @Autowired private SysPermissionService permissionService; - @Autowired - private TokenService tokenService; - /** * 登录方法 * @@ -65,8 +59,7 @@ public class SysLoginController @GetMapping("getInfo") public AjaxResult getInfo() { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); - SysUser user = loginUser.getUser(); + SysUser user = SecurityUtils.getLoginUser().getUser(); // 角色集合 Set roles = permissionService.getRolePermission(user); // 权限集合 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java index 899c60eb6..227ac872d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java @@ -19,7 +19,6 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.framework.web.service.TokenService; @@ -46,7 +45,7 @@ public class SysProfileController extends BaseController @GetMapping public AjaxResult profile() { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); SysUser user = loginUser.getUser(); AjaxResult ajax = AjaxResult.success(user); ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); @@ -71,17 +70,17 @@ public class SysProfileController extends BaseController { return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); SysUser sysUser = loginUser.getUser(); user.setUserId(sysUser.getUserId()); user.setPassword(null); if (userService.updateUserProfile(user) > 0) { // 更新缓存用户信息 - loginUser.getUser().setNickName(user.getNickName()); - loginUser.getUser().setPhonenumber(user.getPhonenumber()); - loginUser.getUser().setEmail(user.getEmail()); - loginUser.getUser().setSex(user.getSex()); + sysUser.setNickName(user.getNickName()); + sysUser.setPhonenumber(user.getPhonenumber()); + sysUser.setEmail(user.getEmail()); + sysUser.setSex(user.getSex()); tokenService.setLoginUser(loginUser); return AjaxResult.success(); } @@ -95,7 +94,7 @@ public class SysProfileController extends BaseController @PutMapping("/updatePwd") public AjaxResult updatePwd(String oldPassword, String newPassword) { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); String userName = loginUser.getUsername(); String password = loginUser.getPassword(); if (!SecurityUtils.matchesPassword(oldPassword, password)) @@ -125,7 +124,7 @@ public class SysProfileController extends BaseController { if (!file.isEmpty()) { - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file); if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) { diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java index 4680b67ef..2870f6678 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java @@ -21,7 +21,6 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.service.SysPermissionService; @@ -123,7 +122,7 @@ public class SysRoleController extends BaseController if (roleService.updateRole(role) > 0) { // 更新缓存用户权限 - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = getLoginUser(); if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) { loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser())); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java index 047f2e942..e5469eca7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java @@ -21,14 +21,11 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.service.ISysPostService; import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysUserService; @@ -51,9 +48,6 @@ public class SysUserController extends BaseController @Autowired private ISysPostService postService; - @Autowired - private TokenService tokenService; - /** * 获取用户列表 */ @@ -83,8 +77,7 @@ public class SysUserController extends BaseController { ExcelUtil util = new ExcelUtil(SysUser.class); List userList = util.importExcel(file.getInputStream()); - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); - String operName = loginUser.getUsername(); + String operName = getUsername(); String message = userService.importUser(userList, updateSupport, operName); return AjaxResult.success(message); } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java index e9884302c..e4340d019 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java @@ -13,10 +13,8 @@ import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.spring.SpringUtils; -import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.common.utils.SecurityUtils; /** * 数据过滤处理 @@ -79,7 +77,7 @@ public class DataScopeAspect return; } // 获取当前的用户 - LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNotNull(loginUser)) { SysUser currentUser = loginUser.getUser(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java index 18500abe8..b7cf17bbe 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java @@ -27,10 +27,9 @@ import com.ruoyi.common.enums.HttpMethod; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.IpUtils; -import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.framework.manager.AsyncManager; import com.ruoyi.framework.manager.factory.AsyncFactory; -import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.domain.SysOperLog; /** @@ -85,7 +84,7 @@ public class LogAspect } // 获取当前的用户 - LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); // *========数据库日志=========*// SysOperLog operLog = new SysOperLog(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java index 003c7942a..3881053b5 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/PermissionService.java @@ -1,12 +1,11 @@ package com.ruoyi.framework.web.service; import java.util.Set; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; /** @@ -27,9 +26,6 @@ public class PermissionService private static final String PERMISSION_DELIMETER = ","; - @Autowired - private TokenService tokenService; - /** * 验证用户是否具备某权限 * @@ -42,7 +38,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) { return false; @@ -73,7 +69,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getPermissions())) { return false; @@ -101,7 +97,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) { return false; @@ -140,7 +136,7 @@ public class PermissionService { return false; } - LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); + LoginUser loginUser = SecurityUtils.getLoginUser(); if (StringUtils.isNull(loginUser) || CollectionUtils.isEmpty(loginUser.getUser().getRoles())) { return false;