Example #1
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);
  }
Example #2
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);
  }
  @Before
  public void setUp() {
    userSessionRule.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);

    DbClient dbClient = mock(DbClient.class);
    when(dbClient.openSession(false)).thenReturn(session);
    when(dbClient.permissionTemplateDao()).thenReturn(permissionTemplateDao);
    when(dbClient.userDao()).thenReturn(userDao);
    when(dbClient.groupDao()).thenReturn(groupDao);
    underTest = new PermissionTemplateService(dbClient, userSessionRule, finder);
  }
Example #4
0
 /**
  * Owners group has an hard coded name, a description based on the organization's name and has all
  * global permissions.
  */
 private GroupDto createOwnersGroup(DbSession dbSession, OrganizationDto organization) {
   GroupDto group =
       dbClient
           .groupDao()
           .insert(
               dbSession,
               new GroupDto()
                   .setOrganizationUuid(organization.getUuid())
                   .setName(OWNERS_GROUP_NAME)
                   .setDescription(
                       format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName())));
   GlobalPermissions.ALL.forEach(permission -> addPermissionToGroup(dbSession, group, permission));
   return group;
 }
  Long getGroupId() {
    if (DefaultGroups.isAnyone(updatedReference)) {
      return null;
    }

    DbSession dbSession = dbClient.openSession(false);
    try {
      GroupDto groupDto = dbClient.groupDao().selectByName(dbSession, updatedReference);
      if (groupDto == null) {
        throw new BadRequestException("Unknown group: " + updatedReference);
      }
      return groupDto.getId();
    } finally {
      dbClient.closeSession(dbSession);
    }
  }
 private GroupDto insertGroup(GroupDto groupDto) {
   return dbClient.groupDao().insert(db.getSession(), groupDto);
 }
Example #7
0
  private GroupDto insertGroup(GroupDto group) {
    GroupDto result = dbClient.groupDao().insert(dbSession, group);
    commit();

    return result;
  }
 private GroupDto insertGroup(GroupDto group) {
   return dbClient.groupDao().insert(dbSession, group);
 }