Search in sources :

Example 1 with OrcidError

use of org.orcid.jaxb.model.error_rc1.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_rc1.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_rc1.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_rc1.OrcidError in project ORCID-Source by ORCID.

the class AccessTokenSecurityChecksTest method evaluateResponse.

private void evaluateResponse(ClientResponse response) {
    assertNotNull(response);
    assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
    OrcidError error = response.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals("401 Unauthorized: The client application is not authorized for this ORCID record.", error.getDeveloperMessage());
    assertEquals(Integer.valueOf(9017), error.getErrorCode());
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError)

Example 5 with OrcidError

use of org.orcid.jaxb.model.error_rc1.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)

Aggregations

Test (org.junit.Test)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)54 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)43 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)24 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)21 Work (org.orcid.jaxb.model.record_v2.Work)19 Visibility (org.orcid.jaxb.model.common_v2.Visibility)10 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)9 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)9 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)8 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)8 Response (javax.ws.rs.core.Response)7 Locale (java.util.Locale)6 DBUnitTest (org.orcid.test.DBUnitTest)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 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)4 Url (org.orcid.jaxb.model.common_v2.Url)4 ArrayList (java.util.ArrayList)3