Search in sources :

Example 36 with RemoteAPI

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());
}
Also used : RemoteAPITokenServiceImpl(ca.corefacility.bioinformatics.irida.service.impl.RemoteAPITokenServiceImpl) RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) User(ca.corefacility.bioinformatics.irida.model.user.User) OAuthClient(org.apache.oltu.oauth2.client.OAuthClient) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) RemoteApiTokenRepository(ca.corefacility.bioinformatics.irida.repositories.RemoteApiTokenRepository) Date(java.util.Date) Before(org.junit.Before)

Example 37 with RemoteAPI

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);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Test(org.junit.Test)

Example 38 with 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);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) Test(org.junit.Test)

Example 39 with 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());
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) DTProject(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProject) Project(ca.corefacility.bioinformatics.irida.model.project.Project) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 40 with RemoteAPI

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;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) OAuthAuthzResponse(org.apache.oltu.oauth2.client.response.OAuthAuthzResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)44 Test (org.junit.Test)30 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)6 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)6 URI (java.net.URI)5 Date (java.util.Date)5 Link (org.springframework.hateoas.Link)5 IridaOAuthException (ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)3 RemoteStatus (ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)3 Before (org.junit.Before)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 OAuthTokenRestTemplate (ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)2