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