use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential in project cloudbreak by hortonworks.
the class BulkUmsUsersStateProvider method addActorsToUmsUsersStateBuilder.
private void addActorsToUmsUsersStateBuilder(int environmentIndex, UserManagementProto.GetUserSyncStateModelResponse userSyncStateModel, ActorHandler actorHandler) {
// process actors - users and machine users are combined in the actor list
userSyncStateModel.getActorList().forEach(actor -> {
UserManagementProto.RightsCheckResult rightsCheckResult = actor.getRightsCheckResult(environmentIndex);
EnvironmentAccessRights environmentAccessRights = new EnvironmentAccessRights(rightsCheckResult.getHasRight(0), rightsCheckResult.getHasRight(1));
Supplier<Collection<String>> groupMembershipSupplier = () -> actor.getGroupIndexList().stream().map(groupIndex -> userSyncStateModel.getGroupList().get(groupIndex).getCrn()).collect(Collectors.toList());
Supplier<Collection<String>> wagMembershipSupplier = () -> actor.getWorkloadAdministrationGroupIndexList().stream().map(wagIndex -> userSyncStateModel.getWorkloadAdministrationGroupList().get(wagIndex).getWorkloadAdministrationGroupName()).collect(Collectors.toList());
Supplier<WorkloadCredential> workloadCredentialSupplier = () -> workloadCredentialConverter.toWorkloadCredential(actor.getCredentials());
actorHandler.handleActor(environmentAccessRights, fmsUserConverter.toFmsUser(actor.getActorDetails()), actor.getActorDetails().getCrn(), groupMembershipSupplier, wagMembershipSupplier, workloadCredentialSupplier, actor.getActorDetails().getCloudIdentityList());
});
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential in project cloudbreak by hortonworks.
the class UserSyncService method getCredentialUpdate.
private WorkloadCredentialUpdate getCredentialUpdate(String username, UmsUsersState umsUsersState) {
UserMetadata userMetadata = requireNonNull(umsUsersState.getUsersState().getUserMetadataMap().get(username), "userMetadata must not be null");
WorkloadCredential workloadCredential = requireNonNull(umsUsersState.getUsersWorkloadCredentialMap().get(username), "workloadCredential must not be null");
return new WorkloadCredentialUpdate(username, userMetadata.getCrn(), workloadCredential);
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential in project cloudbreak by hortonworks.
the class UserSyncStateApplierTest method testApplyDifferenceWithPasswordHashSupport.
@Test
public void testApplyDifferenceWithPasswordHashSupport() throws FreeIpaClientException, TimeoutException {
UsersState usersState = UsersState.newBuilder().addUserMetadata("userToUpdate1", new UserMetadata("userToUpdate1Crn", 1L)).addUserMetadata("userToUpdate2", new UserMetadata("userToUpdate2Crn", 2L)).build();
WorkloadCredential workloadCredential1 = mock(WorkloadCredential.class);
WorkloadCredential workloadCredential2 = mock(WorkloadCredential.class);
UmsUsersState umsUsersState = UmsUsersState.newBuilder().setUsersState(usersState).addWorkloadCredentials("userToUpdate1", workloadCredential1).addWorkloadCredentials("userToUpdate2", workloadCredential2).build();
UserSyncOptions userSyncOptions = mock(UserSyncOptions.class);
UsersStateDifference usersStateDifference = createStateDiff();
Multimap<String, String> warnings = ArrayListMultimap.create();
when(userSyncOptions.isFmsToFreeIpaBatchCallEnabled()).thenReturn(Boolean.TRUE);
Config config = new Config();
config.setIpauserobjectclasses(Set.of("cdpUserAttr"));
when(freeIpaClient.getConfig()).thenReturn(config);
underTest.applyDifference(umsUsersState, ENV_CRN, warnings, usersStateDifference, userSyncOptions, freeIpaClient);
ArgumentCaptor<Set<WorkloadCredentialUpdate>> credentialUpdateCaptor = ArgumentCaptor.forClass(Set.class);
verify(workloadCredentialService).setWorkloadCredentials(eq(userSyncOptions), eq(freeIpaClient), credentialUpdateCaptor.capture(), any());
Set<WorkloadCredentialUpdate> workloadCredentialUpdates = credentialUpdateCaptor.getValue();
assertThat(workloadCredentialUpdates, allOf(hasItem(allOf(hasProperty("username", is("userToUpdate1")), hasProperty("userCrn", is("userToUpdate1Crn")), hasProperty("workloadCredential", is(workloadCredential1)))), hasItem(allOf(hasProperty("username", is("userToUpdate2")), hasProperty("userCrn", is("userToUpdate2Crn")), hasProperty("workloadCredential", is(workloadCredential2))))));
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential in project cloudbreak by hortonworks.
the class UmsCredentialProviderTest method testGetCredentialsNoExpiration.
@Test
void testGetCredentialsNoExpiration() {
GetActorWorkloadCredentialsResponse response = GetActorWorkloadCredentialsResponse.newBuilder().setPasswordHash(PASSWORD_HASH).addAllKerberosKeys(ACTOR_KERBEROS_KEY_LIST).setPasswordHashExpirationDate(0).setWorkloadCredentialsVersion(WORKLOAD_CREDENTIALS_VERSION).build();
when(grpcUmsClient.getActorWorkloadCredentials(eq("user"), any(), any())).thenReturn(response);
WorkloadCredential credential = underTest.getCredentials("user", Optional.empty());
assertEquals(credential.getExpirationDate(), Optional.empty());
assertEquals(WORKLOAD_CREDENTIALS_VERSION, credential.getVersion());
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential in project cloudbreak by hortonworks.
the class WorkloadCredentialConverterTest method testGetActorWorkloadCredentialsResponseToWorkloadCredentialNoExpiration.
@Test
public void testGetActorWorkloadCredentialsResponseToWorkloadCredentialNoExpiration() {
String passwordHash = "password-hash";
List<UserManagementProto.ActorKerberosKey> kerberosKeys = List.of(UserManagementProto.ActorKerberosKey.newBuilder().build());
long passwordExpiration = 0;
List<UserManagementProto.SshPublicKey> sshPublicKeys = List.of(UserManagementProto.SshPublicKey.newBuilder().build());
long workloadCredentialsVersion = 123L;
Optional<Instant> expectedPasswordExpiration = Optional.empty();
UserManagementProto.GetActorWorkloadCredentialsResponse actorWorkloadCredentials = UserManagementProto.GetActorWorkloadCredentialsResponse.newBuilder().setPasswordHash(passwordHash).setPasswordHashExpirationDate(passwordExpiration).addAllKerberosKeys(kerberosKeys).addAllSshPublicKey(sshPublicKeys).setWorkloadCredentialsVersion(workloadCredentialsVersion).build();
WorkloadCredential workloadCredential = underTest.toWorkloadCredential(actorWorkloadCredentials);
assertEquals(passwordHash, workloadCredential.getHashedPassword());
assertEquals(expectedPasswordExpiration, workloadCredential.getExpirationDate());
assertIterableEquals(kerberosKeys, workloadCredential.getKeys());
assertIterableEquals(sshPublicKeys, workloadCredential.getSshPublicKeys());
assertEquals(workloadCredentialsVersion, workloadCredential.getVersion());
}
Aggregations