Commit ec18a68528a10cfaea3833c076b1eed85cbc1787

Authored by 云中非
2 parents b8ebdb7f 50a2df75

Merge branch 'master' into 20220919

... ... @@ -108,7 +108,7 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand
108 108 response.setContentType(MediaType.APPLICATION_JSON_VALUE);
109 109 response.setStatus(HttpStatus.FORBIDDEN.value());
110 110 mapper.writeValue(response.getWriter(),
111   - ThingsboardErrorResponse.of("You don't have permission to perform this operation!",
  111 + ThingsboardErrorResponse.of(ErrorMessage.NOT_HAVE_PERMISSION.getMessage(),
112 112 ThingsboardErrorCode.PERMISSION_DENIED, HttpStatus.FORBIDDEN));
113 113 }
114 114 }
... ... @@ -188,7 +188,7 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand
188 188 private void handleAccessDeniedException(HttpServletResponse response) throws IOException {
189 189 response.setStatus(HttpStatus.FORBIDDEN.value());
190 190 mapper.writeValue(response.getWriter(),
191   - ThingsboardErrorResponse.of("You don't have permission to perform this operation!",
  191 + ThingsboardErrorResponse.of(ErrorMessage.NOT_HAVE_PERMISSION.getMessage(),
192 192 ThingsboardErrorCode.PERMISSION_DENIED, HttpStatus.FORBIDDEN));
193 193
194 194 }
... ... @@ -196,13 +196,13 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand
196 196 private void handleAuthenticationException(AuthenticationException authenticationException, HttpServletResponse response) throws IOException {
197 197 response.setStatus(HttpStatus.UNAUTHORIZED.value());
198 198 if (authenticationException instanceof BadCredentialsException || authenticationException instanceof UsernameNotFoundException) {
199   - mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of("Invalid username or password", ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
  199 + mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(ErrorMessage.USERNAME_PASSWORD_INCORRECT.getMessage(), ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
200 200 } else if (authenticationException instanceof DisabledException) {
201   - mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of("User account is not active", ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
  201 + mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(ErrorMessage.ACCOUNT_IS_NOT_ACTIVE.getMessage(), ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
202 202 } else if (authenticationException instanceof LockedException) {
203 203 mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(ErrorMessage.ACCOUNT_LOCKED.getMessage(), ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
204 204 } else if (authenticationException instanceof JwtExpiredTokenException) {
205   - mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of("Token has expired", ThingsboardErrorCode.JWT_TOKEN_EXPIRED, HttpStatus.UNAUTHORIZED));
  205 + mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(ErrorMessage.TOKEN_EXPIRED.getMessage(), ThingsboardErrorCode.JWT_TOKEN_EXPIRED, HttpStatus.UNAUTHORIZED));
206 206 } else if (authenticationException instanceof AuthMethodNotSupportedException) {
207 207 mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(authenticationException.getMessage(), ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
208 208 } else if (authenticationException instanceof UserPasswordExpiredException) {
... ... @@ -214,7 +214,7 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand
214 214 mapper.writeValue(response.getWriter(), ThingsboardCredentialsExpiredResponse.of(expiredException.getMessage(),ThingsboardErrorCode.AUTHENTICATION, HttpStatus.FORBIDDEN));
215 215 }
216 216 else {
217   - mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of("Authentication failed", ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
  217 + mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(ErrorMessage.AUTHENTICATION_METHOD_NOT_SUPPORTED.getMessage(), ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED));
218 218 }
219 219 }
220 220
... ...
... ... @@ -10,15 +10,17 @@ public enum ErrorMessage {
10 10 NO_PERMISSION(403001, "没有操作权限"),
11 11 ACCOUNT_DISABLED(403002, "账号已禁用"),
12 12 ACCESS_DENIED(403003, "拒绝访问"),
13   - AUTHENTICATION_METHOD_NOT_SUPPORTED(403004, "authentication method not supported"),
14   - ACCOUNT_LOCKED(403002, "根据相关安全策略账号已锁定!"),
15   - USERNAME_PASSWORD_INCORRECT(401001, "incorrect username or password"),
16   - TOKEN_EXPIRED(401002, "token has expired"),
17   - NONE_TENANT_ASSET(401003, "not current tenant asset"),
18   - AUTHENTICATION_FAILED_ACCOUNT_EXPIRED(401003, "account has expired"),
19   - BAD_PARAMETER(400000, "query parameters not valid"),
20   - INVALID_PARAMETER(400001, "invalid parameters"),
21   - TOO_MANY_REQUEST(429001, "too many requests"),
  13 + AUTHENTICATION_METHOD_NOT_SUPPORTED(403004, "权限认证失败"),
  14 + ACCOUNT_LOCKED(403005, "根据相关安全策略账号已锁定!"),
  15 + NOT_HAVE_PERMISSION(403006, "您没有执行该操作的权限!"),
  16 + ACCOUNT_IS_NOT_ACTIVE(401000,"用户账号未激活或初始密码未修改"),
  17 + USERNAME_PASSWORD_INCORRECT(401001, "用户名或密码错误"),
  18 + TOKEN_EXPIRED(401002, "token已过期"),
  19 + NONE_TENANT_ASSET(401003, "非当前租户资产"),
  20 + AUTHENTICATION_FAILED_ACCOUNT_EXPIRED(401003, "账号已过期"),
  21 + BAD_PARAMETER(400000, "查询参数无效"),
  22 + INVALID_PARAMETER(400001, "无效参数"),
  23 + TOO_MANY_REQUEST(429001, "请求过多"),
22 24 EXIST_ENABLE_TEMPLATE(400002,"存在已启用相同类型及用途的模板"),
23 25 NOT_SET_PASSWORD_TEMPLATE(400003,"未设置用于密码重置的模板"),
24 26 PROVIDE_CORRECT_PHONE_NUMBER(400004,"请提供正确的电话号码"),
... ...