Package org.iplantc.agave.client.model

Examples of org.iplantc.agave.client.model.AccessToken


        int lifetime = 14400;
        int expiresIn = json.get("expires_in").asInt();
        DateTime created = new DateTime();
        created = created.minusSeconds(lifetime - expiresIn);
       
        AccessToken token = new AccessToken();
        token.setAccessToken(json.get("access_token").asText());
        token.setClientSecret(clientSecret);
        token.setClientKey(clientKey);
        token.setCreatedAt(created);
        token.setExpiresAt(new DateTime().plusSeconds(expiresIn));
        token.setRefreshToken(json.get("refresh_token").asText());
       
        tokenResponse.setResult(token);
      }
      else
      {
View Full Code Here


  public void createAuthToken() {
    try {
      TokenApi api = new TokenApi();
      TokenResponse response = api.createAuthToken(Settings.API_USERNAME, Settings.API_PASSWORD, Settings.API_CLIENT_KEY, Settings.API_CLIENT_SECRET);
      Assert.assertNotNull(response, "Null response from API");
      AccessToken token = response.getResult();
      Assert.assertNotNull(token, "Null token from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getAccessToken()), "Null access token string from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getRefreshToken()), "Null refresh token string from API");
      Assert.assertTrue(token.getCreatedAt().isBeforeNow(), "Token creation time was not in the past.");
      Assert.assertTrue(token.getExpiresAt().isAfterNow(), "Token creation time was not in the past.");
    } catch (ApiException e) {
      Assert.fail("Failed to pull access token from api", e);
    }
  }
View Full Code Here

  {
    try {
      TokenApi api = new TokenApi();
      TokenResponse response = api.createAuthToken(Settings.API_USERNAME, Settings.API_PASSWORD, Settings.API_CLIENT_KEY, Settings.API_CLIENT_SECRET);
      Assert.assertNotNull(response, "Null response from API");
      AccessToken token = response.getResult();
      Assert.assertNotNull(token, "Null token from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getAccessToken()), "Null access token string from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getRefreshToken()), "Null refresh token string from API");
      Assert.assertTrue(token.getCreatedAt().isBeforeNow(), "Token creation time was not in the past.");
      Assert.assertTrue(token.getExpiresAt().isAfterNow(), "Token creation time was not in the past.");
     
      TokenResponse refreshResponse = api.refreshAuthToken(Settings.API_CLIENT_KEY, Settings.API_CLIENT_SECRET, token.getRefreshToken());
      AccessToken refreshToken = refreshResponse.getResult();
      Assert.assertNotNull(refreshToken, "Null refresh token from API");
      Assert.assertFalse(StringUtils.isEmpty(refreshToken.getAccessToken()), "Null refresh access token string from API");
      Assert.assertFalse(StringUtils.isEmpty(refreshToken.getRefreshToken()), "Null refresh refresh token string from API");
      Assert.assertTrue(refreshToken.getCreatedAt().isBefore(new DateTime().minusSeconds(2)), "Refresh token creation time was not in the past.");
      Assert.assertTrue(refreshToken.getExpiresAt().isAfterNow(), "Refresh token expiration time was not in the future.");
      Assert.assertTrue(refreshToken.getExpiresAt().isAfter(token.getExpiresAt()), "Refresh token creation time was after the original token expiration time.");
    } catch (ApiException e) {
      Assert.fail("Failed to pull access token from api", e);
    }
  }
View Full Code Here

    try
    {
      TokenApi api = new TokenApi();
      TokenResponse response = api.createAuthToken(Settings.API_USERNAME, Settings.API_PASSWORD, Settings.API_CLIENT_KEY, Settings.API_CLIENT_SECRET);
      Assert.assertNotNull(response, "Null response from API");
      AccessToken token = response.getResult();
      Assert.assertNotNull(token, "Null token from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getAccessToken()), "Null access token string from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getRefreshToken()), "Null refresh token string from API");
      Assert.assertTrue(token.getCreatedAt().isBeforeNow(), "Token creation time was not in the past.");
      Assert.assertTrue(token.getExpiresAt().isAfterNow(), "Token creation time was not in the past.");
   
      token.exportCache(Settings.AUTH_CACHE_FILE);
      Assert.assertTrue(Settings.AUTH_CACHE_FILE.exists(), "Cache file does not exist.");
     
      JsonNode json = JsonUtil.getJsonMapper().readTree(Settings.AUTH_CACHE_FILE);
     
      Assert.assertEquals(json.get("access_token").asText(), token.getAccessToken(),
          "Access token saved does not match that returned from the API");
     
    } catch (Exception e) {
      Assert.fail("Failed to pull access token from api", e);
    }
View Full Code Here

    try
    {
      TokenApi api = new TokenApi();
      TokenResponse response = api.createAuthToken(Settings.API_USERNAME, Settings.API_PASSWORD, Settings.API_CLIENT_KEY, Settings.API_CLIENT_SECRET);
      Assert.assertNotNull(response, "Null response from API");
      AccessToken token = response.getResult();
      Assert.assertNotNull(token, "Null token from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getAccessToken()), "Null access token string from API");
      Assert.assertFalse(StringUtils.isEmpty(token.getRefreshToken()), "Null refresh token string from API");
      Assert.assertTrue(token.getCreatedAt().isBeforeNow(), "Token creation time was not in the past.");
      Assert.assertTrue(token.getExpiresAt().isAfterNow(), "Token creation time was not in the past.");
   
      token.exportCache(Settings.AUTH_CACHE_FILE);
      Assert.assertTrue(Settings.AUTH_CACHE_FILE.exists(), "Cache file does not exist.");
     
      JsonNode json = JsonUtil.getJsonMapper().readTree(Settings.AUTH_CACHE_FILE);
      Assert.assertEquals(json.get("access_token").asText(), token.getAccessToken(),
          "Access token saved does not match that returned from the API");
     
      AccessToken importToken = AccessToken.importCache(Settings.AUTH_CACHE_FILE);
      Assert.assertTrue(importToken.equals(token),
          "Access token read does not match that returned from the API and saved");
     
     
    } catch (Exception e) {
      Assert.fail("Failed to pull access token from api", e);
View Full Code Here

TOP

Related Classes of org.iplantc.agave.client.model.AccessToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.