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();
}
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);
}
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";
}
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);
}
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());
}
Aggregations