Skip to content

Commit

Permalink
Merge branch 'main' into gvfs-fuse-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
diqiu50 authored Jan 3, 2025
2 parents 0d83d95 + 2732792 commit 63e0d7f
Show file tree
Hide file tree
Showing 20 changed files with 281 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ void testManageUsers() {
users.stream().map(User::name).collect(Collectors.toList()));
Assertions.assertEquals(Lists.newArrayList("role1"), users.get(2).roles());

// ISSUE-6061: Test listUsers with revoked users
metalake.revokeRolesFromUser(Lists.newArrayList("role1"), username);
Assertions.assertEquals(3, metalake.listUsers().length);

// Get a not-existed user
Assertions.assertThrows(NoSuchUserException.class, () -> metalake.getUser("not-existed"));

Expand Down Expand Up @@ -176,6 +180,10 @@ void testManageGroups() {
groups.stream().map(Group::name).collect(Collectors.toList()));
Assertions.assertEquals(Lists.newArrayList("role2"), groups.get(0).roles());

// ISSUE-6061: Test listGroups with revoked groups
metalake.revokeRolesFromGroup(Lists.newArrayList("role2"), groupName);
Assertions.assertEquals(2, metalake.listGroups().length);

Assertions.assertTrue(metalake.removeGroup(groupName));
Assertions.assertFalse(metalake.removeGroup(groupName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,14 @@ public void validate() throws IllegalArgumentException {
Preconditions.checkArgument(
StringUtils.isNotBlank(name), "\"name\" field is required and cannot be empty");
Preconditions.checkArgument(securableObjects != null, "\"securableObjects\" can't null ");
for (SecurableObjectDTO objectDTO : securableObjects) {
Preconditions.checkArgument(
StringUtils.isNotBlank(objectDTO.name()), "\" securable object name\" can't be blank");
Preconditions.checkArgument(
objectDTO.type() != null, "\" securable object type\" can't be null");
Preconditions.checkArgument(
objectDTO.privileges() != null && !objectDTO.privileges().isEmpty(),
"\"securable object privileges\" can't be null or empty");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ public String listExtendedGroupPOsByMetalakeId(Long metalakeId) {
+ " JSON_ARRAYAGG(rot.role_id) as roleIds"
+ " FROM "
+ GROUP_TABLE_NAME
+ " gt LEFT OUTER JOIN "
+ " gt LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ GROUP_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.group_id = gt.group_id"
+ " LEFT OUTER JOIN "
+ " WHERE deleted_at = 0)"
+ " AS rt ON rt.group_id = gt.group_id"
+ " LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE deleted_at = 0)"
+ " AS rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " gt.deleted_at = 0 AND"
+ " (rot.deleted_at = 0 OR rot.deleted_at is NULL) AND"
+ " (rt.deleted_at = 0 OR rt.deleted_at is NULL) AND gt.metalake_id = #{metalakeId}"
+ " gt.metalake_id = #{metalakeId}"
+ " GROUP BY gt.group_id";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,19 @@ public String listExtendedUserPOsByMetalakeId(@Param("metalakeId") Long metalake
+ " JSON_ARRAYAGG(rot.role_id) as roleIds"
+ " FROM "
+ USER_TABLE_NAME
+ " ut LEFT OUTER JOIN "
+ " ut LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ USER_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.user_id = ut.user_id"
+ " LEFT OUTER JOIN "
+ " WHERE deleted_at = 0)"
+ " AS rt ON rt.user_id = ut.user_id"
+ " LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE deleted_at = 0)"
+ " AS rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " ut.deleted_at = 0 AND"
+ " (rot.deleted_at = 0 OR rot.deleted_at is NULL) AND"
+ " (rt.deleted_at = 0 OR rt.deleted_at is NULL) AND ut.metalake_id = #{metalakeId}"
+ " ut.metalake_id = #{metalakeId}"
+ " GROUP BY ut.user_id";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ public String listExtendedGroupPOsByMetalakeId(@Param("metalakeId") Long metalak
+ " '[' || GROUP_CONCAT('\"' || rot.role_id || '\"') || ']' as roleIds"
+ " FROM "
+ GROUP_TABLE_NAME
+ " gt LEFT OUTER JOIN "
+ " gt LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ GROUP_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.group_id = gt.group_id"
+ " LEFT OUTER JOIN "
+ " WHERE deleted_at = 0)"
+ " AS rt ON rt.group_id = gt.group_id"
+ " LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE deleted_at = 0)"
+ " AS rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " gt.deleted_at = 0 AND"
+ " (rot.deleted_at = 0 OR rot.deleted_at is NULL) AND"
+ " (rt.deleted_at = 0 OR rt.deleted_at is NULL) AND gt.metalake_id = #{metalakeId}"
+ " gt.metalake_id = #{metalakeId}"
+ " GROUP BY gt.group_id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ public String listExtendedUserPOsByMetalakeId(@Param("metalakeId") Long metalake
+ " '[' || GROUP_CONCAT('\"' || rot.role_id || '\"') || ']' as roleIds"
+ " FROM "
+ USER_TABLE_NAME
+ " ut LEFT OUTER JOIN "
+ " ut LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ USER_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.user_id = ut.user_id"
+ " LEFT OUTER JOIN "
+ " WHERE deleted_at = 0)"
+ " AS rt ON rt.user_id = ut.user_id"
+ " LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE deleted_at = 0)"
+ " AS rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " ut.deleted_at = 0 AND "
+ "(rot.deleted_at = 0 OR rot.deleted_at is NULL) AND "
+ "(rt.deleted_at = 0 OR rt.deleted_at is NULL) AND ut.metalake_id = #{metalakeId}"
+ " ut.metalake_id = #{metalakeId}"
+ " GROUP BY ut.user_id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,19 @@ public String listExtendedGroupPOsByMetalakeId(Long metalakeId) {
+ " JSON_AGG(rot.role_id) as roleIds"
+ " FROM "
+ GROUP_TABLE_NAME
+ " gt LEFT OUTER JOIN "
+ " gt LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ GROUP_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.group_id = gt.group_id"
+ " LEFT OUTER JOIN "
+ " WHERE deleted_at = 0)"
+ " AS rt ON rt.group_id = gt.group_id"
+ " LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE deleted_at = 0)"
+ " AS rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " gt.deleted_at = 0 AND"
+ " (rot.deleted_at = 0 OR rot.deleted_at is NULL) AND"
+ " (rt.deleted_at = 0 OR rt.deleted_at is NULL) AND gt.metalake_id = #{metalakeId}"
+ " gt.metalake_id = #{metalakeId}"
+ " GROUP BY gt.group_id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,19 @@ public String listExtendedUserPOsByMetalakeId(Long metalakeId) {
+ " JSON_AGG(rot.role_id) as roleIds"
+ " FROM "
+ USER_TABLE_NAME
+ " ut LEFT OUTER JOIN "
+ " ut LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ USER_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.user_id = ut.user_id"
+ " LEFT OUTER JOIN "
+ " WHERE deleted_at = 0)"
+ " AS rt ON rt.user_id = ut.user_id"
+ " LEFT OUTER JOIN ("
+ " SELECT * FROM "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE deleted_at = 0)"
+ " AS rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " ut.deleted_at = 0 AND"
+ " (rot.deleted_at = 0 OR rot.deleted_at is NULL) AND"
+ " (rt.deleted_at = 0 OR rt.deleted_at is NULL) AND ut.metalake_id = #{metalakeId}"
+ " ut.metalake_id = #{metalakeId}"
+ " GROUP BY ut.user_id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Instant;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -189,6 +190,33 @@ void testListGroups() throws IOException {
}
}
}

// ISSUE-6061: Test listGroupsByNamespace with revoked users
Function<GroupEntity, GroupEntity> revokeUpdater =
group -> {
AuditInfo updateAuditInfo =
AuditInfo.builder()
.withCreator(group.auditInfo().creator())
.withCreateTime(group.auditInfo().createTime())
.withLastModifier("revokeGroup")
.withLastModifiedTime(Instant.now())
.build();

return GroupEntity.builder()
.withNamespace(group.namespace())
.withId(group.id())
.withName(group.name())
.withRoleNames(Collections.emptyList())
.withRoleIds(Collections.emptyList())
.withAuditInfo(updateAuditInfo)
.build();
};

Assertions.assertNotNull(groupMetaService.updateGroup(group2.nameIdentifier(), revokeUpdater));
actualGroups =
groupMetaService.listGroupsByNamespace(
AuthorizationUtils.ofGroupNamespace(metalakeName), true);
Assertions.assertEquals(expectGroups.size(), actualGroups.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Instant;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -188,6 +189,33 @@ void testListUsers() throws IOException {
}
}
}

// ISSUE-6061: Test listUsersByNamespace with revoked users
Function<UserEntity, UserEntity> revokeUpdater =
user -> {
AuditInfo updateAuditInfo =
AuditInfo.builder()
.withCreator(user.auditInfo().creator())
.withCreateTime(user.auditInfo().createTime())
.withLastModifier("revokeUser")
.withLastModifiedTime(Instant.now())
.build();

return UserEntity.builder()
.withNamespace(user.namespace())
.withId(user.id())
.withName(user.name())
.withRoleNames(Collections.emptyList())
.withRoleIds(Collections.emptyList())
.withAuditInfo(updateAuditInfo)
.build();
};

Assertions.assertNotNull(userMetaService.updateUser(user1.nameIdentifier(), revokeUpdater));
actualUsers =
userMetaService.listUsersByNamespace(
AuthorizationUtils.ofUserNamespace(metalakeName), true);
Assertions.assertEquals(expectUsers.size(), actualUsers.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ public Response addGroup(@PathParam("metalake") String metalake, GroupAddRequest
TreeLockUtils.doWithTreeLock(
NameIdentifier.of(AuthorizationUtils.ofGroupNamespace(metalake).levels()),
LockType.WRITE,
() ->
Utils.ok(
new GroupResponse(
DTOConverters.toDTO(
accessControlManager.addGroup(metalake, request.getName()))))));
() -> {
request.validate();
return Utils.ok(
new GroupResponse(
DTOConverters.toDTO(
accessControlManager.addGroup(metalake, request.getName()))));
}));
} catch (Exception e) {
return ExceptionHandlers.handleGroupException(
OperationType.ADD, request.getName(), metalake, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public Response setOwnerForObject(
return Utils.doAs(
httpRequest,
() -> {
request.validate();
MetadataObjectUtil.checkMetadataObject(metalake, object);
NameIdentifier objectIdent = MetadataObjectUtil.toEntityIdent(metalake, object);
TreeLockUtils.doWithTreeLock(
Expand Down
Loading

0 comments on commit 63e0d7f

Please sign in to comment.