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