Search in sources :

Example 1 with SysSvcEndPointLocator

use of com.emc.storageos.security.authentication.SysSvcEndPointLocator in project coprhd-controller by CoprHD.

the class PasswordUtils method changePassword.

/**
 * a wrapper to call change-password internal API or validate-change internal API in PasswordService
 *
 * bDryRun: if true, call validate-change internal API
 * if false, call change-password internal API
 *
 * @param passwordChange
 * @param bDryRun
 * @return
 */
public Response changePassword(PasswordChangeParam passwordChange, boolean bDryRun) {
    SysSvcEndPointLocator sysSvcEndPointLocator = new SysSvcEndPointLocator();
    sysSvcEndPointLocator.setCoordinator(coordinator);
    int attempts = 0;
    ClientResponse response = null;
    while (attempts < MAX_CONFIG_RETRIES) {
        _log.debug("change password attempt {}", ++attempts);
        AuthSvcInternalApiClientIterator sysSvcClientItr = new AuthSvcInternalApiClientIterator(sysSvcEndPointLocator, coordinator);
        try {
            if (sysSvcClientItr.hasNext()) {
                if (bDryRun) {
                    _log.debug("change password dry run");
                    response = sysSvcClientItr.post(URI_VALIDATE_PASSWORD, passwordChange);
                } else {
                    response = sysSvcClientItr.put(URI_CHANGE_PASSWORD, passwordChange);
                }
                _log.debug("change password response with status: " + response.getStatus());
                break;
            }
        } catch (Exception exception) {
            // log the exception and retry the request
            _log.warn(exception.getMessage());
            if (attempts == MAX_CONFIG_RETRIES - 1) {
                throw exception;
            }
        }
    }
    Response.ResponseBuilder b = Response.status(response.getStatus());
    if (!(response.getStatus() == ClientResponse.Status.NO_CONTENT.getStatusCode())) {
        b.entity(response.getEntity(String.class));
    }
    return b.build();
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientResponse(com.sun.jersey.api.client.ClientResponse) Response(javax.ws.rs.core.Response) AuthSvcInternalApiClientIterator(com.emc.storageos.security.authentication.AuthSvcInternalApiClientIterator) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) SysSvcEndPointLocator(com.emc.storageos.security.authentication.SysSvcEndPointLocator)

Aggregations

CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 AuthSvcInternalApiClientIterator (com.emc.storageos.security.authentication.AuthSvcInternalApiClientIterator)1 SysSvcEndPointLocator (com.emc.storageos.security.authentication.SysSvcEndPointLocator)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 Response (javax.ws.rs.core.Response)1