Search in sources :

Example 26 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class DeleteActionTest method addAdmin.

private void addAdmin(OrganizationDto org) {
    UserDto admin = db.users().insertUser();
    db.users().insertPermissionOnUser(org, admin, SYSTEM_ADMIN);
}
Also used : UserDto(org.sonar.db.user.UserDto)

Example 27 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class OrganizationDaoTest method selectByPermission_returns_organization_only_if_user_has_specific_permission_by_user_permission.

@Test
public void selectByPermission_returns_organization_only_if_user_has_specific_permission_by_user_permission() {
    OrganizationDto organization = dbTester.organizations().insert();
    OrganizationDto otherOrganization = dbTester.organizations().insert();
    UserDto user = dbTester.users().insertUser();
    dbTester.users().insertPermissionOnUser(organization, user, PERMISSION_1);
    dbTester.users().insertPermissionOnUser(otherOrganization, user, PERMISSION_2);
    UserDto otherUser = dbTester.users().insertUser();
    dbTester.users().insertPermissionOnUser(organization, otherUser, PERMISSION_2);
    dbTester.users().insertPermissionOnUser(otherOrganization, otherUser, PERMISSION_1);
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnlyOnce(organization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_2)).extracting(OrganizationDto::getUuid).containsOnlyOnce(otherOrganization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnlyOnce(otherOrganization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_2)).extracting(OrganizationDto::getUuid).containsOnlyOnce(organization.getUuid());
}
Also used : UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 28 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class OrganizationDaoTest method selectByPermission_returns_organization_only_if_user_has_specific_permission_by_group_permission.

@Test
public void selectByPermission_returns_organization_only_if_user_has_specific_permission_by_group_permission() {
    OrganizationDto organization = dbTester.organizations().insert();
    OrganizationDto otherOrganization = dbTester.organizations().insert();
    GroupDto group1 = dbTester.users().insertGroup(organization);
    GroupDto group2 = dbTester.users().insertGroup(organization);
    GroupDto otherGroup1 = dbTester.users().insertGroup(otherOrganization);
    GroupDto otherGroup2 = dbTester.users().insertGroup(otherOrganization);
    dbTester.users().insertPermissionOnGroup(group1, PERMISSION_1);
    dbTester.users().insertPermissionOnGroup(otherGroup2, PERMISSION_2);
    dbTester.users().insertPermissionOnGroup(group2, PERMISSION_2);
    dbTester.users().insertPermissionOnGroup(otherGroup1, PERMISSION_1);
    UserDto user = dbTester.users().insertUser();
    dbTester.users().insertMember(group1, user);
    dbTester.users().insertMember(otherGroup2, user);
    UserDto otherUser = dbTester.users().insertUser();
    dbTester.users().insertMember(group2, otherUser);
    dbTester.users().insertMember(otherGroup1, otherUser);
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnlyOnce(organization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_2)).extracting(OrganizationDto::getUuid).containsOnlyOnce(otherOrganization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnlyOnce(otherOrganization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_2)).extracting(OrganizationDto::getUuid).containsOnlyOnce(organization.getUuid());
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 29 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class OrganizationDaoTest method selectByPermission_returns_organization_when_user_has_ADMIN_group_permission_on_some_organization.

@Test
public void selectByPermission_returns_organization_when_user_has_ADMIN_group_permission_on_some_organization() {
    UserDto user = dbTester.users().insertUser();
    OrganizationDto organization1 = dbTester.organizations().insert();
    GroupDto defaultGroup = dbTester.users().insertGroup(organization1);
    dbTester.users().insertPermissionOnGroup(defaultGroup, PERMISSION_1);
    dbTester.users().insertMember(defaultGroup, user);
    OrganizationDto organization2 = dbTester.organizations().insert();
    GroupDto group1 = dbTester.users().insertGroup(organization2);
    dbTester.users().insertPermissionOnGroup(group1, PERMISSION_1);
    dbTester.users().insertMember(group1, user);
    UserDto otherUser = dbTester.users().insertUser();
    OrganizationDto organization3 = dbTester.organizations().insert();
    GroupDto group2 = dbTester.users().insertGroup(organization3);
    dbTester.users().insertPermissionOnGroup(group2, PERMISSION_1);
    dbTester.users().insertMember(group2, otherUser);
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnly(organization1.getUuid(), organization2.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnly(organization3.getUuid());
    assertThat(underTest.selectByPermission(dbSession, 1234, PERMISSION_1)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 30 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UserIdentityAuthenticator method registerNewUser.

private UserDto registerNewUser(DbSession dbSession, UserIdentity user, IdentityProvider provider, AuthenticationEvent.Source source) {
    if (!provider.allowsUsersToSignUp()) {
        throw AuthenticationException.newBuilder().setSource(source).setLogin(user.getLogin()).setMessage(format("User signup disabled for provider '%s'", provider.getKey())).setPublicMessage(format("'%s' users are not allowed to sign up", provider.getKey())).build();
    }
    String email = user.getEmail();
    if (email != null && dbClient.userDao().doesEmailExist(dbSession, email)) {
        throw AuthenticationException.newBuilder().setSource(source).setLogin(user.getLogin()).setMessage(format("Email '%s' is already used", email)).setPublicMessage(format("You can't sign up because email '%s' is already used by an existing user. This means that you probably already registered with another account.", email)).build();
    }
    String userLogin = user.getLogin();
    userUpdater.create(dbSession, NewUser.builder().setLogin(userLogin).setEmail(user.getEmail()).setName(user.getName()).setExternalIdentity(new ExternalIdentity(provider.getKey(), user.getProviderLogin())).build());
    UserDto newUser = dbClient.userDao().selectOrFailByLogin(dbSession, userLogin);
    syncGroups(dbSession, user, newUser);
    return newUser;
}
Also used : UserDto(org.sonar.db.user.UserDto) ExternalIdentity(org.sonar.server.user.ExternalIdentity)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41