Search in sources :

Example 1 with OrcidError

use of org.orcid.jaxb.model.error_v2.OrcidError in project ORCID-Source by ORCID.

the class OrcidOAuth2AuthenticationEntryPoint method handleAsOrcidError.

public void handleAsOrcidError(HttpServletRequest request, HttpServletResponse response, Exception authException) throws IOException, ServletException {
    try {
        ResponseEntity<OAuth2Exception> result = exceptionTranslator.translate(authException);
        result = enhanceResponse(result, authException);
        OrcidError orcidError = new OrcidError();
        orcidError.setResponseCode(result.getStatusCode().value());
        orcidError.setDeveloperMessage(result.getBody().getLocalizedMessage());
        ResponseEntity<OrcidError> errorResponseEntity = new ResponseEntity<>(orcidError, result.getHeaders(), result.getStatusCode());
        exceptionRenderer.handleHttpEntityResponse(errorResponseEntity, new ServletWebRequest(request, response));
        response.flushBuffer();
    } catch (ServletException e) {
        // (even if there is one)
        if (handlerExceptionResolver.resolveException(request, response, this, e) == null) {
            throw e;
        }
    } catch (IOException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        // Wrap other Exceptions. These are not expected to happen
        throw new RuntimeException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ResponseEntity(org.springframework.http.ResponseEntity) IOException(java.io.IOException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 2 with OrcidError

use of org.orcid.jaxb.model.error_v2.OrcidError in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testLimitedWorkBulkReadPublicTokenNoSource.

@Test
public void testLimitedWorkBulkReadPublicTokenNoSource() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.LIMITED, null), createWork(Visibility.LIMITED, null)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_2, ScopePathType.READ_PUBLIC);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(2, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
    assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Test(org.junit.Test)

Example 3 with OrcidError

use of org.orcid.jaxb.model.error_v2.OrcidError in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testMixedPublicAndLimitedWorkBulkReadPublicToken.

@Test
public void testMixedPublicAndLimitedWorkBulkReadPublicToken() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PUBLIC, CLIENT_2), createWork(Visibility.LIMITED, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_PUBLIC);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(2, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 4 with OrcidError

use of org.orcid.jaxb.model.error_v2.OrcidError in project ORCID-Source by ORCID.

the class InternalAPITest method testGetMemberInfo.

@Test
public void testGetMemberInfo() {
    ClientResponse response = internalApiClient.viewMemberDetails(memberId);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = internalApiClient.viewMemberDetails("invalid name");
    assertNotNull(response);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
    OrcidError error = response.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(new Integer(0), error.getErrorCode());
    assertEquals("Member id or name not found for: invalid name", error.getDeveloperMessage());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) Test(org.junit.Test)

Example 5 with OrcidError

use of org.orcid.jaxb.model.error_v2.OrcidError in project ORCID-Source by ORCID.

the class WorksTest method testCantAddMoreThan1000WorksAtATime.

@Test
public void testCantAddMoreThan1000WorksAtATime() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(1001, null);
    ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
    OrcidError error = postResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9006), error.getErrorCode());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc4.OrcidError) WorkBulk(org.orcid.jaxb.model.record_rc4.WorkBulk) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)70 ClientResponse (com.sun.jersey.api.client.ClientResponse)56 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)51 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)25 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)23 Work (org.orcid.jaxb.model.record_v2.Work)22 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)13 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)12 Visibility (org.orcid.jaxb.model.common_v2.Visibility)11 Response (javax.ws.rs.core.Response)8 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)8 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)8 Url (org.orcid.jaxb.model.common_v2.Url)7 LockedRecordException (org.orcid.listener.exception.LockedRecordException)7 DBUnitTest (org.orcid.test.DBUnitTest)7 Locale (java.util.Locale)6 DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)6 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)5