Search in sources :

Example 1 with WorkloadCredentialUpdate

use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate 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);
}
Also used : UserMetadata(com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata) WorkloadCredentialUpdate(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate) WorkloadCredential(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential)

Example 2 with WorkloadCredentialUpdate

use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate 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))))));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Config(com.sequenceiq.freeipa.client.model.Config) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserMetadata(com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) WorkloadCredential(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) WorkloadCredentialUpdate(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate) UsersStateDifference(com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference) Test(org.junit.jupiter.api.Test)

Example 3 with WorkloadCredentialUpdate

use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.

the class SetPasswordHandler method setPasswordHash.

private void setPasswordHash(Stack stack, SetPasswordRequest request, FreeIpaClient freeIpaClient, WorkloadCredential workloadCredential) throws IOException, FreeIpaClientException {
    String accountId = Crn.fromString(stack.getEnvironmentCrn()).getAccountId();
    boolean credentialsUpdateOptimizationEnabled = entitlementService.usersyncCredentialsUpdateOptimizationEnabled(accountId);
    LOGGER.info("Credentials update optimization is{} enabled for account {}", credentialsUpdateOptimizationEnabled ? "" : " not", accountId);
    if (credentialUpdateRequired(credentialsUpdateOptimizationEnabled, request.getUsername(), freeIpaClient, workloadCredential)) {
        workloadCredentialService.setWorkloadCredential(credentialsUpdateOptimizationEnabled, freeIpaClient, new WorkloadCredentialUpdate(request.getUsername(), request.getUserCrn(), workloadCredential));
    } else {
        LOGGER.debug("Not setting workload credentials for user '{}' because credentials are already up to date", request.getUsername());
    }
}
Also used : WorkloadCredentialUpdate(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate)

Example 4 with WorkloadCredentialUpdate

use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.

the class WorkloadCredentialServiceTest method setWorkloadCredentials.

private void setWorkloadCredentials(boolean batchCallEnabled, boolean updateOptimizationEnabled, FreeIpaClient ipaClient, Map<String, WorkloadCredential> usersWorkloadCredentialMap, Set<String> usersWithCredentialsToUpdate, Map<String, String> userToCrnMap, BiConsumer<String, String> warnings) throws FreeIpaClientException, TimeoutException {
    ImmutableSet<WorkloadCredentialUpdate> credentialUpdates = usersWithCredentialsToUpdate.stream().map(username -> new WorkloadCredentialUpdate(username, userToCrnMap.get(username), usersWorkloadCredentialMap.get(username))).collect(ImmutableSet.toImmutableSet());
    WorkloadCredentialsUpdateType credentialsUpdateType = updateOptimizationEnabled ? WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED : WorkloadCredentialsUpdateType.FORCE_UPDATE;
    underTest.setWorkloadCredentials(new UserSyncOptions(false, batchCallEnabled, credentialsUpdateType), ipaClient, credentialUpdates, warnings);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) TimeoutException(java.util.concurrent.TimeoutException) Multimap(com.google.common.collect.Multimap) CrnTestUtil(com.sequenceiq.cloudbreak.auth.crn.CrnTestUtil) Function(java.util.function.Function) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentMatcher(org.mockito.ArgumentMatcher) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) WorkloadCredentialsUpdateType(com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType) BatchPartitionSizeProperties(com.sequenceiq.freeipa.configuration.BatchPartitionSizeProperties) ThreadInterruptChecker(com.sequenceiq.freeipa.util.ThreadInterruptChecker) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UserMetadataConverter(com.sequenceiq.freeipa.service.freeipa.user.conversion.UserMetadataConverter) Mockito.doReturn(org.mockito.Mockito.doReturn) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableSet(com.google.common.collect.ImmutableSet) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) WorkloadCredential(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential) Set(java.util.Set) User(com.sequenceiq.freeipa.client.model.User) Mockito.times(org.mockito.Mockito.times) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) WorkloadCredentialUpdate(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) UserSyncTestUtils(com.sequenceiq.freeipa.service.freeipa.user.UserSyncTestUtils) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Optional(java.util.Optional) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) WorkloadCredentialsUpdateType(com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType) WorkloadCredentialUpdate(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate)

Example 5 with WorkloadCredentialUpdate

use of com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate in project cloudbreak by hortonworks.

the class WorkloadCredentialServiceTest method testSetWorkloadCredentialWithUpdateOptimization.

@Test
void testSetWorkloadCredentialWithUpdateOptimization() throws Exception {
    doReturn("userMetadataJson").when(userMetadataConverter).toUserMetadataJson(USER_CRN, UMS_WORKLOAD_CREDENTIALS_VERSION);
    when(freeIpaClient.invoke(any(), any(), any(), any())).thenReturn(getRpcResponse());
    underTest.setWorkloadCredential(true, freeIpaClient, new WorkloadCredentialUpdate(USER, USER_CRN, createWorkloadCredential()));
    verify(freeIpaClient).invoke(eq("user_mod"), eq(List.of(USER)), argThat(matchesTitleAttribute("userMetadataJson")), any());
    verifyNoInteractions(interruptChecker);
}
Also used : WorkloadCredentialUpdate(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate) Test(org.junit.jupiter.api.Test)

Aggregations

WorkloadCredentialUpdate (com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredentialUpdate)8 Test (org.junit.jupiter.api.Test)5 WorkloadCredential (com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential)4 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)3 Optional (java.util.Optional)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)2 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)2 Set (java.util.Set)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Multimap (com.google.common.collect.Multimap)1 CrnTestUtil (com.sequenceiq.cloudbreak.auth.crn.CrnTestUtil)1 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)1 WorkloadCredentialsUpdateType (com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType)1 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)1 Config (com.sequenceiq.freeipa.client.model.Config)1 User (com.sequenceiq.freeipa.client.model.User)1 BatchPartitionSizeProperties (com.sequenceiq.freeipa.configuration.BatchPartitionSizeProperties)1 UserSyncTestUtils (com.sequenceiq.freeipa.service.freeipa.user.UserSyncTestUtils)1