Commit 36e53d4c3f76ce865e8d8e25bb823d30b0bc5b8b
Merge branch '20220919' into 'master'
20220919 See merge request huang/thingsboard3.3.2!132
Showing
11 changed files
with
22 additions
and
19 deletions
... | ... | @@ -74,7 +74,7 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt |
74 | 74 | |
75 | 75 | //Thingskit function |
76 | 76 | public static final String CODE_BASED_LOGIN_ENTRY_POINT = "/api/yt/auth/code/login"; |
77 | - public static final String[] YT_NOT_AUTH_API = new String[]{"/api/yt/auth/code/login","/api/yt/third/bind","/api/yt/third/login/*","/api/yt/third/login/id/*", "/api/yt/third/authorize","/api/yt/platform/get","/api/yt/platform/app", "/api/yt/noauth/**"}; | |
77 | + public static final String[] YT_NOT_AUTH_API = new String[]{"/api/yt/auth/code/login","/api/yt/third/bind","/api/yt/third/login/*","/api/yt/third/login/id/*", "/api/yt/third/authorize","/api/yt/platform/get","/api/yt/app_design/get", "/api/yt/noauth/**"}; | |
78 | 78 | |
79 | 79 | public static final String PUBLIC_LOGIN_ENTRY_POINT = "/api/auth/login/public"; |
80 | 80 | public static final String TOKEN_REFRESH_ENTRY_POINT = "/api/auth/token"; | ... | ... |
... | ... | @@ -90,7 +90,7 @@ import static org.thingsboard.server.controller.ControllerConstants.UUID_WIKI_LI |
90 | 90 | public class UserController extends BaseController { |
91 | 91 | |
92 | 92 | public static final String USER_ID = "userId"; |
93 | - public static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "You don't have permission to perform this operation!"; | |
93 | + public static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "您没有执行该操作的权限!"; | |
94 | 94 | public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s"; |
95 | 95 | |
96 | 96 | @Value("${security.user_token_access_enabled}") | ... | ... |
... | ... | @@ -7,6 +7,7 @@ import org.springframework.http.ResponseEntity; |
7 | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
8 | 8 | import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
10 | +import org.thingsboard.server.common.data.id.EntityId; | |
10 | 11 | import org.thingsboard.server.common.data.yunteng.dto.SysAppDesignDTO; |
11 | 12 | import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; |
12 | 13 | import org.thingsboard.server.controller.BaseController; |
... | ... | @@ -28,7 +29,12 @@ public class YtAppDesignController extends BaseController { |
28 | 29 | @GetMapping("get") |
29 | 30 | @ApiOperation("查询详情") |
30 | 31 | public ResponseEntity<SysAppDesignDTO> get() throws ThingsboardException { |
31 | - return ResponseEntity.ok(sysAppDesignService.get(getCurrentUser().getCurrentTenantId())); | |
32 | + String tenantId = EntityId.NULL_UUID.toString(); | |
33 | + try { | |
34 | + tenantId = getCurrentUser().getCurrentTenantId(); | |
35 | + } catch (ThingsboardException e) { | |
36 | + } | |
37 | + return ResponseEntity.ok(sysAppDesignService.get(tenantId)); | |
32 | 38 | } |
33 | 39 | |
34 | 40 | @PutMapping("update") | ... | ... |
... | ... | @@ -99,6 +99,7 @@ public class YtConfigurationCenterController extends BaseController { |
99 | 99 | |
100 | 100 | @GetMapping("/get_configuration_info/{id}") |
101 | 101 | @ApiOperation("获取组态信息") |
102 | + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:configuration:center:get_configuration_info:get'})") | |
102 | 103 | public ResponseEntity<ConfigurationContentInfoDTO> getConfigurationInfos( |
103 | 104 | @PathVariable("id") String id) throws ThingsboardException { |
104 | 105 | return ResponseEntity.ok( | ... | ... |
... | ... | @@ -27,7 +27,6 @@ public class YtConfigurationContentController extends BaseController { |
27 | 27 | |
28 | 28 | @PostMapping |
29 | 29 | @ApiOperation("新增") |
30 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:content:post'})") | |
31 | 30 | public ResponseEntity<ConfigurationContentDTO> save( |
32 | 31 | @Validated({AddGroup.class}) @RequestBody ConfigurationContentDTO configurationContentDTO) |
33 | 32 | throws ThingsboardException { |
... | ... | @@ -38,7 +37,6 @@ public class YtConfigurationContentController extends BaseController { |
38 | 37 | |
39 | 38 | @PutMapping |
40 | 39 | @ApiOperation("修改") |
41 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:content:update'})") | |
42 | 40 | public ResponseEntity<ConfigurationContentInfoDTO> update( |
43 | 41 | @Validated({UpdateGroup.class}) @RequestBody ConfigurationContentInfoDTO contentReqDTO) |
44 | 42 | throws ThingsboardException { |
... | ... | @@ -53,7 +51,6 @@ public class YtConfigurationContentController extends BaseController { |
53 | 51 | |
54 | 52 | @DeleteMapping |
55 | 53 | @ApiOperation("删除") |
56 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:content:delete'})") | |
57 | 54 | public ResponseEntity<Boolean> delete( |
58 | 55 | @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) |
59 | 56 | throws ThingsboardException { | ... | ... |
... | ... | @@ -35,7 +35,6 @@ public class YtConfigurationNodeController extends BaseController { |
35 | 35 | |
36 | 36 | @PostMapping |
37 | 37 | @ApiOperation("保存节点数据源并刷新节点的交互和动效信息") |
38 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:node:post'})") | |
39 | 38 | public ResponseEntity<ConfigurationNodeStateDTO> saveNode( |
40 | 39 | @Validated({AddGroup.class}) @RequestBody ConfigurationNodeStateDTO nodeDTO) |
41 | 40 | throws ThingsboardException { |
... | ... | @@ -74,7 +73,6 @@ public class YtConfigurationNodeController extends BaseController { |
74 | 73 | |
75 | 74 | @PostMapping("datasource") |
76 | 75 | @ApiOperation("编辑数据源") |
77 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:node:datasource:post'})") | |
78 | 76 | public ResponseEntity<ConfigurationDatasourceDTO> saveDatasource( |
79 | 77 | @Validated({AddGroup.class}) @RequestBody ConfigurationDatasourceDTO datasourceDTO) |
80 | 78 | throws ThingsboardException { |
... | ... | @@ -85,7 +83,6 @@ public class YtConfigurationNodeController extends BaseController { |
85 | 83 | |
86 | 84 | @PostMapping("event") |
87 | 85 | @ApiOperation("编辑数据交互") |
88 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:node:event:post'})") | |
89 | 86 | public ResponseEntity<ConfigurationEventDTO> saveEvent( |
90 | 87 | @Validated({AddGroup.class}) @RequestBody ConfigurationEventDTO eventDTO) |
91 | 88 | throws ThingsboardException { |
... | ... | @@ -96,7 +93,6 @@ public class YtConfigurationNodeController extends BaseController { |
96 | 93 | |
97 | 94 | @PostMapping("act") |
98 | 95 | @ApiOperation("编辑动画效果") |
99 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:node:act:post'})") | |
100 | 96 | public ResponseEntity<ConfigurationActDTO> saveAct( |
101 | 97 | @Validated({AddGroup.class}) @RequestBody ConfigurationActDTO actDTO) |
102 | 98 | throws ThingsboardException { |
... | ... | @@ -108,7 +104,6 @@ public class YtConfigurationNodeController extends BaseController { |
108 | 104 | |
109 | 105 | @DeleteMapping("datasource") |
110 | 106 | @ApiOperation("删除数据源") |
111 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:node:datasource:delete'})") | |
112 | 107 | public ResponseEntity<Boolean> deleteDatasource(@RequestBody ConfigurationDatasourceDTO deleteDTO) |
113 | 108 | throws ThingsboardException { |
114 | 109 | deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); |
... | ... | @@ -117,7 +112,6 @@ public class YtConfigurationNodeController extends BaseController { |
117 | 112 | |
118 | 113 | @DeleteMapping("event") |
119 | 114 | @ApiOperation("删除数据交互") |
120 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:node:event:delete'})") | |
121 | 115 | public ResponseEntity<Boolean> deleteEvent( @RequestBody ConfigurationEventDTO deleteDTO) |
122 | 116 | throws ThingsboardException { |
123 | 117 | deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); |
... | ... | @@ -125,7 +119,6 @@ public class YtConfigurationNodeController extends BaseController { |
125 | 119 | } |
126 | 120 | @DeleteMapping("act") |
127 | 121 | @ApiOperation("删除动画效果") |
128 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:configuration:node:act:delete'})") | |
129 | 122 | public ResponseEntity<Boolean> deleteAct( @RequestBody ConfigurationActDTO deleteDTO) |
130 | 123 | throws ThingsboardException { |
131 | 124 | deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ... | ... |
... | ... | @@ -73,14 +73,14 @@ public class YtNoticeController extends BaseController { |
73 | 73 | } |
74 | 74 | |
75 | 75 | @DeleteMapping("delete") |
76 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:notice:delete:delete'})") | |
76 | + @PreAuthorize("@check.checkPermissions({},{'api:yt:notice:delete'})") | |
77 | 77 | @ApiOperation("批量删除") |
78 | 78 | public void delete(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { |
79 | 79 | sysNoticeService.delete(deleteDTO.getIds(), getCurrentUser().getCurrentTenantId()); |
80 | 80 | } |
81 | 81 | |
82 | 82 | @PostMapping("save") |
83 | - @PreAuthorize("@check.checkPermissions({},{'api:yt:notice:post'})") | |
83 | + @PreAuthorize("@check.checkPermissions({},{'api:yt:notice:save:post'})") | |
84 | 84 | @ApiOperation("保存草稿") |
85 | 85 | public ResponseEntity<SysNoticeDTO> save(@Validated(AddGroup.class) @RequestBody SysNoticeDTO sysNoticeDTO) throws ThingsboardException { |
86 | 86 | sysNoticeDTO.setStatus(FastIotConstants.DraftStatus.DRAFT); | ... | ... |
... | ... | @@ -104,6 +104,7 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand |
104 | 104 | public void handle(HttpServletRequest request, HttpServletResponse response, |
105 | 105 | AccessDeniedException accessDeniedException) throws IOException, |
106 | 106 | ServletException { |
107 | + response.setCharacterEncoding("utf-8"); | |
107 | 108 | if (!response.isCommitted()) { |
108 | 109 | response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
109 | 110 | response.setStatus(HttpStatus.FORBIDDEN.value()); |
... | ... | @@ -168,11 +169,13 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand |
168 | 169 | ThingsboardErrorCode errorCode = thingsboardException.getErrorCode(); |
169 | 170 | HttpStatus status = errorCodeToStatus(errorCode); |
170 | 171 | response.setStatus(status.value()); |
172 | + response.setCharacterEncoding("utf-8"); | |
171 | 173 | mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(thingsboardException.getMessage(), errorCode, status)); |
172 | 174 | } |
173 | 175 | |
174 | 176 | private void handleRateLimitException(HttpServletResponse response, TbRateLimitsException exception) throws IOException { |
175 | 177 | response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value()); |
178 | + response.setCharacterEncoding("utf-8"); | |
176 | 179 | String message = "Too many requests for current " + exception.getEntityType().name().toLowerCase() + "!"; |
177 | 180 | mapper.writeValue(response.getWriter(), |
178 | 181 | ThingsboardErrorResponse.of(message, |
... | ... | @@ -181,11 +184,13 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand |
181 | 184 | |
182 | 185 | private void handleSubscriptionException(ThingsboardException subscriptionException, HttpServletResponse response) throws IOException { |
183 | 186 | response.setStatus(HttpStatus.FORBIDDEN.value()); |
187 | + response.setCharacterEncoding("utf-8"); | |
184 | 188 | mapper.writeValue(response.getWriter(), |
185 | 189 | (new ObjectMapper()).readValue(((HttpClientErrorException) subscriptionException.getCause()).getResponseBodyAsByteArray(), Object.class)); |
186 | 190 | } |
187 | 191 | |
188 | 192 | private void handleAccessDeniedException(HttpServletResponse response) throws IOException { |
193 | + response.setCharacterEncoding("utf-8"); | |
189 | 194 | response.setStatus(HttpStatus.FORBIDDEN.value()); |
190 | 195 | mapper.writeValue(response.getWriter(), |
191 | 196 | ThingsboardErrorResponse.of(ErrorMessage.NOT_HAVE_PERMISSION.getMessage(), |
... | ... | @@ -195,6 +200,7 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand |
195 | 200 | |
196 | 201 | private void handleAuthenticationException(AuthenticationException authenticationException, HttpServletResponse response) throws IOException { |
197 | 202 | response.setStatus(HttpStatus.UNAUTHORIZED.value()); |
203 | + response.setCharacterEncoding("utf-8"); | |
198 | 204 | if (authenticationException instanceof BadCredentialsException || authenticationException instanceof UsernameNotFoundException) { |
199 | 205 | mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(ErrorMessage.USERNAME_PASSWORD_INCORRECT.getMessage(), ThingsboardErrorCode.AUTHENTICATION, HttpStatus.UNAUTHORIZED)); |
200 | 206 | } else if (authenticationException instanceof DisabledException) { | ... | ... |
... | ... | @@ -34,7 +34,7 @@ import static org.thingsboard.server.dao.service.Validator.validateId; |
34 | 34 | public class DefaultAccessControlService implements AccessControlService { |
35 | 35 | |
36 | 36 | private static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; |
37 | - private static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "You don't have permission to perform this operation!"; | |
37 | + private static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "您没有执行该操作的权限!!"; | |
38 | 38 | |
39 | 39 | private final Map<Authority, Permissions> authorityPermissions = new HashMap<>(); |
40 | 40 | ... | ... |
... | ... | @@ -15,9 +15,9 @@ public enum ErrorMessage { |
15 | 15 | NOT_HAVE_PERMISSION(403006, "您没有执行该操作的权限!"), |
16 | 16 | ACCOUNT_IS_NOT_ACTIVE(401000,"用户账号未激活或初始密码未修改"), |
17 | 17 | USERNAME_PASSWORD_INCORRECT(401001, "用户名或密码错误"), |
18 | - TOKEN_EXPIRED(401002, "token已过期"), | |
18 | + TOKEN_EXPIRED(401002, "token已过期,请重新登录"), | |
19 | 19 | NONE_TENANT_ASSET(401003, "非当前租户资产"), |
20 | - AUTHENTICATION_FAILED_ACCOUNT_EXPIRED(401003, "账号已过期"), | |
20 | + AUTHENTICATION_FAILED_ACCOUNT_EXPIRED(401003, "账号已过期,请联系你的管理员"), | |
21 | 21 | BAD_PARAMETER(400000, "查询参数无效"), |
22 | 22 | INVALID_PARAMETER(400001, "无效参数"), |
23 | 23 | TOO_MANY_REQUEST(429001, "请求过多"), | ... | ... |
... | ... | @@ -64,7 +64,7 @@ public class YtNoticeServiceImpl implements YtNoticeService { |
64 | 64 | |
65 | 65 | QueryWrapper<AlarmProfile> profileQueryWrapper = new QueryWrapper<AlarmProfile>(); |
66 | 66 | profileQueryWrapper.lambda() |
67 | - .eq(AlarmProfile::getId, profileId).eq(AlarmProfile::getStatus, StatusEnum.ENABLE.ordinal()); | |
67 | + .eq(AlarmProfile::getId, profileId).eq(AlarmProfile::getStatus, StatusEnum.ENABLE.getIndex()); | |
68 | 68 | AlarmProfile alarmProfile = alarmProfileMapper.selectOne(profileQueryWrapper); |
69 | 69 | |
70 | 70 | ... | ... |