use of com.cloudera.api.swagger.UsersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsNotConfiguredAndTheGivenUserIsNotAdmin.
@Test
public void testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsNotConfiguredAndTheGivenUserIsNotAdmin() throws CloudbreakException, ApiException, ClouderaManagerClientInitException {
initTestInput("ambariUser");
UsersResourceApi usersResourceApi = mock(UsersResourceApi.class);
UsersResourceApi newUsersResourceApi = mock(UsersResourceApi.class);
ToolsResourceApi toolsResourceApi = mock(ToolsResourceApi.class);
ApiClient newApiClient = mock(ApiClient.class);
ApiUser2List oldUserList = createApiUser2List();
when(clouderaManagerApiClientProvider.getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
when(clouderaManagerApiFactory.getUserResourceApi(apiClient)).thenReturn(usersResourceApi);
when(usersResourceApi.readUsers2("SUMMARY")).thenReturn(oldUserList);
when(clouderaManagerApiFactory.getToolsResourceApi(any())).thenReturn(toolsResourceApi);
when(toolsResourceApi.echo("TEST")).thenReturn(new ApiEcho());
when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(newApiClient);
when(clouderaManagerApiFactory.getUserResourceApi(newApiClient)).thenReturn(newUsersResourceApi);
underTest.changeOriginalCredentialsAndCreateCloudbreakUser(LDAP_DISABLED);
verify(clouderaManagerApiClientProvider).getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31);
verify(usersResourceApi).readUsers2("SUMMARY");
verify(clouderaManagerApiClientProvider).getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31);
ArgumentCaptor<ApiUser2List> createUserCaptor = ArgumentCaptor.forClass(ApiUser2List.class);
verify(usersResourceApi, times(2)).createUsers2(createUserCaptor.capture());
List<ApiUser2List> createdUsers = createUserCaptor.getAllValues();
assertEquals(stack.getCluster().getCloudbreakAmbariUser(), createdUsers.get(0).getItems().get(0).getName());
assertEquals(stack.getCluster().getCloudbreakAmbariPassword(), createdUsers.get(0).getItems().get(0).getPassword());
assertEquals(stack.getCluster().getDpAmbariUser(), createdUsers.get(1).getItems().get(0).getName());
assertEquals(stack.getCluster().getDpAmbariPassword(), createdUsers.get(1).getItems().get(0).getPassword());
ArgumentCaptor<ApiUser2List> createNewUserCaptor = ArgumentCaptor.forClass(ApiUser2List.class);
verify(newUsersResourceApi).createUsers2(createNewUserCaptor.capture());
List<ApiUser2List> createdNewUser = createNewUserCaptor.getAllValues();
assertEquals(stack.getCluster().getUserName(), createdNewUser.get(0).getItems().get(0).getName());
assertEquals(stack.getCluster().getPassword(), createdNewUser.get(0).getItems().get(0).getPassword());
verifyNoMoreInteractions(clouderaManagerApiClientProvider);
}
use of com.cloudera.api.swagger.UsersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method replaceUserNamePassword.
@Override
public void replaceUserNamePassword(String newUserName, String newPassword) throws CloudbreakException {
Cluster cluster = stack.getCluster();
String user = cluster.getCloudbreakAmbariUser();
String password = cluster.getCloudbreakAmbariPassword();
try {
ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig);
UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
ApiUser2List oldUserList = usersResourceApi.readUsers2("SUMMARY");
Optional<ApiUser2> oldAdminUser = oldUserList.getItems().stream().filter(apiUser2 -> apiUser2.getName().equals(stack.getCluster().getUserName())).findFirst();
if (oldAdminUser.isPresent()) {
createNewUser(usersResourceApi, oldAdminUser.get().getAuthRoles(), newUserName, newPassword, oldUserList);
usersResourceApi.deleteUser2(oldAdminUser.get().getName());
} else {
throw new CloudbreakException("Can't find original admin user");
}
} catch (ApiException | ClouderaManagerClientInitException e) {
LOGGER.info("Can't replace original admin user due to: ", e);
throw new CloudbreakException("Can't replace original admin user due to: " + e.getMessage());
}
}
use of com.cloudera.api.swagger.UsersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method removeDefaultAdminUser.
private void removeDefaultAdminUser(boolean ldapConfigured, Optional<String> userName) {
if (ldapConfigured && isUserIsNullOrNotAdmin(userName)) {
try {
String user = stack.getCluster().getCloudbreakAmbariUser();
String password = stack.getCluster().getCloudbreakAmbariPassword();
ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig);
UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
usersResourceApi.deleteUser2(ADMIN_USER);
} catch (ApiException | ClouderaManagerClientInitException e) {
LOGGER.info("Can't remove default admin user due to: ", e);
}
}
}
use of com.cloudera.api.swagger.UsersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method createUserSuppliedCMUser.
private void createUserSuppliedCMUser(ApiUser2List userList, ApiUser2 oldAdminUser, Cluster cluster) throws ClouderaManagerClientInitException, ApiException {
ApiClient client;
String user = cluster.getCloudbreakAmbariUser();
String password = cluster.getCloudbreakAmbariPassword();
client = getClient(stack.getGatewayPort(), user, password, clientConfig);
UsersResourceApi newUsersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
createNewUser(newUsersResourceApi, oldAdminUser.getAuthRoles(), cluster.getUserName(), cluster.getPassword(), userList);
}
use of com.cloudera.api.swagger.UsersResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method updateUserNamePassword.
@Override
public void updateUserNamePassword(String newPassword) throws CloudbreakException {
Cluster cluster = stack.getCluster();
String cmUser = cluster.getCloudbreakAmbariUser();
String password = cluster.getCloudbreakAmbariPassword();
try {
ApiClient client = getClient(stack.getGatewayPort(), cmUser, password, clientConfig);
UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
ApiUser2List oldUserList = usersResourceApi.readUsers2("SUMMARY");
Optional<ApiUser2> oldAdminUser = oldUserList.getItems().stream().filter(apiUser2 -> apiUser2.getName().equals(stack.getCluster().getUserName())).findFirst();
if (oldAdminUser.isPresent()) {
ApiUser2 user = oldAdminUser.get();
user.setPassword(newPassword);
usersResourceApi.updateUser2(user.getName(), user);
} else {
throw new CloudbreakException("Can't find admin user");
}
} catch (ApiException | ClouderaManagerClientInitException e) {
LOGGER.info("Can't replace admin password due to: ", e);
throw new CloudbreakException("Can't replace admin password due to: " + e.getMessage());
}
}
Aggregations