Search in sources :

Example 31 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class FreeIpaUsersStateProvider method getFilteredFreeIpaState.

public UsersState getFilteredFreeIpaState(FreeIpaClient freeIpaClient, Set<String> userNames) throws FreeIpaClientException {
    LOGGER.debug("Retrieving users with user names [{}] from FreeIPA", userNames);
    UsersState.Builder builder = new UsersState.Builder();
    freeIpaClient.groupFindAll().stream().filter(group -> !IPA_UNMANAGED_GROUPS.contains(group.getCn())).forEach(group -> builder.addGroup(fromIpaGroup(group)));
    for (String userName : userNames) {
        if (IPA_PROTECTED_USERS.contains(userName)) {
            continue;
        }
        Optional<User> userOptional = FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue(() -> freeIpaClient.userShow(userName), null);
        if (userOptional.isPresent()) {
            User ipaUser = userOptional.get();
            builder.addUser(fromIpaUser(ipaUser));
            userMetadataConverter.toUserMetadata(ipaUser).ifPresent(meta -> builder.addUserMetadata(ipaUser.getUid(), meta));
            if (ipaUser.getMemberOfGroup() != null) {
                ipaUser.getMemberOfGroup().stream().filter(group -> !IPA_UNMANAGED_GROUPS.contains(group)).forEach(groupname -> {
                    builder.addMemberToGroup(groupname, userName);
                });
            }
        }
    }
    return builder.build();
}
Also used : FmsGroup(com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup) Logger(org.slf4j.Logger) IPA_UNMANAGED_GROUPS(com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_UNMANAGED_GROUPS) FreeIpaClientExceptionUtil(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil) LoggerFactory(org.slf4j.LoggerFactory) IPA_PROTECTED_USERS(com.sequenceiq.freeipa.client.FreeIpaChecks.IPA_PROTECTED_USERS) Set(java.util.Set) User(com.sequenceiq.freeipa.client.model.User) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) UserMetadataConverter(com.sequenceiq.freeipa.service.freeipa.user.conversion.UserMetadataConverter) User(com.sequenceiq.freeipa.client.model.User) FmsUser(com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser) UsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UsersState)

Example 32 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class KerberosConfigV1Service method createNewKerberosConfig.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public KerberosConfig createNewKerberosConfig(String environmentCrn, String clusterName, Stack existingStack, boolean ignoreExistingUser) throws FreeIpaClientException {
    LOGGER.debug("Kerberos config doesn't exists for cluster [{}] in env [{}]. Creating new in FreeIPA", clusterName, environmentCrn);
    FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStack(existingStack);
    User user = ignoreExistingUser ? createBindUserIgnoreExisting(freeIpaClient, clusterName) : createBindUser(freeIpaClient, clusterName);
    String password = setPasswordForBindUser(freeIpaClient, user);
    addEnrollmentAdminRole(freeIpaClient, user);
    return kerberosConfigRegisterService.createKerberosConfig(existingStack.getId(), user.getUid(), password, clusterName, environmentCrn);
}
Also used : User(com.sequenceiq.freeipa.client.model.User) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Retryable(org.springframework.retry.annotation.Retryable)

Example 33 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class FreeipaClientTestService method userShow.

public String userShow(Long id, String name) {
    FreeIpaClient freeIpaClient;
    try {
        freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStackId(id);
    } catch (Exception e) {
        LOGGER.error("Error creating FreeIpaClient", e);
        return "FAILED TO CREATE CLIENT";
    }
    try {
        User user = freeIpaClient.userShow(name);
        LOGGER.info("Groups: {}", user.getMemberOfGroup());
        LOGGER.info("Success: {}", user);
    } catch (Exception e) {
        LOGGER.error("Error showing user {}", name, e);
        return "FAILED TO SHOW USER";
    }
    return "END";
}
Also used : User(com.sequenceiq.freeipa.client.model.User) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException)

Example 34 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class LdapConfigV1Service method createNewLdapConfig.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public LdapConfig createNewLdapConfig(String environmentCrn, String clusterName, Stack stack, boolean ignoreExistingUser) throws FreeIpaClientException {
    LOGGER.debug("Create new LDAP config for environment in FreeIPA");
    FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStack(stack);
    User user = ignoreExistingUser ? createBindUserIgnoreExisting(clusterName, freeIpaClient) : createBindUser(clusterName, freeIpaClient);
    String password = setBindUserPassword(freeIpaClient, user);
    return ldapConfigRegisterService.createLdapConfig(stack.getId(), user.getDn(), password, clusterName, environmentCrn);
}
Also used : User(com.sequenceiq.freeipa.client.model.User) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Retryable(org.springframework.retry.annotation.Retryable)

Example 35 with User

use of com.sequenceiq.freeipa.client.model.User in project cloudbreak by hortonworks.

the class UserRemoveOperationTest method testInvoke.

@Test
public void testInvoke() throws FreeIpaClientException {
    RPCResponse<Object> rpcResponse = new RPCResponse<>();
    rpcResponse.setResult(new User());
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
    UserRemoveOperation.create(USER_NAME).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("user_del"), anyList(), any(), any());
}
Also used : User(com.sequenceiq.freeipa.client.model.User) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.sequenceiq.freeipa.client.model.User)38 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)15 Test (org.junit.jupiter.api.Test)13 Map (java.util.Map)11 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)10 Set (java.util.Set)8 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)7 FmsUser (com.sequenceiq.freeipa.service.freeipa.user.model.FmsUser)7 List (java.util.List)7 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 UserMetadata (com.sequenceiq.freeipa.service.freeipa.user.model.UserMetadata)4 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 SetPasswordRequest (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)3 FmsGroup (com.sequenceiq.freeipa.service.freeipa.user.model.FmsGroup)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)2 FreeIpaErrorCodes (com.sequenceiq.freeipa.client.FreeIpaErrorCodes)2