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 cf2897a..a2bfc6a 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 @@ -93,4 +93,14 @@ public interface IApiConsts { * 用户详情 */ String GET_USER_DETAIL = "%s/resource/user/getuserdetail/%s"; + + /** + * 密码状态 + */ + String GET_PASSWORD_STATUS = "%s/resource/user/getpasswordstatus"; + + /** + * 修改密码 + */ + String UPDATE_USER_PASSWORD = "%s/resource/user/updateuserpassword"; } 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 6e7744d..d14d782 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 @@ -2,12 +2,16 @@ package com.cm.common.plugin.oauth.controller.apis.user; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.cm.common.annotation.CheckRequestBodyAnnotation; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.AccessTokenException; +import com.cm.common.exception.ParamsException; import com.cm.common.exception.SearchException; +import com.cm.common.exception.UpdateException; import com.cm.common.plugin.oauth.service.user.IUserService; import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResult; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -140,4 +144,21 @@ public class UserController extends AbstractController { return userService.getUserDetail(params); } + @ApiOperation(value = "获取密码状态", notes = "获取密码状态接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("getpasswordstatus") + public JSONObject getPasswordStatus() { + return userService.getPasswordStatus(); + } + + @ApiOperation(value = "修改密码", notes = "修改密码接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("updateuserpassword") + @CheckRequestBodyAnnotation + public SuccessResult updateUserPassword(@RequestBody Map params) throws ParamsException, SearchException, UpdateException { +// params.put("oldPassword", appChangePasswordVO.getOldPassword()); +// params.put("newPassword", appChangePasswordVO.getNewPassword()); + return userService.updateUserPassword(params); + } + } \ No newline at end of file diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java index e133103..aa7173c 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java @@ -40,4 +40,11 @@ public class UserRouteController extends AbstractController { return mv; } + @ApiOperation(value = "修改密码页面", notes = "修改密码页面接口") + @GetMapping("updatepassword") + public ModelAndView updatePassword() { + ModelAndView mv = new ModelAndView("user/update-password.html"); + return mv; + } + } 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 67a798a..4f18d95 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 @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cm.common.exception.AccessTokenException; import com.cm.common.exception.SearchException; +import com.cm.common.result.SuccessResult; import java.util.Map; @@ -127,5 +128,33 @@ public interface IUserService { */ JSONObject getUserDetail(Map params) throws AccessTokenException, SearchException; + /** + * 角色用户列表 + * + * @param accessToken + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ JSONArray listRoleUsers(String accessToken, Map params) throws AccessTokenException, SearchException; + + /** + * 查询密码状态 + * + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONObject getPasswordStatus() throws AccessTokenException, SearchException; + + /** + * 更新用户密码 + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + SuccessResult updateUserPassword(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 484a67d..5ee111b 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 @@ -9,10 +9,13 @@ 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.user.IUserService; +import com.cm.common.plugin.oauth.token.ClientTokenManager; import com.cm.common.plugin.utils.RestTemplateUtil; +import com.cm.common.result.SuccessResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; import java.util.Map; /** @@ -38,142 +41,100 @@ public class UserServiceImpl extends AbstractService implements IUserService { @Override public JSONArray listDepartmentUsers(Map params) throws AccessTokenException, SearchException { String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_DEPARTMENT_USER, apiPathProperties.getUserCenter(), params.get("departmentId").toString()), params); - if (result == null) { - throw new AccessTokenException("认证失败"); - } - if (result.isEmpty()) { - throw new SearchException("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); 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("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); 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("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); 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("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); 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); - if (result == null) { - throw new AccessTokenException("认证失败"); - } - if (result.isEmpty()) { - throw new SearchException("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); return JSONArray.parseArray(result); } @Override public JSONArray listAllUsers(Map params) throws AccessTokenException, SearchException { String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_ALL_USER, apiPathProperties.getUserCenter()), params); - if (result == null) { - throw new AccessTokenException("认证失败"); - } - if (result.isEmpty()) { - throw new SearchException("获取全部人员列表失败"); - } + searchResourceResult(result, "获取全部人员列表失败"); return JSONArray.parseArray(result); } @Override public JSONArray listUserDepartmentUser(Map params) throws AccessTokenException, SearchException { String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_USER_DEPARTMENT_USER, apiPathProperties.getUserCenter(), params.get("userId").toString()), params); - if (result == null) { - throw new AccessTokenException("认证失败"); - } - if (result.isEmpty()) { - throw new SearchException("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); 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("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); return JSONArray.parseArray(result); } @Override public JSONArray listUserDepartmentUserByRole(String token, Map params) throws SearchException { String result = restTemplateUtil.doGetFormForApp(token, String.format(IApiConsts.APP_LIST_USER_DEPARTMENT_USER_BY_ROLE, apiPathProperties.getUserCenter(), params.get("userId").toString(), params.get("roleId").toString()), params); - if (result == null || result.isEmpty()) { - throw new SearchException("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); 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("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); return JSONArray.parseArray(result); } @Override public JSONObject getUserDetail(Map params) throws AccessTokenException, SearchException { String result = restTemplateUtil.doPostForm(String.format(IApiConsts.GET_USER_DETAIL, apiPathProperties.getUserCenter(), params.get("userId").toString()), params); - if (result == null) { - throw new AccessTokenException("认证失败"); - } - if (result.isEmpty()) { - throw new SearchException("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); return JSONObject.parseObject(result); } @Override public JSONArray listRoleUsers(String accessToken, Map params) throws AccessTokenException, SearchException { String result = oAuthRestTemplateComponent.doPostFormForOAuth2Client(accessToken, 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("获取人员列表失败"); - } + searchResourceResult(result, "获取人员列表失败"); return JSONArray.parseArray(result); } + @Override + public JSONObject getPasswordStatus() throws AccessTokenException, SearchException { + Map params = getHashMap(0); + String result = restTemplateUtil.doGetForm(String.format(IApiConsts.GET_PASSWORD_STATUS, apiPathProperties.getUserCenter()), params); + searchResourceResult(result, "获取密码状态失败"); + return JSONObject.parseObject(result); + } + + @Override + public SuccessResult updateUserPassword(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.UPDATE_USER_PASSWORD, apiPathProperties.getUserCenter()), params); + updateResourceResult(result, "密码修改失败"); + return new SuccessResult(); + } + } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java index e60b23d..97d4264 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java @@ -15,6 +15,9 @@ import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestClientResponseException; import org.springframework.web.client.RestTemplate; import java.util.Map; @@ -172,7 +175,10 @@ public class RestTemplateUtil { try { LOG.debug("Rest post:\nurl: {},\nparams: {},\nhttpHeaders: {},\nqueryParams: {}", url, params, httpHeaders, queryParams); return getResponse(restTemplate.postForEntity(url, httpEntity, String.class)); - } catch (Exception e) { + } catch (HttpClientErrorException e) { + if (e.getRawStatusCode() == HttpStatus.BAD_REQUEST.value()) { + return e.getResponseBodyAsString(); + } LOG.error(e.getMessage(), e); return null; } @@ -187,7 +193,10 @@ public class RestTemplateUtil { try { LOG.debug("Rest post for app:\ntoken: {},\nurl: {},\nparams: {}", token, url, params); return getResponse(restTemplate.postForEntity(url, httpEntity, String.class)); - } catch (Exception e) { + } catch (HttpClientErrorException e) { + if (e.getRawStatusCode() == HttpStatus.BAD_REQUEST.value()) { + return e.getResponseBodyAsString(); + } LOG.error(e.getMessage(), e); return null; } @@ -219,8 +228,8 @@ public class RestTemplateUtil { */ private String getResponse(ResponseEntity responseEntity) { LOG.debug(">>>> 请求结果状态: {}, ", responseEntity.getStatusCodeValue()); + String response = responseEntity.getBody(); if (HttpStatus.OK.value() == responseEntity.getStatusCodeValue()) { - String response = responseEntity.getBody(); LOG.debug(">>>> 返回结果: {}", response); return response; } else if (HttpStatus.UNAUTHORIZED.value() == responseEntity.getStatusCodeValue()) { diff --git a/cloud-common-plugin-oauth/src/main/resources/templates/user/update-password.html b/cloud-common-plugin-oauth/src/main/resources/templates/user/update-password.html new file mode 100644 index 0000000..dc55d7a --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/resources/templates/user/update-password.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + + +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/cloud-common-plugin/src/main/java/com/cm/common/aspect/ApiLogAspect.java b/cloud-common-plugin/src/main/java/com/cm/common/aspect/ApiLogAspect.java index 9016baa..b6e41ea 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/aspect/ApiLogAspect.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/aspect/ApiLogAspect.java @@ -204,7 +204,7 @@ public class ApiLogAspect { params.put("gmtCreate", currentTime); params.put("gmtModified", currentTime); params.put("creator", accessToken); - params.put("creatorName", accessToken); + params.put("creatorName", "client"); systemLoggerService.saveSystemLogger(params); return result; } diff --git a/cloud-common/src/main/java/com/cm/common/base/AbstractService.java b/cloud-common/src/main/java/com/cm/common/base/AbstractService.java index 7129d22..5ab8e72 100644 --- a/cloud-common/src/main/java/com/cm/common/base/AbstractService.java +++ b/cloud-common/src/main/java/com/cm/common/base/AbstractService.java @@ -1,7 +1,10 @@ package com.cm.common.base; +import com.alibaba.fastjson.JSONObject; import com.cm.common.component.SecurityComponent; import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.AccessTokenException; +import com.cm.common.exception.SearchException; import com.cm.common.pojo.bos.UserInfoBO; import com.cm.common.pojo.dtos.ZTreeDTO; import com.cm.common.token.app.AppTokenManager; @@ -178,4 +181,42 @@ public abstract class AbstractService { } return securityComponent.getCurrentUser().getBaseDepartmentIds(); } + + /** + * 查询资源结果 + * + * @param result 结果 + * @param errorMessage 异常提示 + * @throws AccessTokenException + * @throws SearchException + */ + protected void searchResourceResult(String result, String errorMessage) throws AccessTokenException, SearchException { + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException(errorMessage); + } + } + + /** + * 更新结果 + * + * @param result + * @param errorMessage + * @throws AccessTokenException + * @throws SearchException + */ + protected void updateResourceResult(String result, String errorMessage) throws AccessTokenException, SearchException { + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException(errorMessage); + } + JSONObject resultObj = JSONObject.parseObject(result); + if (resultObj.getString("msg") != null) { + throw new SearchException(resultObj.getString("msg")); + } + } } diff --git a/cloud-security/src/test/java/com/cm/LicenseTest.java b/cloud-security/src/test/java/com/cm/LicenseTest.java index f3447c3..af08cdc 100644 --- a/cloud-security/src/test/java/com/cm/LicenseTest.java +++ b/cloud-security/src/test/java/com/cm/LicenseTest.java @@ -22,9 +22,10 @@ public class LicenseTest { // 包头东河三务公开:‎00-16-3E-00-62-F6 // 通用 00-16-3E-00-79-58 // 乌海海勃湾区 50-AF-73-27-2E-B2 + // 东河新三务公开:00-16-3E-00-79-BC String mac = AddressUtil.getMacAddress(); System.out.println(mac); - String license = License.getLicense("2019-11-15", "60", "50-AF-73-27-2E-B2", "CMXX0471"); + String license = License.getLicense("2019-12-27", "10000", "00-16-3E-00-79-BC", "CMXX0471"); System.out.println(license); }