Search in sources :

Example 36 with UserDto

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

the class CurrentAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<UserDto> user = Optional.empty();
        Collection<String> groups = emptyList();
        if (userSession.isLoggedIn()) {
            user = selectCurrentUser(dbSession);
            groups = selectGroups(dbSession);
        }
        writeResponse(response, user, groups);
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto)

Example 37 with UserDto

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

the class UserIdentityAuthenticatorTest method authenticate_new_user_with_groups.

@Test
public void authenticate_new_user_with_groups() throws Exception {
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
    authenticate(USER_LOGIN, "group1", "group2", "group3");
    Optional<UserDto> user = db.users().selectUserByLogin(USER_LOGIN);
    assertThat(user).isPresent();
    assertThat(user.get().isRoot()).isFalse();
    assertThat(db.users().selectGroupIdsOfUser(user.get())).containsOnly(group1.getId(), group2.getId());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 38 with UserDto

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

the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_remove_groups.

@Test
public void authenticate_existing_user_and_remove_groups() throws Exception {
    UserDto user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN).setActive(true).setName("John"));
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
    db.users().insertMember(group1, user);
    db.users().insertMember(group2, user);
    authenticate(USER_LOGIN, "group1");
    assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group1.getId());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 39 with UserDto

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

the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_remove_all_groups.

@Test
public void authenticate_existing_user_and_remove_all_groups() throws Exception {
    UserDto user = db.users().insertUser();
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
    db.users().insertMember(group1, user);
    db.users().insertMember(group2, user);
    authenticate(user.getLogin());
    assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 40 with UserDto

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

the class OAuth2ContextFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    UserDto userDto = dbClient.userDao().insert(dbSession, newUserDto());
    dbSession.commit();
    when(request.getSession()).thenReturn(session);
    when(identityProvider.getKey()).thenReturn(PROVIDER_KEY);
    when(identityProvider.getName()).thenReturn(PROVIDER_NAME);
    when(userIdentityAuthenticator.authenticate(USER_IDENTITY, identityProvider, Source.oauth2(identityProvider))).thenReturn(userDto);
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Before(org.junit.Before)

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