use of org.orcid.jaxb.model.error_rc2.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);
}
}
use of org.orcid.jaxb.model.error_rc2.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);
}
use of org.orcid.jaxb.model.error_rc2.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);
}
use of org.orcid.jaxb.model.error_rc2.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());
}
use of org.orcid.jaxb.model.error_rc2.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());
}
Aggregations