예제 #1
0
  @Test
  public void count_user_twice_when_user_and_group_permission() {
    DbClient dbClient = db.getDbClient();

    UserDto user = dbClient.userDao().insert(db.getSession(), new UserDto().setActive(true));
    GroupDto group = dbClient.groupDao().insert(db.getSession(), new GroupDto());
    dbClient
        .userGroupDao()
        .insert(
            db.getSession(), new UserGroupDto().setGroupId(group.getId()).setUserId(user.getId()));
    dbClient
        .roleDao()
        .insertGroupRole(
            db.getSession(),
            new GroupRoleDto().setGroupId(group.getId()).setRole(GlobalPermissions.SYSTEM_ADMIN));
    dbClient
        .roleDao()
        .insertUserRole(
            db.getSession(),
            new UserRoleDto().setUserId(user.getId()).setRole(GlobalPermissions.SYSTEM_ADMIN));

    int result =
        underTest.countUserPermissions(db.getSession(), GlobalPermissions.SYSTEM_ADMIN, null);

    assertThat(result).isEqualTo(2);
  }
예제 #2
0
  @Test
  public void count_users_with_one_specific_permission() {
    DbClient dbClient = db.getDbClient();
    UserDto user = dbClient.userDao().insert(db.getSession(), new UserDto().setActive(true));
    dbClient
        .roleDao()
        .insertUserRole(
            db.getSession(),
            new UserRoleDto()
                .setUserId(user.getId())
                .setResourceId(123L)
                .setRole(GlobalPermissions.SYSTEM_ADMIN));
    dbClient
        .roleDao()
        .insertUserRole(
            db.getSession(),
            new UserRoleDto().setUserId(user.getId()).setRole(GlobalPermissions.SYSTEM_ADMIN));
    dbClient
        .roleDao()
        .insertUserRole(
            db.getSession(),
            new UserRoleDto().setUserId(user.getId()).setRole(GlobalPermissions.SCAN_EXECUTION));

    int result =
        underTest.countUserPermissions(db.getSession(), GlobalPermissions.SYSTEM_ADMIN, null);

    assertThat(result).isEqualTo(1);
  }
예제 #3
0
  @Test
  public void count_users_with_one_permission_when_the_last_one_is_in_a_group() {
    DbClient dbClient = db.getDbClient();

    UserDto user = dbClient.userDao().insert(db.getSession(), new UserDto().setActive(true));
    GroupDto group = dbClient.groupDao().insert(db.getSession(), new GroupDto());
    dbClient
        .userGroupDao()
        .insert(
            db.getSession(), new UserGroupDto().setGroupId(group.getId()).setUserId(user.getId()));
    dbClient
        .roleDao()
        .insertGroupRole(
            db.getSession(),
            new GroupRoleDto().setGroupId(group.getId()).setRole(GlobalPermissions.SYSTEM_ADMIN));

    int resultWithoutExcludingGroup =
        underTest.countUserPermissions(db.getSession(), GlobalPermissions.SYSTEM_ADMIN, null);
    int resultWithGroupExclusion =
        underTest.countUserPermissions(
            db.getSession(), GlobalPermissions.SYSTEM_ADMIN, group.getId());

    assertThat(resultWithoutExcludingGroup).isEqualTo(1);
    assertThat(resultWithGroupExclusion).isEqualTo(0);
  }
 private void insertUserRole(String permission, long userId, @Nullable Long resourceId) {
   dbClient
       .roleDao()
       .insertUserRole(
           dbSession,
           new UserRoleDto().setRole(permission).setUserId(userId).setResourceId(resourceId));
 }
예제 #5
0
 private void insertGroupPermission(String permission, long groupId, long componentId) {
   dbClient
       .roleDao()
       .insertGroupRole(
           dbSession,
           new GroupRoleDto().setRole(permission).setGroupId(groupId).setResourceId(componentId));
   db.commit();
 }
 private void insertGroupRole(
     String permission, @Nullable Long resourceId, @Nullable Long groupId) {
   dbClient
       .roleDao()
       .insertGroupRole(
           dbSession,
           new GroupRoleDto().setRole(permission).setResourceId(resourceId).setGroupId(groupId));
 }
예제 #7
0
 private void insertUserPermission(String permission, long userId, long componentId) {
   dbClient
       .roleDao()
       .insertUserRole(
           dbSession,
           new UserPermissionDto()
               .setPermission(permission)
               .setUserId(userId)
               .setComponentId(componentId));
   db.commit();
 }
예제 #8
0
 private void insertGroupRole(GroupRoleDto groupRole) {
   dbClient.roleDao().insertGroupRole(dbSession, groupRole);
   commit();
 }