use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class FmsUserConverterTest method testUserSyncActorDetailsToFmsUserDeactivatedState.
@Test
public void testUserSyncActorDetailsToFmsUserDeactivatedState() {
String workloadUsername = "foobar";
UserManagementProto.UserSyncActorDetails actorDetails = UserManagementProto.UserSyncActorDetails.newBuilder().setWorkloadUsername(workloadUsername).setState(UserManagementProto.ActorState.Value.DEACTIVATED).build();
FmsUser fmsUser = underTest.toFmsUser(actorDetails);
assertEquals(workloadUsername, fmsUser.getName());
assertEquals(underTest.NONE_STRING, fmsUser.getFirstName());
assertEquals(underTest.NONE_STRING, fmsUser.getLastName());
assertEquals(FmsUser.State.DISABLED, fmsUser.getState());
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class FreeIpaUsersStateProviderTest method testGetUserState.
@Test
void testGetUserState() throws Exception {
List<String> user1GroupNames = List.of("group1", "group2");
List<String> user2GroupNames = List.of("group2", "group3", IPA_UNMANAGED_GROUPS.get(0));
List<String> ipaOnlyUserGroupNames = List.of("dont_include");
List<String> groupsWithoutMembers = List.of("group4");
Map<String, Pair<List<String>, Optional<UserMetadata>>> users = Map.of("user1", Pair.of(user1GroupNames, Optional.empty()), "user2", Pair.of(user2GroupNames, Optional.of(new UserMetadata("user2-crn", 1L))), IPA_PROTECTED_USERS.get(0), Pair.of(ipaOnlyUserGroupNames, Optional.empty()));
Set<com.sequenceiq.freeipa.client.model.User> usersFindAll = users.entrySet().stream().map(entry -> createIpaUser(entry.getKey(), entry.getValue().getLeft())).collect(Collectors.toSet());
Set<com.sequenceiq.freeipa.client.model.Group> groupsFindAll = Stream.of(user1GroupNames.stream(), user2GroupNames.stream(), groupsWithoutMembers.stream(), IPA_UNMANAGED_GROUPS.stream()).flatMap(groupName -> groupName).map(this::createIpaGroup).collect(Collectors.toSet());
when(freeIpaClient.userFindAll()).thenReturn(usersFindAll);
when(freeIpaClient.groupFindAll()).thenReturn(groupsFindAll);
Set<String> expectedUsers = users.keySet().stream().filter(user -> !IPA_PROTECTED_USERS.contains(user)).collect(Collectors.toSet());
Set<String> expectedGroups = groupsFindAll.stream().map(com.sequenceiq.freeipa.client.model.Group::getCn).filter(groupName -> !IPA_UNMANAGED_GROUPS.contains(groupName)).collect(Collectors.toSet());
Map<String, UserMetadata> expectedUserMetadata = Maps.newHashMap();
expectedUsers.forEach(username -> {
Optional<UserMetadata> userMetadata = users.get(username).getRight();
doReturn(userMetadata).when(userMetadataConverter).toUserMetadata(argThat(arg -> username.equals(arg.getUid())));
userMetadata.ifPresent(meta -> expectedUserMetadata.put(username, meta));
});
UsersState ipaState = underTest.getUsersState(freeIpaClient);
for (FmsUser fmsUser : ipaState.getUsers()) {
assertTrue(expectedUsers.contains(fmsUser.getName()));
expectedUsers.remove(fmsUser.getName());
}
assertTrue(expectedUsers.isEmpty());
for (FmsGroup fmsGroup : ipaState.getGroups()) {
assertTrue(expectedGroups.contains(fmsGroup.getName()));
expectedGroups.remove(fmsGroup.getName());
}
assertTrue(expectedGroups.isEmpty());
assertEquals(expectedUserMetadata, ipaState.getUserMetadataMap());
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class UserSyncOperationsTest method testAddUsersSingle.
@Test
public void testAddUsersSingle() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
FmsUser user1 = new FmsUser().withName("user1").withFirstName("User_1").withLastName("Test1").withState(FmsUser.State.ENABLED);
FmsUser user2 = new FmsUser().withName("user2").withFirstName("User_2").withLastName("Test2").withState(FmsUser.State.DISABLED);
Set<FmsUser> users = Set.of(user1, user2);
ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
RPCResponse<Object> response1 = new RPCResponse<>();
response1.setResult(new User());
RPCResponse<Object> response2 = new RPCResponse<>();
response2.setResult(new User());
when(freeIpaClient.invoke(eq("user_add"), flagsCaptor.capture(), paramsCaptor.capture(), eq(User.class))).thenReturn(response1, response2);
underTest.addUsers(false, freeIpaClient, users, warnings::put);
assertTrue(warnings.isEmpty());
verifyNoInteractions(batchPartitionSizeProperties);
verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
List<List<Object>> flagsList = flagsCaptor.getAllValues();
assertThat(flagsList, allOf(hasItem(hasItem("user1")), hasItem(hasItem("user2"))));
List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
assertThat(paramsList, everyItem(aMapWithSize(5)));
assertThat(paramsList, allOf(Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_1"), hasEntry("sn", "Test1"))), Matchers.<Map<String, Object>>hasItem(allOf(hasEntry("givenname", "User_2"), hasEntry("sn", "Test2")))));
verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class UserSyncOperations method addUsers.
public void addUsers(boolean fmsToFreeipaBatchCallEnabled, FreeIpaClient freeIpaClient, Set<FmsUser> fmsUsers, BiConsumer<String, String> warnings) throws FreeIpaClientException, TimeoutException {
List<UserAddOperation> operations = Lists.newArrayList();
for (FmsUser fmsUser : fmsUsers) {
threadInterruptChecker.throwTimeoutExIfInterrupted();
operations.add(UserAddOperation.create(fmsUser.getName(), fmsUser.getFirstName(), fmsUser.getLastName(), fmsUser.getState() == FmsUser.State.DISABLED));
}
invokeOperation(operations, fmsToFreeipaBatchCallEnabled, freeIpaClient, warnings, Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY), true);
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser in project cloudbreak by hortonworks.
the class DefaultUmsUsersStateProvider method addActorsToUmsUsersStateBuilder.
private void addActorsToUmsUsersStateBuilder(String accountId, EnvironmentAccessChecker environmentAccessChecker, List<UserManagementProto.User> users, List<UserManagementProto.MachineUser> machineUsers, ActorHandler actorHandler, Optional<String> requestIdOptional) {
Streams.concat(users.stream().map(user -> Triple.of(user.getCrn(), fmsUserConverter.toFmsUser(user), user.getCloudIdentitiesList())), machineUsers.stream().map(machineUser -> Triple.of(machineUser.getCrn(), fmsUserConverter.toFmsUser(machineUser), machineUser.getCloudIdentitiesList()))).forEach(triple -> {
String memberCrn = triple.getLeft();
FmsUser fmsUser = triple.getMiddle();
List<UserManagementProto.CloudIdentity> cloudIdentityList = triple.getRight();
Supplier<Collection<String>> groupMembershipSupplier = () -> grpcUmsClient.listGroupsForMember(accountId, memberCrn, requestIdOptional, regionAwareInternalCrnGeneratorFactory);
Supplier<Collection<String>> wagMembershipSupplier = () -> grpcUmsClient.listWorkloadAdministrationGroupsForMember(memberCrn, requestIdOptional, regionAwareInternalCrnGeneratorFactory);
Supplier<WorkloadCredential> workloadCredentialSupplier = () -> umsCredentialProvider.getCredentials(memberCrn, requestIdOptional);
try {
actorHandler.handleActor(environmentAccessChecker.hasAccess(memberCrn, requestIdOptional), fmsUser, memberCrn, groupMembershipSupplier, wagMembershipSupplier, workloadCredentialSupplier, cloudIdentityList);
} catch (StatusRuntimeException e) {
// membership.
if (e.getStatus().getCode() == Status.Code.NOT_FOUND) {
LOGGER.warn("Member CRN {} not found in UMS. Member will not be added to the UMS Users State. {}", memberCrn, e.getLocalizedMessage());
} else {
throw e;
}
}
});
}
Aggregations