| | |
| | | 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; |
| | |
| | | |
| | | |
| | | @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); |
| | | } |
| | | |
| | | |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | * @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); |
| | | } |
| | | |
| | | |
| | |
| | | * @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); |
| | | } |
| | | |
| | | } |
| | |
| | | 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; |
| | |
| | | |
| | | |
| | | @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); |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | |
| | | |
| | | @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); |
| | | } |
| | | |
| | | |
| | |
| | | * @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()); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | |
| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | // 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 { |
| | |
| | | } |
| | | |
| | | // security对象中存入登陆者信息 |
| | | return new UsernamePasswordAuthenticationToken(userId,authToken,authorities); |
| | | return new UsernamePasswordAuthenticationToken(contextCacheUser,authToken,authorities); |
| | | |
| | | } |
| | | |