Search in sources :

Example 31 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class AbstractAuthenticationFilter method doFilter.

@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    AbstractRequestWrapper reqWrapper = null;
    try {
        reqWrapper = authenticate(servletRequest);
    } catch (APIException e) {
        _log.debug("unauthorized request: serviceUrl = " + request.getRequestURI(), e);
        response.sendError(toHTTPStatus(e), toServiceErrorXml(e));
        return;
    } catch (final InternalException e) {
        response.sendError(toHTTPStatus(e), toServiceErrorXml(e));
        return;
    }
    if (reqWrapper != null) {
        // we are done, forward it to resource service
        forwardToService(servletRequest, servletResponse, reqWrapper);
    } else {
        // not mine, forward it on to the next filter
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) HttpServletResponse(javax.servlet.http.HttpServletResponse) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 32 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class AbstractRequestWrapperFilter method doFilter.

@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    try {
        final AbstractRequestWrapper reqWrapper = authenticate(servletRequest);
        filterChain.doFilter(reqWrapper, servletResponse);
    } catch (APIException e) {
        _log.debug("unauthorized request: serviceUrl = " + request.getRequestURI(), e);
        response.sendError(toHTTPStatus(e), toServiceErrorXml(e));
        return;
    } catch (final InternalException e) {
        response.sendError(toHTTPStatus(e), toServiceErrorXml(e));
        return;
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) HttpServletResponse(javax.servlet.http.HttpServletResponse) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 33 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class SendAlertEvent method run.

@Override
public void run() {
    try {
        super.callEMCHome();
        dbClient.ready(SysEvent.class, sysEventId, operationId);
        alertsLog.warn("Alert event initiated by " + _eventParameters.getContact() + " is sent successfully");
    } catch (APIException api) {
        dbClient.error(SysEvent.class, sysEventId, operationId, api);
        alertsLog.error("Failed to send alert event initiated by " + _eventParameters.getContact() + ". " + api.getMessage());
    } finally {
        SysEvent sysEvent = permissionsHelper.getObjectById(sysEventId, SysEvent.class);
        dbClient.removeObject(sysEvent);
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SysEvent(com.emc.storageos.db.client.model.SysEvent)

Example 34 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException 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)

Example 35 with APIException

use of com.emc.storageos.svcs.errorhandling.resources.APIException in project coprhd-controller by CoprHD.

the class Validator method getUserTenants.

public static UserTenantList getUserTenants(String username, TenantOrg tenant) {
    String endpoint = null;
    int attempts = 0;
    while (attempts < _MAX_VALIDATION_RETRIES) {
        _log.debug("Get user tenants attempt {}", ++attempts);
        AuthSvcInternalApiClientIterator authSvcClientItr = new AuthSvcInternalApiClientIterator(_authSvcEndPointLocator, _coordinator);
        try {
            if (authSvcClientItr.hasNext()) {
                endpoint = authSvcClientItr.peek().toString();
                // 
                String queryParameters = "?username=" + username;
                if (tenant != null) {
                    queryParameters += "&tenantURI=" + tenant.getId();
                    if (tenant.getUserMappings() != null) {
                        String userMappingStr = MarshallUtil.convertTenantUserMappingToString(tenant);
                        String encodedUserMapping = URLEncoder.encode(userMappingStr);
                        queryParameters += "&usermappings=" + encodedUserMapping;
                    }
                }
                final ClientResponse response = authSvcClientItr.get(URI.create(_URI_USERTENANT + queryParameters));
                final int status = response.getStatus();
                _log.debug("Status: {}", status);
                if (status == ClientResponse.Status.OK.getStatusCode()) {
                    return response.getEntity(UserTenantList.class);
                } else if (status == ClientResponse.Status.BAD_REQUEST.getStatusCode()) {
                    throw APIException.badRequests.theParametersAreNotValid(response.hasEntity() ? response.getEntity(String.class) : "Bad request");
                } else {
                    _log.info("Unexpected response code {}.", status);
                }
            }
        } catch (APIException 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) 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

APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)55 URI (java.net.URI)28 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)25 Produces (javax.ws.rs.Produces)22 Path (javax.ws.rs.Path)21 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)20 ArrayList (java.util.ArrayList)19 POST (javax.ws.rs.POST)19 Volume (com.emc.storageos.db.client.model.Volume)18 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)18 TaskList (com.emc.storageos.model.TaskList)17 Consumes (javax.ws.rs.Consumes)16 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)13 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)12 Operation (com.emc.storageos.db.client.model.Operation)10 DataObject (com.emc.storageos.db.client.model.DataObject)9 NamedURI (com.emc.storageos.db.client.model.NamedURI)9 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)7