use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteAPITokenServiceImplTest method setUp.
@Before
public void setUp() {
tokenRepository = mock(RemoteApiTokenRepository.class);
userRepo = mock(UserRepository.class);
oauthClient = mock(OAuthClient.class);
service = new RemoteAPITokenServiceImpl(tokenRepository, userRepo, oauthClient);
user = new User("tom", "an@email.com", "password1", "tom", "matthews", "123456789");
remoteAPI = new RemoteAPI("apiname", "http://nowhere", "a test api", "clientId", "clientSecret");
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(user, null));
remoteAPIToken = new RemoteAPIToken("token", remoteAPI, new Date());
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteServiceImplTest method testList.
@Test
public void testList() {
String uri = "http://resourcelist";
RemoteAPI remoteAPI = new RemoteAPI();
service.list(uri, remoteAPI);
verify(repository).list(uri, remoteAPI);
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class RemoteServiceImplTest method testReadWithoutApi.
@Test
public void testReadWithoutApi() {
String uri = "http://resource";
RemoteAPI remoteAPI = new RemoteAPI();
when(apiRepo.getRemoteAPIForUrl(uri)).thenReturn(remoteAPI);
service.read(uri);
verify(repository).read(uri, remoteAPI);
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class ProjectsController method ajaxGetProjectsForApi.
/**
* List all the {@link Project}s that can be read for a user from a given
* {@link RemoteAPI}
*
* @param apiId
* the local ID of the {@link RemoteAPI}
* @return a List of {@link Project}s
*/
@RequestMapping(value = "/projects/ajax/api/{apiId}")
@ResponseBody
public List<ProjectByApiResponse> ajaxGetProjectsForApi(@PathVariable Long apiId) {
RemoteAPI api = remoteApiService.read(apiId);
List<Project> listProjectsForAPI = projectRemoteService.listProjectsForAPI(api);
return listProjectsForAPI.stream().map(ProjectByApiResponse::new).collect(Collectors.toList());
}
use of ca.corefacility.bioinformatics.irida.model.RemoteAPI in project irida by phac-nml.
the class OltuAuthorizationController method getTokenFromAuthCode.
/**
* Receive the OAuth2 authorization code and request an OAuth2 token
*
* @param request
* The incoming request
* @param response
* The response to redirect
* @param apiId
* the Long ID of the API we're requesting from
* @param redirect
* The URL location to redirect to after completion
* @return A ModelAndView redirecting back to the resource that was
* requested
* @throws OAuthSystemException
* if we can't get an access token for the current request.
* @throws OAuthProblemException
* if we can't get a response from the authorization server
*/
@RequestMapping(TOKEN_ENDPOINT)
public String getTokenFromAuthCode(HttpServletRequest request, HttpServletResponse response, @RequestParam("apiId") Long apiId, @RequestParam("redirect") String redirect) throws OAuthSystemException, OAuthProblemException {
// Get the OAuth2 auth code
OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
String code = oar.getCode();
logger.trace("Received auth code: " + code);
// Build the redirect URI to request a token from
String tokenRedirect = buildRedirectURI(apiId, redirect);
// Read the RemoteAPI from the RemoteAPIService and get the base URI
RemoteAPI remoteAPI = remoteAPIService.read(apiId);
tokenService.createTokenFromAuthCode(code, remoteAPI, tokenRedirect);
// redirect the response back to the requested resource
return "redirect:" + redirect;
}
Aggregations