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);
}
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());
}
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());
}
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();
}
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;
}
Aggregations