use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class SampleRemoteRepositoryImpl method getSampleMetadata.
/**
* {@inheritDoc}
*/
public Map<String, MetadataEntry> getSampleMetadata(Sample sample) {
logger.trace("Requesting sample metadata for sample " + sample.getSelfHref());
RemoteAPI remoteAPI = sample.getRemoteStatus().getApi();
OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
// get the metadata link
Link metadataLink = sample.getLink(METADATA_REL);
// request metadata response
ResponseEntity<ResourceWrapper<SampleMetadataWrapper>> exchange = restTemplate.exchange(metadataLink.getHref(), HttpMethod.GET, HttpEntity.EMPTY, metadataTypeReference);
// pull metadata response from request
Map<String, MetadataEntry> resource = exchange.getBody().getResource().getMetadata();
return resource;
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class OltuAuthorizationControllerTest method testAuthenticate.
@Test
public void testAuthenticate() throws OAuthSystemException, UnsupportedEncodingException {
RemoteAPI remoteAPI = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
remoteAPI.setId(1L);
String redirect = "http://base";
String authenticate = controller.authenticate(remoteAPI, redirect);
// need to decode the escaped characters
String decoded = URLDecoder.decode(authenticate, "UTF-8");
assertTrue(decoded.startsWith("redirect:"));
assertTrue(decoded.contains(redirect));
assertTrue(decoded.contains(serverBase));
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class OltuAuthorizationControllerTest method testGetTokenFromAuthCode.
@Test
public void testGetTokenFromAuthCode() throws IOException, OAuthSystemException, OAuthProblemException, URISyntaxException {
Long apiId = 1L;
RemoteAPI remoteAPI = new RemoteAPI("name", "http://remoteLocation", "a description", "id", "secret");
remoteAPI.setId(apiId);
String code = "code";
String redirect = "http://originalPage";
when(apiService.read(apiId)).thenReturn(remoteAPI);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
Map<String, String[]> requestParams = new HashMap<>();
requestParams.put("code", new String[] { code });
when(request.getParameterMap()).thenReturn(requestParams);
controller.getTokenFromAuthCode(request, response, apiId, redirect);
verify(apiService).read(apiId);
ArgumentCaptor<String> redirectArg = ArgumentCaptor.forClass(String.class);
verify(tokenService).createTokenFromAuthCode(eq(code), eq(remoteAPI), redirectArg.capture());
String capturedRedirect = redirectArg.getValue();
assertTrue(capturedRedirect.contains(redirect));
assertTrue(capturedRedirect.contains(serverBase));
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteAPIControllerTest method testConnectToAPI.
@Test(expected = IridaOAuthException.class)
public void testConnectToAPI() {
Long apiId = 1L;
ExtendedModelMap model = new ExtendedModelMap();
RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
when(remoteAPIService.read(apiId)).thenReturn(client);
when(projectRemoteService.getServiceStatus(client)).thenThrow(new IridaOAuthException("invalid token", client));
remoteAPIController.connectToAPI(apiId, model);
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteAPIControllerTest method testHandleOAuthException.
@Test
public void testHandleOAuthException() throws MalformedURLException, OAuthSystemException {
HttpServletRequest request = mock(HttpServletRequest.class);
String redirect = "http://request";
when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).thenReturn(redirect);
RemoteAPI client = new RemoteAPI("name", "http://uri", "a description", "id", "secret");
IridaOAuthException ex = new IridaOAuthException("msg", client);
remoteAPIController.handleOAuthException(request, ex);
verify(authController).authenticate(client, redirect);
}
Aggregations