Search in sources :

Example 1 with FatalSecurityException

use of com.emc.storageos.security.exceptions.FatalSecurityException in project coprhd-controller by CoprHD.

the class Validator method refreshUser.

/**
 * Make an internal REST API call to the authsvc in order to reload the user in the
 * DB.
 *
 * @param username
 */
public static void refreshUser(String username) {
    String endpoint = null;
    int attempts = 0;
    while (attempts < _MAX_VALIDATION_RETRIES) {
        _log.debug("Refresh user, attempt {}", ++attempts);
        AuthSvcInternalApiClientIterator authSvcClientItr = new AuthSvcInternalApiClientIterator(_authSvcEndPointLocator, _coordinator);
        try {
            if (authSvcClientItr.hasNext()) {
                endpoint = authSvcClientItr.peek().toString();
                final ClientResponse response = authSvcClientItr.put(URI.create(_URI_REFRESH + "?username=" + URLEncoder.encode(username, "UTF-8")), null);
                final int status = response.getStatus();
                _log.debug("Status: {}", status);
                if (status == ClientResponse.Status.OK.getStatusCode()) {
                    return;
                } else if (status == ClientResponse.Status.BAD_REQUEST.getStatusCode()) {
                    throw APIException.badRequests.principalSearchFailed(username);
                } else if (status == ClientResponse.Status.INTERNAL_SERVER_ERROR.getStatusCode()) {
                    ServiceErrorRestRep error = response.getEntity(ServiceErrorRestRep.class);
                    // if we got here, it means that we refresh user has failed
                    throw SecurityException.fatals.failedToRefreshUser(error.getDetailedMessage());
                } else {
                    _log.error("Unexpected response code {}.", status);
                }
            }
        } catch (APIException e) {
            throw e;
        } catch (FatalSecurityException e) {
            throw e;
        } catch (Exception e) {
            _log.info("Exception connecting to {}. ", endpoint, e);
        }
    }
    throw SecurityException.retryables.requiredServiceUnvailable(ServiceLocatorInfo.AUTH_SVC.getServiceName());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FatalSecurityException(com.emc.storageos.security.exceptions.FatalSecurityException) ServiceErrorRestRep(com.emc.storageos.model.errorhandling.ServiceErrorRestRep) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) AuthSvcInternalApiClientIterator(com.emc.storageos.security.authentication.AuthSvcInternalApiClientIterator) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) FatalSecurityException(com.emc.storageos.security.exceptions.FatalSecurityException) SecurityException(com.emc.storageos.security.exceptions.SecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ServiceErrorRestRep (com.emc.storageos.model.errorhandling.ServiceErrorRestRep)1 AuthSvcInternalApiClientIterator (com.emc.storageos.security.authentication.AuthSvcInternalApiClientIterator)1 FatalSecurityException (com.emc.storageos.security.exceptions.FatalSecurityException)1 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1