You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/10/01 03:51:42 UTC

[GitHub] [dolphinscheduler] github-code-scanning[bot] commented on a diff in pull request #12241: [Feature-12086][API][UI] Support to grant permissions of the tenant to a user.

github-code-scanning[bot] commented on code in PR #12241:
URL: https://github.com/apache/dolphinscheduler/pull/12241#discussion_r985037937


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dms/src/main/java/org/apache/dolphinscheduler/plugin/task/dms/DmsTask.java:
##########
@@ -44,11 +44,11 @@
 public class DmsTask extends AbstractRemoteTask {
 
     private static final ObjectMapper objectMapper =
-        new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
-            .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
-            .configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
-            .configure(REQUIRE_SETTERS_FOR_GETTERS, true)
-            .setPropertyNamingStrategy(new PropertyNamingStrategy.UpperCamelCaseStrategy());
+            new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
+                    .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
+                    .configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
+                    .configure(REQUIRE_SETTERS_FOR_GETTERS, true)

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ObjectMapper.configure](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/1586)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java:
##########
@@ -114,4 +120,24 @@
      * @return Tenant object
      */
     Tenant createTenantIfNotExists(String tenantCode, String desc, String queue, String queueName);
+
+
+    /**
+     * query authorized tenant
+     *
+     * @param loginUser login user
+     * @param userId user id
+     * @return tenants that the user have permission to see, Except for items created by this user
+     */
+    public Result queryAuthorizedTenant(User loginUser, Integer userId);

Review Comment:
   ## Useless parameter
   
   The parameter loginUser is unused.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/1589)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java:
##########
@@ -114,4 +120,24 @@
      * @return Tenant object
      */
     Tenant createTenantIfNotExists(String tenantCode, String desc, String queue, String queueName);
+
+
+    /**
+     * query authorized tenant
+     *
+     * @param loginUser login user
+     * @param userId user id
+     * @return tenants that the user have permission to see, Except for items created by this user
+     */
+    public Result queryAuthorizedTenant(User loginUser, Integer userId);
+
+    /**
+     * query unauthorized tenant
+     *
+     * @param loginUser login user
+     * @param userId user id
+     * @return the tenants that the user hasn't permission to see
+     */
+    Result queryUnauthorizedTenant(User loginUser, Integer userId);

Review Comment:
   ## Useless parameter
   
   The parameter loginUser is unused.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/1588)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java:
##########
@@ -1344,26 +1338,93 @@
      * @param userPassword user password
      * @param email        user email
      * @param phone        user phone
-     * @param tenantCode   tenant code
      * @param queue        queue
      * @param state        state
      * @return create result code
      */
     @Override
     @Transactional
     public User createUserIfNotExists(String userName, String userPassword, String email, String phone,
-                                      String tenantCode,
                                       String queue,
                                       int state) throws IOException {
+
         User user = userMapper.queryByUserNameAccurately(userName);
         if (Objects.isNull(user)) {
-            Tenant tenant = tenantMapper.queryByTenantCode(tenantCode);
-            user = createUser(userName, userPassword, email, tenant.getId(), phone, queue, state);
+            user = createUser(userName, userPassword, email, phone, queue, state);
             return user;
         }
 
-        updateUser(user, user.getId(), userName, userPassword, email, user.getTenantId(), phone, queue, state, null);
-        user = userMapper.queryDetailsById(user.getId());
+        updateUser(user, user.getId(), userName, userPassword, email, phone, queue, state, null);
         return user;
     }
+
+    @Override
+    public Map<String, Object> grantTenant(User loginUser, Integer userId, String tenantIds) {
+        Map<String, Object> result = new HashMap<>();
+        if (!isAdmin((loginUser))) {
+            putMsg(result, Status.USER_NO_OPERATION_PERM);
+            return result;
+        }
+
+        if (Objects.isNull(userId)) {
+            putMsg(result, Status.GRANT_TENANT_NOT_FOUND_USER_ERROR);
+            return result;
+        }
+
+        User user = userMapper.selectById(userId);
+        if (Objects.isNull(user)) {
+            putMsg(result, Status.GRANT_TENANT_NOT_FOUND_USER_ERROR);
+            return result;
+        }
+
+        if (isAdmin(user)) {
+            putMsg(result, Status.GRANT_TENANT_FOR_ADMIN_USER_ERROR);
+            return result;
+        }
+
+        try {
+            if (!StringUtils.isNotBlank(tenantIds)) {
+                tenantUserMapper
+                        .delete(new QueryWrapper<TenantUser>().lambda().eq(TenantUser::getUserId, user.getId()));
+            } else {
+                Set<Integer> tenantIdList = Splitter.on(",")
+                        .omitEmptyStrings()
+                        .splitToStream(tenantIds)
+                        .map(Integer::parseInt)

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/1594)



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/main/java/org/apache/dolphinscheduler/plugin/task/emr/AbstractEmrTask.java:
##########
@@ -52,20 +51,19 @@
     AmazonElasticMapReduce emrClient;
     String clusterId;
 
-
     /**
      * config ObjectMapper features and propertyNamingStrategy
      * use UpperCamelCaseStrategy support capital letters parse
      *
      * @see PropertyNamingStrategy.UpperCamelCaseStrategy
      */
     static final ObjectMapper objectMapper = new ObjectMapper()
-        .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
-        .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
-        .configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
-        .configure(REQUIRE_SETTERS_FOR_GETTERS, true)
-        .setTimeZone(TimeZone.getDefault())
-        .setPropertyNamingStrategy(new PropertyNamingStrategy.UpperCamelCaseStrategy());
+            .configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
+            .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
+            .configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
+            .configure(REQUIRE_SETTERS_FOR_GETTERS, true)

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [ObjectMapper.configure](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/1587)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org