From 00e40ce8b1de4da44d427a80f46d69fb90a9c075 Mon Sep 17 00:00:00 2001 From: songhuangfeng123 <shf18767906695@163.com> Date: 星期一, 18 七月 2022 09:02:10 +0800 Subject: [PATCH] Merge branch 'master' of https://sinanoaq.cn:8888/r/safePlatform-out into genchuang --- safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java | 8 ++- safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/security/TokenAuthenticationFilter.java | 16 ++++---- safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/RoleController.java | 20 +++++---- safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/UserController.java | 25 +++++++----- safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java | 26 ++++++++++--- safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/DepartmentController.java | 20 +++++---- 6 files changed, 69 insertions(+), 46 deletions(-) diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/DepartmentController.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/DepartmentController.java index 3bc2502..b44713c 100644 --- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/DepartmentController.java +++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/DepartmentController.java @@ -6,9 +6,11 @@ import com.gkhy.safePlatform.account.rpc.apimodel.model.req.DepAddRPCReqDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.req.DepModRPCReqDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepRPCRespDTO; +import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -33,24 +35,24 @@ @RequestMapping(value = "/add", method = RequestMethod.POST) - public ResultVO<String> addDepartment(Principal principal, @RequestBody DepAddRPCReqDTO depAddRPCReqDTO) { - String userId = principal.getName(); - return accountDepartmentService.addDep(Long.valueOf(userId) , depAddRPCReqDTO); + public ResultVO<String> addDepartment(Authentication authentication, @RequestBody DepAddRPCReqDTO depAddRPCReqDTO) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountDepartmentService.addDep(currentUser.getUid(), depAddRPCReqDTO); } @RequestMapping(value = "/mod", method = RequestMethod.POST) - public ResultVO<String> addDepartment(Principal principal, @RequestBody DepModRPCReqDTO depModRPCReqDTO) { - String userId = principal.getName(); - return accountDepartmentService.modDep(Long.valueOf(userId) , depModRPCReqDTO); + public ResultVO<String> addDepartment(Authentication authentication, @RequestBody DepModRPCReqDTO depModRPCReqDTO) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountDepartmentService.modDep(currentUser.getUid(), depModRPCReqDTO); } @RequestMapping(value = "/del", method = RequestMethod.POST) - public ResultVO<String> addDepartment(Principal principal, @RequestBody JSONObject json) { - String userId = principal.getName(); + public ResultVO<String> addDepartment(Authentication authentication, @RequestBody JSONObject json) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); Long depId = json.getLong("depId"); - return accountDepartmentService.delDep(Long.valueOf(userId) , depId); + return accountDepartmentService.delDep(currentUser.getUid(), depId); } diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java index d139e52..c7b3ca3 100644 --- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java +++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java @@ -4,10 +4,12 @@ import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.MenuRPCRespDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserLoginRPCRespDTO; +import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -30,8 +32,8 @@ } @RequestMapping("/menu") - public ResultVO<List<MenuRPCRespDTO>> getMenu(Principal principal, Long projectId){ - String userId = principal.getName(); - return accountAuthService.getMenu(Long.valueOf(userId), projectId); + public ResultVO<List<MenuRPCRespDTO>> getMenu(Authentication authentication, Long projectId){ + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountAuthService.getMenu(currentUser.getUid(), projectId); } } diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java index 07fc726..4db9b5f 100644 --- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java +++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java @@ -1,11 +1,14 @@ package com.gkhy.safePlatform.accountController; +import com.alibaba.fastjson.JSONObject; import com.gkhy.safePlatform.account.rpc.apimodel.AccountMenuService; import com.gkhy.safePlatform.account.rpc.apimodel.model.req.MenuAddRPCReqDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.MenuModRPCReqDTO; +import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -25,9 +28,9 @@ * @Description: 新增菜单 */ @RequestMapping(value = "/add",method = RequestMethod.POST) - public ResultVO<String> addMenu(Principal principal, @RequestBody MenuAddRPCReqDTO menuAddDto) { - String userId = principal.getName(); - return accountMenuService.addMenu(Long.valueOf(userId), menuAddDto); + public ResultVO<String> addMenu(Authentication authentication, @RequestBody MenuAddRPCReqDTO menuAddDto) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountMenuService.addMenu(currentUser.getUid(), menuAddDto); } @@ -35,9 +38,20 @@ * @Description: 新增菜单 */ @RequestMapping(value = "/mod",method = RequestMethod.POST) - public ResultVO<String> addMenu(Principal principal, @RequestBody MenuModRPCReqDTO menuModDto) { - String userId = principal.getName(); - return accountMenuService.modMenu(Long.valueOf(userId), menuModDto); + public ResultVO<String> addMenu(Authentication authentication, @RequestBody MenuModRPCReqDTO menuModDto) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountMenuService.modMenu(currentUser.getUid(), menuModDto); + } + + + /** + * @Description: 新增菜单 + */ + @RequestMapping(value = "/del",method = RequestMethod.POST) + public ResultVO<String> delMenu(Authentication authentication,@RequestBody JSONObject json ) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + Long id = json.getLong("id"); + return accountMenuService.delMenu(currentUser.getUid(), id); } } diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/RoleController.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/RoleController.java index d8946cc..34ff3cd 100644 --- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/RoleController.java +++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/RoleController.java @@ -7,9 +7,11 @@ import com.gkhy.safePlatform.account.rpc.apimodel.model.req.RoleAddRPCReqDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.req.RoleModRPCReqDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.RoleRPCRespDTO; +import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @@ -38,24 +40,24 @@ @RequestMapping(value = "/add",method = RequestMethod.POST) - public ResultVO<String> addRole(Principal principal, RoleAddRPCReqDTO roleAddRPCReqDTO){ - String userId = principal.getName(); - return accountRoleService.addRole(Long.valueOf(userId),roleAddRPCReqDTO); + public ResultVO<String> addRole(Authentication authentication, RoleAddRPCReqDTO roleAddRPCReqDTO){ + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountRoleService.addRole(currentUser.getUid(),roleAddRPCReqDTO); } @RequestMapping(value = "/mod",method = RequestMethod.POST) - public ResultVO<String> modRole(Principal principal, RoleModRPCReqDTO roleModRPCReqDTO){ - String userId = principal.getName(); - return accountRoleService.modRole(Long.valueOf(userId),roleModRPCReqDTO); + public ResultVO<String> modRole(Authentication authentication, RoleModRPCReqDTO roleModRPCReqDTO){ + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountRoleService.modRole(currentUser.getUid(),roleModRPCReqDTO); } @RequestMapping(value = "/del",method = RequestMethod.POST) - public ResultVO<String> modRole(Principal principal, JSONObject json){ - String userId = principal.getName(); + public ResultVO<String> modRole(Authentication authentication, JSONObject json){ + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); Long depId = json.getLong("depId"); - return accountRoleService.delRole(Long.valueOf(userId),depId); + return accountRoleService.delRole(currentUser.getUid(),depId); } } diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/UserController.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/UserController.java index 2d677b9..1573723 100644 --- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/UserController.java +++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/UserController.java @@ -9,12 +9,14 @@ import com.gkhy.safePlatform.account.rpc.apimodel.model.req.query.AccountRPCQuery; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepUserRPCRespDTO; import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.PersonalDetailRPCRespDTO; +import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.vo.ResultVO; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -33,8 +35,9 @@ @RequestMapping("/page/list") - public Object getUserPage(Principal principal, PageQuery<AccountRPCQuery> rpcQueryPageQuery) { - return accountUserService.getAccountPage(Long.valueOf(principal.getName()), rpcQueryPageQuery); + public Object getUserPage(Authentication authentication, PageQuery<AccountRPCQuery> rpcQueryPageQuery) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountUserService.getAccountPage(currentUser.getUid(), rpcQueryPageQuery); } @@ -42,18 +45,18 @@ * @Description: 获取部门下的用户列表 */ @RequestMapping(value = "/dep/list", method = RequestMethod.GET) - public ResultVO<List<DepUserRPCRespDTO>> depUserList(Principal principal, Long depId) { - String userId = principal.getName(); - return accountUserService.getDepList(Long.valueOf(userId), depId); + public ResultVO<List<DepUserRPCRespDTO>> depUserList(Authentication authentication, Long depId) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountUserService.getDepList(currentUser.getUid(), depId); } /** * @Description: 个人信息 */ @RequestMapping(value = "/personal", method = RequestMethod.GET) - public ResultVO<PersonalDetailRPCRespDTO> getPersonal(Principal principal) { - String userId = principal.getName(); - return accountUserService.getPersonalAccountDetail(Long.valueOf(userId)); + public ResultVO<PersonalDetailRPCRespDTO> getPersonal(Authentication authentication) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountUserService.getPersonalAccountDetail(currentUser.getUid()); } @@ -62,9 +65,9 @@ */ @RequestMapping(value = "/add", method = RequestMethod.POST) @PreAuthorize("hasRole('ROLE_admin')") - public ResultVO<String> addUser(Principal principal, @RequestBody AccountAddRPCReqDTO accountAddRPCReqDTO) { - String userId = principal.getName(); - return accountUserService.addAccount(Long.valueOf(userId), accountAddRPCReqDTO); + public ResultVO<String> addUser(Authentication authentication, @RequestBody AccountAddRPCReqDTO accountAddRPCReqDTO) { + ContextCacheUser currentUser = (ContextCacheUser) authentication.getPrincipal(); + return accountUserService.addAccount(currentUser.getUid(), accountAddRPCReqDTO); } diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/security/TokenAuthenticationFilter.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/security/TokenAuthenticationFilter.java index 8617cb2..1316c2a 100644 --- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/security/TokenAuthenticationFilter.java +++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/security/TokenAuthenticationFilter.java @@ -4,8 +4,8 @@ import com.alibaba.fastjson.JSONObject; import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService; import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService; -import com.gkhy.safePlatform.commons.co.CacheAuthority; -import com.gkhy.safePlatform.commons.co.CacheUser; +import com.gkhy.safePlatform.commons.co.ContextCacheAuthority; +import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.RedisKeyEnum; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.exception.BusinessException; @@ -86,9 +86,9 @@ throw new BusinessException(ResultCodes.CLIENT_CREDENTIALS_TOKEN_INVALID); }else{ Long userId = Long.valueOf(loginUserId); - CacheUser cacheUser = JSONObject.parseObject(o.toString(), CacheUser.class); - assert userId.equals(cacheUser.getUserId()); - if ( !authToken.equals(cacheUser.getAccessToken())) { + ContextCacheUser contextCacheUser = JSONObject.parseObject(o.toString(), ContextCacheUser.class); + assert userId.equals(contextCacheUser.getUid()); + if ( !authToken.equals(contextCacheUser.getAccessToken())) { throw new BusinessException(ResultCodes.CLIENT_CREDENTIALS_TOKEN_INVALID); } @@ -99,8 +99,8 @@ // 4.redis中是否存在 if (oo != null) { // 5.存在 - List<CacheAuthority> cacheAuthorities = JSONArray.parseArray(oo.toString(), CacheAuthority.class); - for (CacheAuthority cacheAuthority: cacheAuthorities) { + List<ContextCacheAuthority> cacheAuthorities = JSONArray.parseArray(oo.toString(), ContextCacheAuthority.class); + for (ContextCacheAuthority cacheAuthority: cacheAuthorities) { authorities.add(new SimpleGrantedAuthority(cacheAuthority.getAuthority())); } }else { @@ -146,7 +146,7 @@ } // security对象中存入登陆者信息 - return new UsernamePasswordAuthenticationToken(userId,authToken,authorities); + return new UsernamePasswordAuthenticationToken(contextCacheUser,authToken,authorities); } -- Gitblit v1.9.2