use of com.cloudera.api.swagger.model.ApiUser2List in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method setupMonitoringUser.
@Override
public void setupMonitoringUser() 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);
String monitoringUser = cluster.getCloudbreakClusterManagerMonitoringUser();
String monitoringPassword = cluster.getCloudbreakClusterManagerMonitoringPassword();
ApiUser2List userList = usersResourceApi.readUsers2("SUMMARY");
Optional<ApiUser2> mUser = userList.getItems().stream().filter(apiUser2 -> apiUser2.getName().equals(monitoringUser)).findFirst();
if (mUser.isPresent()) {
LOGGER.info("Monitoring user '{}' already exists. Skipping user generation", monitoringUser);
} else {
List<ApiAuthRoleRef> authRoles = new ArrayList<>();
ApiAuthRoleRef apiAuthRoleRef = new ApiAuthRoleRef();
apiAuthRoleRef.setName("ROLE_ADMIN");
authRoles.add(apiAuthRoleRef);
createNewUser(usersResourceApi, authRoles, monitoringUser, monitoringPassword, userList);
}
} catch (ApiException | ClouderaManagerClientInitException e) {
throw new CloudbreakException("Can't replace admin password due to: " + e.getMessage());
}
}
use of com.cloudera.api.swagger.model.ApiUser2List in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method changeOriginalCredentialsAndCreateCloudbreakUser.
@Override
public void changeOriginalCredentialsAndCreateCloudbreakUser(boolean ldapConfigured) throws CloudbreakException {
LOGGER.debug("change original admin user and create cloudbreak user");
try {
ApiClient client = createApiClient();
UsersResourceApi usersResourceApi = clouderaManagerApiFactory.getUserResourceApi(client);
ApiUser2List userList = usersResourceApi.readUsers2("SUMMARY");
ApiUser2 oldAdminUser = getOldAdminUser(userList).orElseThrow(() -> new CloudbreakException("Can't find original admin user"));
Cluster cluster = stack.getCluster();
createNewUser(usersResourceApi, oldAdminUser.getAuthRoles(), cluster.getCloudbreakAmbariUser(), cluster.getCloudbreakAmbariPassword(), userList);
createNewUser(usersResourceApi, oldAdminUser.getAuthRoles(), cluster.getDpAmbariUser(), cluster.getDpAmbariPassword(), userList);
if (ADMIN_USER.equals(cluster.getUserName())) {
oldAdminUser.setPassword(cluster.getPassword());
usersResourceApi.updateUser2(oldAdminUser.getName(), oldAdminUser);
} else if (cluster.getUserName() != null) {
createUserSuppliedCMUser(userList, oldAdminUser, cluster);
}
removeDefaultAdminUser(ldapConfigured, Optional.ofNullable(cluster.getUserName()));
} catch (ApiException | ClusterClientInitException | 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.model.ApiUser2List in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method createNewUser.
private void createNewUser(UsersResourceApi usersResourceApi, List<ApiAuthRoleRef> authRoles, String userName, String password, ApiUser2List userList) throws ApiException {
if (checkUserExists(userList, userName)) {
return;
}
ApiUser2List apiUser2List = new ApiUser2List();
ApiUser2 newUser = new ApiUser2();
newUser.setName(userName);
newUser.setPassword(password);
newUser.setAuthRoles(authRoles);
apiUser2List.addItemsItem(newUser);
usersResourceApi.createUsers2(apiUser2List);
}
use of com.cloudera.api.swagger.model.ApiUser2List in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndAdminUserIsProvided.
@Test
public void testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndAdminUserIsProvided() throws CloudbreakException, ApiException, ClouderaManagerClientInitException {
initTestInput(ADMIN);
UsersResourceApi usersResourceApi = mock(UsersResourceApi.class);
ToolsResourceApi toolsResourceApi = mock(ToolsResourceApi.class);
ApiUser2List oldUserList = createApiUser2List();
when(clouderaManagerApiClientProvider.getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
when(clouderaManagerApiFactory.getUserResourceApi(any())).thenReturn(usersResourceApi);
when(usersResourceApi.readUsers2("SUMMARY")).thenReturn(oldUserList);
when(clouderaManagerApiFactory.getToolsResourceApi(any())).thenReturn(toolsResourceApi);
when(toolsResourceApi.echo("TEST")).thenReturn(new ApiEcho());
underTest.changeOriginalCredentialsAndCreateCloudbreakUser(LDAP_ENABLED);
verify(clouderaManagerApiFactory).getUserResourceApi(apiClient);
verify(usersResourceApi).readUsers2("SUMMARY");
ArgumentCaptor<ApiUser2List> argumentCaptor = ArgumentCaptor.forClass(ApiUser2List.class);
verify(usersResourceApi, times(2)).createUsers2(argumentCaptor.capture());
List<ApiUser2List> createdUsers = argumentCaptor.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());
verify(usersResourceApi).updateUser2(oldUserList.getItems().get(0).getName(), oldUserList.getItems().get(0));
}
use of com.cloudera.api.swagger.model.ApiUser2List in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndTheGivenUserIsNotAdmin.
@Test
public void testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndTheGivenUserIsNotAdmin() 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_ENABLED);
verify(clouderaManagerApiClientProvider).getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31);
verify(usersResourceApi).readUsers2("SUMMARY");
verify(clouderaManagerApiClientProvider, times(2)).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());
verify(newUsersResourceApi).deleteUser2(ADMIN);
}
Aggregations