Search in sources :

Example 6 with OrcidBadRequestException

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

the class MemberV2ApiServiceDelegatorImpl method validateSearchParams.

private void validateSearchParams(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"));
        }
    } 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 7 with OrcidBadRequestException

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

the class OrcidApiServiceDelegatorImpl method validateStart.

private void validateStart(Map<String, List<String>> queryMap) {
    String clientId = orcidSecurityManager.getClientIdFromAPIRequest();
    if (clientId == null) {
        // only validate start param where no client credentials
        List<String> startList = queryMap.get("start");
        if (startList != null && !startList.isEmpty()) {
            try {
                String startString = startList.get(0);
                int start = Integer.valueOf(startString);
                if (start < 0 || start > OrcidSearchManager.MAX_SEARCH_START) {
                    throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
                }
            } catch (NumberFormatException e) {
                throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
            }
        }
    }
}
Also used : OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException)

Example 8 with OrcidBadRequestException

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

the class ApiVersionCheckFilterTest method apiDefaultVersionTest.

@Test
public void apiDefaultVersionTest() {
    WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
    URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
    URI requestUri = URI.create("http://localhost:8443/orcid-api-web/0000-0001-7510-9252/activities");
    InBoundHeaders headers = new InBoundHeaders();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
    ContainerRequest containerRequest = new ContainerRequest(webApp, "GET", baseUri, requestUri, headers, inputStream);
    ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
    filter.filter(containerRequest);
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) ByteArrayInputStream(java.io.ByteArrayInputStream) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Example 9 with OrcidBadRequestException

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

the class ApiVersionCheckFilterTest method invalidWebhooksShouldNotWork.

@Test
public void invalidWebhooksShouldNotWork() {
    WebApplication webApp = Mockito.mock(WebApplication.class, Mockito.RETURNS_MOCKS);
    URI baseUri = URI.create("http://localhost:8443/orcid-api-web/");
    URI requestUri = URI.create("http://localhost:8443/orcid-api-web/0000-0001-7510-9252/webhook/");
    InBoundHeaders headers = new InBoundHeaders();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[0]);
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "POST", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "PUT", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        ContainerRequest containerRequest = new ContainerRequest(webApp, "DELETE", baseUri, requestUri, headers, inputStream);
        ApiVersionCheckFilter filter = getApiVersionCheckFilter("http");
        filter.filter(containerRequest);
        fail();
    } catch (OrcidBadRequestException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : InBoundHeaders(com.sun.jersey.core.header.InBoundHeaders) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) ByteArrayInputStream(java.io.ByteArrayInputStream) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) WebApplication(com.sun.jersey.spi.container.WebApplication) URI(java.net.URI) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) Test(org.junit.Test)

Example 10 with OrcidBadRequestException

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

the class PublicV2ApiServiceDelegatorImpl method validateStart.

private void validateStart(Map<String, List<String>> queryMap) {
    String clientId = orcidSecurityManager.getClientIdFromAPIRequest();
    if (clientId == null) {
        // only validate start param where no client credentials
        List<String> startList = queryMap.get("start");
        if (startList != null && !startList.isEmpty()) {
            try {
                String startString = startList.get(0);
                int start = Integer.valueOf(startString);
                if (start < 0 || start > OrcidSearchManager.MAX_SEARCH_START) {
                    throw new SearchStartParameterLimitExceededException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
                }
            } catch (NumberFormatException e) {
                throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_start.exception", OrcidSearchManager.MAX_SEARCH_START));
            }
        }
    }
}
Also used : OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) SearchStartParameterLimitExceededException(org.orcid.core.exception.SearchStartParameterLimitExceededException)

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