diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java index 7806ef3..3602fed 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java @@ -29,6 +29,21 @@ public interface IApiConsts { */ String LIST_DEPARTMENT_USER = "%s/resource/user/listdepartmentusers/%s"; + /** + * 角色用户列表 + */ + String LIST_ROLE_USER = "%s/resource/user/listroleusers/%s"; + + /** + * 组用户列表 + */ + String LIST_GROUP_USER = "%s/resource/user/listgroupusers/%s"; + + /** + * 职位用户列表 + */ + String LIST_POSITION_USER = "%s/resource/user/listpositionusers/%s"; + /** * 用户列表,通过ID获取 */ @@ -39,4 +54,18 @@ public interface IApiConsts { */ String LIST_ALL_USER = "%s/resource/user/listalluser"; + /** + * 获取用户所在部门用户列表(通过角色) + */ + String LIST_USER_DEPARTMENT_USER_BY_ROLE = "%s/resource/user/listuserdepartmentuserbyrole/%s/%s"; + + /** + * 获取用户所在部门用户列表(通过职位) + */ + String LIST_USER_DEPARTMENT_USER_BY_POSITION = "%s/resource/user/listuserdepartmentuserbyposition/%s/%s"; + + /** + * 获取用户职位列表 + */ + String LIST_USER_POSITION = "%s/resource/position/listuserposition/%s"; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/auth/AuthController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/auth/AuthController.java index 4e4f433..a5e199c 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/auth/AuthController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/auth/AuthController.java @@ -2,8 +2,10 @@ package com.cm.common.plugin.oauth.controller.apis.auth; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; +import com.cm.common.result.ErrorResult; import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultData; +import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.oauth2.client.OAuth2ClientContext; @@ -22,6 +24,7 @@ import java.util.Date; * @Date: 2019/3/18 2:47 PM * @Version: 1.0 **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "认证授权") @RestController @RequestMapping(ISystemConstant.API_PREFIX + "/auth") public class AuthController extends AbstractController { @@ -30,22 +33,16 @@ public class AuthController extends AbstractController { @Qualifier("oauth2ClientContext") private OAuth2ClientContext oAuth2ClientContext; - /** - * 获取当前access_token - * - * @return - */ + @ApiOperation(value = "获取当前access_token", notes = "获取当前access_token接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("getaccesstoken") public SuccessResultData getAccessToken() { OAuth2AccessToken oAuth2AccessToken = oAuth2ClientContext.getAccessToken(); return new SuccessResultData<>(oAuth2AccessToken.getValue()); } - /** - * 获取当前refreshtoken - * - * @return - */ + @ApiOperation(value = "获取当前refresh_token", notes = "获取当前refresh_token接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("getrefreshtoken") public SuccessResultData getRefreshToken() { OAuth2AccessToken oAuth2AccessToken = oAuth2ClientContext.getAccessToken(); diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java index 11c72e9..20b8a72 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java @@ -6,6 +6,8 @@ import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.AccessTokenException; import com.cm.common.exception.SearchException; import com.cm.common.plugin.oauth.service.department.IDepartmentService; +import com.cm.common.result.ErrorResult; +import io.swagger.annotations.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -26,6 +28,7 @@ import java.util.Map; * @Date: 2019-07-29 21:30 * @Version: 1.0 **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "组织部门管理") @RestController @RequestMapping(ISystemConstant.API_PREFIX + "/department") public class DepartmentController extends AbstractController { @@ -33,6 +36,11 @@ public class DepartmentController extends AbstractController { @Autowired private IDepartmentService departmentService; + @ApiOperation(value = "部门列表", notes = "部门列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "上级部门ID", paramType = "form") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartments") public JSONArray listDepartments() throws SearchException, AccessTokenException { Map params = requestParams(); diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/menu/MenuController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/menu/MenuController.java index 613006e..deae6f3 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/menu/MenuController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/menu/MenuController.java @@ -6,6 +6,8 @@ import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.AccessTokenException; import com.cm.common.exception.SearchException; import com.cm.common.plugin.oauth.service.menu.IMenuService; +import com.cm.common.result.ErrorResult; +import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -20,6 +22,7 @@ import java.util.Map; * @Date: 2019/4/22 1:59 PM * @Version: 1.0 **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "菜单管理") @RestController @RequestMapping(ISystemConstant.API_PREFIX + "/menu") public class MenuController extends AbstractController { @@ -27,6 +30,8 @@ public class MenuController extends AbstractController { @Autowired private IMenuService menuService; + @ApiOperation(value = "全部菜单列表", notes = "全部菜单列表接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listmenu") public JSONArray listMenu() throws AccessTokenException, SearchException { Map params = requestParams(); diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/position/PositionController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/position/PositionController.java new file mode 100644 index 0000000..5d614f5 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/position/PositionController.java @@ -0,0 +1,49 @@ +package com.cm.common.plugin.oauth.controller.apis.position; + +import com.alibaba.fastjson.JSONArray; +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.AccessTokenException; +import com.cm.common.exception.SearchException; +import com.cm.common.plugin.oauth.service.position.IPositionService; +import com.cm.common.result.ErrorResult; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: PositionController + * @Description: 职位 + * @Author: WangGeng + * @Date: 2019/8/30 5:33 下午 + * @Version: 1.0 + **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "职位管理") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/position") +public class PositionController extends AbstractController { + + @Autowired + private IPositionService positionService; + + @ApiOperation(value = "用户职位列表", notes = "用户职位列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listuserposition/{userId}") + public JSONArray listUserPosition(@PathVariable("userId") String userId) throws AccessTokenException, SearchException { + Map params = getParams(); + params.put("userId", userId); + return positionService.listUserPosition(params); + } + +} diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java index 5717a5d..9857990 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java @@ -6,6 +6,8 @@ import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.AccessTokenException; import com.cm.common.exception.SearchException; import com.cm.common.plugin.oauth.service.user.IUserService; +import com.cm.common.result.ErrorResult; +import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -21,6 +23,7 @@ import java.util.Map; * @Date: 2019-07-29 21:30 * @Version: 1.0 **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "用户管理") @RestController @RequestMapping(ISystemConstant.API_PREFIX + "/user") public class UserController extends AbstractController { @@ -28,13 +31,11 @@ public class UserController extends AbstractController { @Autowired private IUserService userService; - /** - * 部门人员列表 - * - * @param departmentId - * @return - * @throws SearchException - */ + @ApiOperation(value = "部门人员列表", notes = "部门人员列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartmentusers/{departmentId}") public JSONArray listDepartmentUsers(@PathVariable("departmentId") String departmentId) throws AccessTokenException, SearchException { Map params = getParams(); @@ -42,13 +43,47 @@ public class UserController extends AbstractController { return userService.listDepartmentUsers(params); } - /** - * 通过用户ID获取用户列表 - * - * @param userIds - * @return - * @throws AccessTokenException - */ + @ApiOperation(value = "角色人员列表", notes = "角色人员列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listroleusers/{roleId}") + public JSONArray listRoleUsers(@PathVariable("roleId") String roleId) throws SearchException, AccessTokenException { + Map params = getParams(); + params.put("roleId", roleId); + return userService.listRoleUsers(params); + } + + @ApiOperation(value = "组人员列表", notes = "组人员列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "groupId", value = "组ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listgroupusers/{groupId}") + public JSONArray listGroupUsers(@PathVariable("groupId") String groupId) throws SearchException, AccessTokenException { + Map params = getParams(); + params.put("groupId", groupId); + return userService.listGroupUsers(params); + } + + @ApiOperation(value = "职位人员列表", notes = "职位人员列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "positionId", value = "职位ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpositionusers/{groupId}") + public JSONArray listPositionUsers(@PathVariable("positionId") String positionId) throws SearchException, AccessTokenException { + Map params = getParams(); + params.put("positionId", positionId); + return userService.listPositionUsers(params); + } + + @ApiOperation(value = "通过用户ID获取用户列表", notes = "通过用户ID获取用户列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userIds", value = "用不ID列表", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listuserbyids/{userIds}") public JSONArray listUserByIds(@PathVariable("userIds") String userIds) throws AccessTokenException, SearchException { Map params = getParams(); @@ -56,15 +91,40 @@ public class UserController extends AbstractController { return userService.listUserByIds(params); } - /** - * 全部用户 - * - * @return - */ + @ApiOperation(value = "全部用户列表", notes = "全部用户列表接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listallusers") public JSONArray listAllUsers() throws AccessTokenException, SearchException { Map params = getParams(); return userService.listAllUsers(params); } + @ApiOperation(value = "获取用户所在部门用户列表(通过角色)", notes = "获取用户所在部门用户列表(通过角色)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"), + @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listuserdepartmentuserbyrole/{userId}/{roleId}") + public JSONArray listUserDepartmentUserByRole(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) throws SearchException, AccessTokenException { + Map params = getParams(); + params.put("userId", userId); + params.put("roleId", roleId); + return userService.listUserDepartmentUserByRole(params); + } + + @ApiOperation(value = "获取用户所在部门用户列表(通过职位)", notes = "获取用户所在部门用户列表(通过职位)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"), + @ApiImplicitParam(name = "positionId", value = "职位ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listuserdepartmentuserbyposition/{userId}/{positionId}") + public JSONArray listUserDepartmentUserByPosition(@PathVariable("userId") String userId, @PathVariable("positionId") String positionId) throws SearchException, AccessTokenException { + Map params = getParams(); + params.put("userId", userId); + params.put("positionId", positionId); + return userService.listUserDepartmentUserByPosition(params); + } + } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/position/IPositionService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/position/IPositionService.java new file mode 100644 index 0000000..5b547e5 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/position/IPositionService.java @@ -0,0 +1,31 @@ +package com.cm.common.plugin.oauth.service.position; + +import com.alibaba.fastjson.JSONArray; +import com.cm.common.exception.AccessTokenException; +import com.cm.common.exception.SearchException; + +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IPositionService + * @Description: 职位 + * @Author: WangGeng + * @Date: 2019/8/30 5:34 下午 + * @Version: 1.0 + **/ +public interface IPositionService { + + /** + * 用户职位列表 + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listUserPosition(Map params) throws AccessTokenException, SearchException; + +} diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/position/impl/PositionServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/position/impl/PositionServiceImpl.java new file mode 100644 index 0000000..ea8bccf --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/position/impl/PositionServiceImpl.java @@ -0,0 +1,46 @@ +package com.cm.common.plugin.oauth.service.position.impl; + +import com.alibaba.fastjson.JSONArray; +import com.cm.common.base.AbstractService; +import com.cm.common.config.properties.ApiPathProperties; +import com.cm.common.exception.AccessTokenException; +import com.cm.common.exception.SearchException; +import com.cm.common.plugin.IApiConsts; +import com.cm.common.plugin.oauth.service.position.IPositionService; +import com.cm.common.plugin.utils.RestTemplateUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: PositionServiceImpl + * @Description: 职位 + * @Author: WangGeng + * @Date: 2019/8/30 5:34 下午 + * @Version: 1.0 + **/ +@Service +public class PositionServiceImpl extends AbstractService implements IPositionService { + + @Autowired + private RestTemplateUtil restTemplateUtil; + @Autowired + private ApiPathProperties apiPathProperties; + + @Override + public JSONArray listUserPosition(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_USER_POSITION, apiPathProperties.getUserCenter(), params.get("userId").toString()), params); + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException("获取职位列表失败"); + } + return JSONArray.parseArray(result); + } + +} diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java index 7b1eb70..d251333 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java @@ -22,15 +22,47 @@ public interface IUserService { * * @param params * @return + * @throws AccessTokenException * @throws SearchException */ JSONArray listDepartmentUsers(Map params) throws AccessTokenException, SearchException; + /** + * 角色人员列表 + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listRoleUsers(Map params) throws AccessTokenException, SearchException; + + /** + * 组人员列表 + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listGroupUsers(Map params) throws AccessTokenException, SearchException; + + /** + * 职位人员列表 + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listPositionUsers(Map params) throws AccessTokenException, SearchException; + /** * 通过id列表获取用户ID * * @param params * @return + * @throws AccessTokenException * @throws SearchException */ JSONArray listUserByIds(Map params) throws AccessTokenException, SearchException; @@ -40,7 +72,29 @@ public interface IUserService { * * @param params * @return + * @throws AccessTokenException * @throws SearchException */ JSONArray listAllUsers(Map params) throws AccessTokenException, SearchException; + + /** + * 获取用户所在部门用户列表(通过角色) + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listUserDepartmentUserByRole(Map params) throws AccessTokenException, SearchException; + + /** + * 获取用户所在部门用户列表(通过职位) + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listUserDepartmentUserByPosition(Map params) throws AccessTokenException, SearchException; + } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java index 7d4cfbb..79babb9 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java @@ -45,6 +45,42 @@ public class UserServiceImpl extends AbstractService implements IUserService { return JSONArray.parseArray(result); } + @Override + public JSONArray listRoleUsers(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_ROLE_USER, apiPathProperties.getUserCenter(), params.get("roleId").toString()), params); + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException("获取人员列表失败"); + } + return JSONArray.parseArray(result); + } + + @Override + public JSONArray listGroupUsers(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_GROUP_USER, apiPathProperties.getUserCenter(), params.get("groupId").toString()), params); + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException("获取人员列表失败"); + } + return JSONArray.parseArray(result); + } + + @Override + public JSONArray listPositionUsers(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_POSITION_USER, apiPathProperties.getUserCenter(), params.get("positionId").toString()), params); + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException("获取人员列表失败"); + } + return JSONArray.parseArray(result); + } + @Override public JSONArray listUserByIds(Map params) throws AccessTokenException, SearchException { String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_USER_BY_ID, apiPathProperties.getUserCenter()), params); @@ -68,4 +104,28 @@ public class UserServiceImpl extends AbstractService implements IUserService { } return JSONArray.parseArray(result); } + + @Override + public JSONArray listUserDepartmentUserByRole(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_USER_DEPARTMENT_USER_BY_ROLE, apiPathProperties.getUserCenter(), params.get("userId").toString(), params.get("roleId").toString()), params); + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException("获取人员列表失败"); + } + return JSONArray.parseArray(result); + } + + @Override + public JSONArray listUserDepartmentUserByPosition(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_USER_DEPARTMENT_USER_BY_POSITION, apiPathProperties.getUserCenter(), params.get("userId").toString(), params.get("positionId").toString()), params); + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException("获取人员列表失败"); + } + return JSONArray.parseArray(result); + } } diff --git a/cloud-security/pom.xml b/cloud-security/pom.xml index b98ff32..dfc6090 100644 --- a/cloud-security/pom.xml +++ b/cloud-security/pom.xml @@ -18,7 +18,11 @@ 4.12 test - + + com.auth0 + java-jwt + 3.8.2 + diff --git a/cloud-security/src/test/java/com/cm/JwtTest.java b/cloud-security/src/test/java/com/cm/JwtTest.java new file mode 100644 index 0000000..987ce7b --- /dev/null +++ b/cloud-security/src/test/java/com/cm/JwtTest.java @@ -0,0 +1,35 @@ +package com.cm; + +import com.alibaba.fastjson.JSONObject; +import com.auth0.jwt.JWT; +import com.auth0.jwt.impl.JWTParser; +import com.auth0.jwt.interfaces.Claim; +import com.auth0.jwt.interfaces.DecodedJWT; +import org.junit.Test; + +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: JwtTest + * @Description: + * @Author: WangGeng + * @Date: 2019/8/29 3:22 下午 + * @Version: 1.0 + **/ +public class JwtTest { + + @Test + public void jwtParse() { + String accessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2luZm8iOnsicGFzc3dvcmQiOm51bGwsInVzZXJuYW1lIjoiYWRtaW4iLCJhdXRob3JpdGllcyI6W3sicm9sZUlkIjoiIiwicm9sZU5hbWUiOiIiLCJhcGlTYXZlTWVudSI6bnVsbCwiYXBpRGVsZXRlTWVudSI6bnVsbCwiYXBpVXBkYXRlTWVudSI6bnVsbCwiYXBpUXVlcnlNZW51IjpudWxsLCJyZXNvdXJjZVNhdmVNZW51IjpudWxsLCJyZXNvdXJjZURlbGV0ZU1lbnUiOm51bGwsInJlc291cmNlVXBkYXRlTWVudSI6bnVsbCwicmVzb3VyY2VRdWVyeU1lbnUiOm51bGwsInJvdXRlU2F2ZU1lbnUiOm51bGwsInJvdXRlVXBkYXRlTWVudSI6bnVsbCwicm91dGVRdWVyeU1lbnUiOm51bGwsImF1dGhvcml0eSI6IlJPTEVfQUxMIn0seyJyb2xlSWQiOiIiLCJyb2xlTmFtZSI6IiIsImFwaVNhdmVNZW51IjpudWxsLCJhcGlEZWxldGVNZW51IjpudWxsLCJhcGlVcGRhdGVNZW51IjpudWxsLCJhcGlRdWVyeU1lbnUiOm51bGwsInJlc291cmNlU2F2ZU1lbnUiOm51bGwsInJlc291cmNlRGVsZXRlTWVudSI6bnVsbCwicmVzb3VyY2VVcGRhdGVNZW51IjpudWxsLCJyZXNvdXJjZVF1ZXJ5TWVudSI6bnVsbCwicm91dGVTYXZlTWVudSI6bnVsbCwicm91dGVVcGRhdGVNZW51IjpudWxsLCJyb3V0ZVF1ZXJ5TWVudSI6bnVsbCwiYXV0aG9yaXR5IjoiUk9MRV9HUk9VUF9BTEwifV0sImFjY291bnROb25FeHBpcmVkIjp0cnVlLCJhY2NvdW50Tm9uTG9ja2VkIjp0cnVlLCJjcmVkZW50aWFsc05vbkV4cGlyZWQiOnRydWUsImVuYWJsZWQiOnRydWUsInVzZXJJZCI6IjEiLCJ1c2VyTmFtZSI6ImFkbWluIiwidXNlclBob25lIjoiMTg4ODg4ODg4ODgiLCJyb2xlcyI6bnVsbCwiZ3JvdXBzIjpudWxsLCJkZXBhcnRtZW50cyI6bnVsbH0sInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsiYWxsIl0sImV4cCI6MTU2NzA2NzgyNSwiYXV0aG9yaXRpZXMiOlsie1wiYXV0aG9yaXR5XCI6XCJST0xFX0FMTFwiX3dnX1wicm9sZUlkXCI6XCJcIl93Z19cInJvbGVOYW1lXCI6XCJcIn0iLCJ7XCJhdXRob3JpdHlcIjpcIlJPTEVfR1JPVVBfQUxMXCJfd2dfXCJyb2xlSWRcIjpcIlwiX3dnX1wicm9sZU5hbWVcIjpcIlwifSJdLCJqdGkiOiI0MmRiMGY2Ny03Yzc0LTRmMzctYTljZS1kZTA2N2U3MDA2NTYiLCJjbGllbnRfaWQiOiJkMjlmNDg4MGI4ZGY0NmVhYjA5MDMzOWNhYzA1NjgwOSJ9.gMsExojfKVgiHx8SOCWWU55DfQAB-xftIokbMETnKvE"; + DecodedJWT decodedJWT = JWT.decode(accessToken); + Claim claim = decodedJWT.getClaim("user_info"); + JSONObject cliamObj = claim.as(JSONObject.class); + String userId = cliamObj.getString("userId"); + String userName = cliamObj.getString("userName"); + System.out.println(String.format("%s:%s", userId, userName)); + } + +}