use of com.cloudera.api.swagger.model.ApiUser2 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.model.ApiUser2 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