use of com.cloudera.api.swagger.model.ApiUser2 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.ApiUser2 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.ApiUser2 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.ApiUser2 in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method setUpUsersAlreadyCreated.
private void setUpUsersAlreadyCreated(UsersResourceApi usersResourceApi, Cluster cluster) throws ApiException {
ApiUser2List oldUserList = new ApiUser2List().addItemsItem(new ApiUser2().name(ADMIN)).addItemsItem(new ApiUser2().name(cluster.getUserName()).password(cluster.getPassword())).addItemsItem(new ApiUser2().name(cluster.getCloudbreakAmbariUser()).password(cluster.getCloudbreakAmbariPassword())).addItemsItem(new ApiUser2().name(cluster.getDpAmbariUser()).password(cluster.getDpAmbariPassword()));
when(usersResourceApi.readUsers2("SUMMARY")).thenReturn(oldUserList);
}
use of com.cloudera.api.swagger.model.ApiUser2 in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method createApiUser2List.
private ApiUser2List createApiUser2List() {
ApiUser2List apiUser2List = new ApiUser2List();
ApiUser2 admin = new ApiUser2();
admin.setName(ADMIN);
admin.setAuthRoles(Collections.singletonList(new ApiAuthRoleRef()));
apiUser2List.setItems(List.of(admin));
return apiUser2List;
}
Aggregations