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());
}
Aggregations