Search in sources :

Example 1 with DefaultOrganization

use of org.sonar.server.organization.DefaultOrganization in project sonarqube by SonarSource.

the class UserIdentityAuthenticator method syncGroups.

private void syncGroups(DbSession dbSession, UserIdentity userIdentity, UserDto userDto) {
    if (userIdentity.shouldSyncGroups()) {
        String userLogin = userIdentity.getLogin();
        Set<String> userGroups = new HashSet<>(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(userLogin)).get(userLogin));
        Set<String> identityGroups = userIdentity.getGroups();
        LOGGER.debug("List of groups returned by the identity provider '{}'", identityGroups);
        Collection<String> groupsToAdd = Sets.difference(identityGroups, userGroups);
        Collection<String> groupsToRemove = Sets.difference(userGroups, identityGroups);
        Collection<String> allGroups = new ArrayList<>(groupsToAdd);
        allGroups.addAll(groupsToRemove);
        DefaultOrganization defaultOrganization = defaultOrganizationProvider.get();
        Map<String, GroupDto> groupsByName = dbClient.groupDao().selectByNames(dbSession, defaultOrganization.getUuid(), allGroups).stream().collect(uniqueIndex(GroupDto::getName));
        addGroups(dbSession, userDto, groupsToAdd, groupsByName);
        removeGroups(dbSession, userDto, groupsToRemove, groupsByName);
        dbSession.commit();
    }
}
Also used : ArrayList(java.util.ArrayList) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) HashSet(java.util.HashSet) DefaultOrganization(org.sonar.server.organization.DefaultOrganization)

Example 2 with DefaultOrganization

use of org.sonar.server.organization.DefaultOrganization in project sonarqube by SonarSource.

the class SearchActionComponentsMediumTest method setUp.

@Before
public void setUp() {
    tester.clearDbAndIndexes();
    db = tester.get(DbClient.class);
    wsTester = tester.get(WsTester.class);
    session = db.openSession(false);
    OrganizationDao organizationDao = db.organizationDao();
    DefaultOrganization defaultOrganization = tester.get(DefaultOrganizationProvider.class).get();
    this.defaultOrganization = organizationDao.selectByUuid(session, defaultOrganization.getUuid()).get();
    this.otherOrganization1 = OrganizationTesting.newOrganizationDto().setKey("my-org-1");
    this.otherOrganization2 = OrganizationTesting.newOrganizationDto().setKey("my-org-2");
    organizationDao.insert(session, this.otherOrganization1);
    organizationDao.insert(session, this.otherOrganization2);
    session.commit();
}
Also used : DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) DefaultOrganizationProvider(org.sonar.server.organization.DefaultOrganizationProvider) OrganizationDao(org.sonar.db.organization.OrganizationDao) DefaultOrganization(org.sonar.server.organization.DefaultOrganization) Before(org.junit.Before)

Example 3 with DefaultOrganization

use of org.sonar.server.organization.DefaultOrganization in project sonarqube by SonarSource.

the class SearchActionMediumTest method setUp.

@Before
public void setUp() {
    tester.clearDbAndIndexes();
    db = tester.get(DbClient.class);
    wsTester = tester.get(WsTester.class);
    session = db.openSession(false);
    OrganizationDao organizationDao = db.organizationDao();
    DefaultOrganization defaultOrganization = tester.get(DefaultOrganizationProvider.class).get();
    this.defaultOrganization = organizationDao.selectByUuid(session, defaultOrganization.getUuid()).get();
    this.otherOrganization1 = OrganizationTesting.newOrganizationDto().setKey("my-org-1");
    this.otherOrganization2 = OrganizationTesting.newOrganizationDto().setKey("my-org-2");
    organizationDao.insert(session, this.otherOrganization1);
    organizationDao.insert(session, this.otherOrganization2);
    session.commit();
}
Also used : DbClient(org.sonar.db.DbClient) WsTester(org.sonar.server.ws.WsTester) DefaultOrganizationProvider(org.sonar.server.organization.DefaultOrganizationProvider) OrganizationDao(org.sonar.db.organization.OrganizationDao) DefaultOrganization(org.sonar.server.organization.DefaultOrganization) Before(org.junit.Before)

Aggregations

DefaultOrganization (org.sonar.server.organization.DefaultOrganization)3 Before (org.junit.Before)2 DbClient (org.sonar.db.DbClient)2 OrganizationDao (org.sonar.db.organization.OrganizationDao)2 DefaultOrganizationProvider (org.sonar.server.organization.DefaultOrganizationProvider)2 WsTester (org.sonar.server.ws.WsTester)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 GroupDto (org.sonar.db.user.GroupDto)1 UserGroupDto (org.sonar.db.user.UserGroupDto)1