Search in sources :

Example 11 with OrcidBadRequestException

use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.

the class PublicV2ApiServiceDelegatorImpl method validateRows.

private void validateRows(Map<String, List<String>> queryMap) {
    List<String> rowsList = queryMap.get("rows");
    if (rowsList != null && !rowsList.isEmpty()) {
        try {
            String rowsString = rowsList.get(0);
            int rows = Integer.valueOf(rowsString);
            if (rows < 0 || rows > OrcidSearchManager.MAX_SEARCH_ROWS) {
                throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_rows.exception", OrcidSearchManager.MAX_SEARCH_ROWS));
            }
        } catch (NumberFormatException e) {
            throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_rows.exception", OrcidSearchManager.MAX_SEARCH_ROWS));
        }
    } else {
        // Set the default number of results
        queryMap.put("rows", Arrays.asList(String.valueOf(OrcidSearchManager.DEFAULT_SEARCH_ROWS)));
    }
}
Also used : OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException)

Example 12 with OrcidBadRequestException

use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.

the class ApiVersionCheckFilter method filter.

@Override
public ContainerRequest filter(ContainerRequest request) {
    String path = request.getPath();
    String method = request.getMethod() == null ? null : request.getMethod().toUpperCase();
    Matcher matcher = VERSION_PATTERN.matcher(path);
    String version = null;
    if (matcher.lookingAt()) {
        version = matcher.group(1);
    }
    if (PojoUtil.isEmpty(version) && !PojoUtil.isEmpty(method) && !"oauth/token".equals(path) && !path.matches(WEBHOOKS_PATH_PATTERN)) {
        if (!RequestMethod.GET.name().equals(method)) {
            Object[] params = { method };
            throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_missing_version.exception", params));
        }
    } else if (version != null && version.startsWith("1.1") && v1xDisabled) {
        throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_version_disabled.exception"));
    } else if (version != null && version.startsWith("2.0")) {
        if (!OrcidUrlManager.isSecure(httpRequest)) {
            throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_secure_only.exception"));
        }
    }
    return request;
}
Also used : OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Matcher(java.util.regex.Matcher)

Aggregations

OrcidBadRequestException (org.orcid.core.exception.OrcidBadRequestException)12 URI (java.net.URI)3 AccessControl (org.orcid.core.security.visibility.aop.AccessControl)3 InBoundHeaders (com.sun.jersey.core.header.InBoundHeaders)2 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)2 WebApplication (com.sun.jersey.spi.container.WebApplication)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 OrcidNotFoundException (org.orcid.core.exception.OrcidNotFoundException)2 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 DataAccessException (org.springframework.dao.DataAccessException)2 Authentication (org.springframework.security.core.Authentication)2 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)2 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 Date (java.util.Date)1 Locale (java.util.Locale)1