use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class ActorHandler method handleActor.
public void handleActor(EnvironmentAccessRights environmentAccessRights, FmsUser fmsUser, String actorCrn, Supplier<Collection<String>> groupCrnMembershipSupplier, Supplier<Collection<String>> wagMembershipSupplier, Supplier<WorkloadCredential> workloadCredentialSupplier, List<UserManagementProto.CloudIdentity> cloudIdentityList) {
if (environmentAccessRights.hasEnvironmentAccessRight()) {
String workloadUsername = fmsUser.getName();
// Retrieve all information from UMS before modifying to the UmsUsersState or UsersState. This is so that
// we don't partially modify the state if the member has been deleted after we started the sync
Collection<String> groupCrnsForMember = groupCrnMembershipSupplier.get();
Collection<String> workloadAdministrationGroupsForMember = wagMembershipSupplier.get();
WorkloadCredential workloadCredential = workloadCredentialSupplier.get();
groupCrnsForMember.forEach(gcrn -> {
FmsGroup group = crnToFmsGroup.get(gcrn);
// the group and group membership will be updated on the next sync
if (group != null) {
usersStateBuilder.addMemberToGroup(group.getName(), workloadUsername);
} else {
LOGGER.warn("{} is a member of unexpected group {}. Group must have been added after UMS state calculation started", workloadUsername, gcrn);
}
});
workloadAdministrationGroupsForMember.stream().filter(wagName -> !wagNamesForOtherEnvironments.contains(wagName)).forEach(wagName -> {
usersStateBuilder.addGroup(fmsGroupConverter.nameToGroup(wagName));
usersStateBuilder.addMemberToGroup(wagName, workloadUsername);
});
addMemberToInternalTrackingGroup(usersStateBuilder, workloadUsername);
if (environmentAccessRights.hasAdminFreeIpaRight()) {
usersStateBuilder.addMemberToGroup(UserSyncConstants.ADMINS_GROUP, workloadUsername);
}
umsUsersStateBuilder.addWorkloadCredentials(workloadUsername, workloadCredential);
umsUsersStateBuilder.addUserCloudIdentities(workloadUsername, cloudIdentityList);
usersStateBuilder.addUserMetadata(workloadUsername, new UserMetadata(actorCrn, workloadCredential.getVersion()));
usersStateBuilder.addUser(fmsUser);
}
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class UserSyncServiceTest method testApplyStateDifferenceToIpa.
@Test
void testApplyStateDifferenceToIpa() throws FreeIpaClientException {
FmsGroup groupToAdd1 = new FmsGroup().withName("groupToAdd1");
FmsGroup groupToAdd2 = new FmsGroup().withName("groupToAdd2");
FmsGroup groupToRemove1 = new FmsGroup().withName("groupToRemove1");
FmsGroup groupToRemove2 = new FmsGroup().withName("groupToRemove2");
FmsUser userToAdd1 = new FmsUser().withName("userToAdd1").withFirstName("clark").withLastName("kent");
FmsUser userToAdd2 = new FmsUser().withName("userToAdd2").withFirstName("peter").withLastName("parker");
String userToRemove1 = "userToRemove1";
String userToRemove2 = "userToRemove2";
String userToDisable1 = "userToDisable1";
String userToDisable2 = "userToDisable2";
String userToEnable1 = "userToEnable1";
String userToEnable2 = "userToEnable2";
Multimap<String, String> warnings = ArrayListMultimap.create();
doNothing().when(freeIpaClient).callBatch(any(), any(), any(), any());
UsersStateDifference usersStateDifference = new UsersStateDifference(ImmutableSet.of(groupToAdd1, groupToAdd2), ImmutableSet.of(groupToRemove1, groupToRemove2), ImmutableSet.of(userToAdd1, userToAdd2), ImmutableSet.of(), ImmutableSet.of(userToRemove1, userToRemove2), ImmutableMultimap.<String, String>builder().put(groupToAdd1.getName(), userToAdd1.getName()).put(groupToAdd2.getName(), userToAdd2.getName()).build(), ImmutableMultimap.<String, String>builder().put(groupToRemove1.getName(), userToRemove1).put(groupToRemove2.getName(), userToRemove2).build(), ImmutableSet.of(userToDisable1, userToDisable2), ImmutableSet.of(userToEnable1, userToEnable2));
underTest.applyStateDifferenceToIpa(ENV_CRN, freeIpaClient, usersStateDifference, warnings::put, true);
// 9 times instead of 8 because non-posix groups are added in a separate batch
verify(freeIpaClient, times(9)).callBatch(any(), any(), any(), any());
verifyNoMoreInteractions(freeIpaClient);
}
Aggregations