Package org.springframework.security.oauth2.client.token

Examples of org.springframework.security.oauth2.client.token.AccessTokenRequest


    requestFactory = new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(new ObjectMapper().writeValueAsString(token));
      }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("foo");
    resource.setAccessTokenUri("http://localhost/oauth/token");
    setUpRestTemplate();
    assertEquals(token, provider.obtainAccessToken(resource, request));
  }
View Full Code Here


      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(HttpStatus.BAD_REQUEST,
            new ObjectMapper().writeValueAsString(exception));
      }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("foo");
    resource.setAccessTokenUri("http://localhost/oauth/token");
    expected.expect(OAuth2AccessDeniedException.class);
    expected.expect(hasCause(instanceOf(InvalidClientException.class)));
    setUpRestTemplate();
    provider.obtainAccessToken(resource, request);
View Full Code Here

    requestFactory = new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(responseHeaders, "access_token=FOO");
      }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("foo");
    resource.setAccessTokenUri("http://localhost/oauth/token");
    setUpRestTemplate();
    assertEquals(token, provider.obtainAccessToken(resource, request));
  }
View Full Code Here

      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        return new StubClientHttpRequest(HttpStatus.BAD_REQUEST, responseHeaders,
            "error=invalid_client&error_description=FOO");
      }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("foo");
    resource.setAccessTokenUri("http://localhost/oauth/token");
    expected.expect(OAuth2AccessDeniedException.class);
    expected.expect(hasCause(instanceOf(InvalidClientException.class)));
    setUpRestTemplate();
    provider.obtainAccessToken(resource, request);
View Full Code Here

  private ImplicitResourceDetails resource = new ImplicitResourceDetails();

  @Test(expected = IllegalStateException.class)
  public void testRedirectNotSpecified() throws Exception {
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    provider.obtainAccessToken(resource, request);
  }
View Full Code Here

    provider.obtainAccessToken(resource, request);
  }

  @Test
  public void testGetAccessTokenRequest() throws Exception {
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    resource.setClientId("foo");
    resource.setAccessTokenUri("http://localhost/oauth/authorize");
    resource.setPreEstablishedRedirectUri("http://anywhere.com");
    assertEquals("FOO", provider.obtainAccessToken(resource, request).getValue());
    assertEquals("foo", params.getFirst("client_id"));
View Full Code Here

  }

  @Test
  public void tokenSavedOnLogin() throws MojoExecutionException, IOException, URISyntaxException {
    DefaultOAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken("refreshtoken");
    DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken("accesstoken");
    accessToken.setRefreshToken(refreshToken);
    when(client.login()).thenReturn(accessToken);

    HashMap<String, Object> info = new HashMap<String, Object>(1);
    info.put("version", "2");
    when(client.getCloudInfo()).thenReturn(new CloudInfo(info));
View Full Code Here

  private Authentication createAuthentication(JsonObject token) {
    return new PreAuthenticatedAuthenticationToken(token.get("sub").getAsString(), token, introspectionAuthorityGranter.getAuthorities(token));
  }

  private OAuth2AccessToken createAccessToken(final JsonObject token, final String tokenString) {
    OAuth2AccessToken accessToken = new OAuth2AccessTokenImpl(token, tokenString);
    return accessToken;
  }
View Full Code Here

        return false;
      }
      // create an OAuth2Authentication
      OAuth2Authentication auth = new OAuth2Authentication(createStoredRequest(tokenResponse), createAuthentication(tokenResponse));
      // create an OAuth2AccessToken
      OAuth2AccessToken token = createAccessToken(tokenResponse, accessToken);

      if (token.getExpiration().after(new Date())) {
        // Store them in the cache
        authCache.put(accessToken, new TokenCacheObject(token, auth));

        return true;
      }
View Full Code Here

//    String userJson = getRestTemplate().getForObject(getUrl("/v2/users/{guid}"), String.class, user);
//    Map<String, Object> userInfo = (Map<String, Object>) JsonUtil.convertJsonToMap(userJson);
//    return userInfo();
    //TODO: remove this temporary hack once the /v2/users/ uri can be accessed by mere mortals
    String userJson = "{}";
    OAuth2AccessToken accessToken = oauthClient.getToken();
    if (accessToken != null) {
      String tokenString = accessToken.getValue();
      int x = tokenString.indexOf('.');
      int y = tokenString.indexOf('.', x + 1);
      String encodedString = tokenString.substring(x + 1, y);
      try {
        byte[] decodedBytes = new sun.misc.BASE64Decoder().decodeBuffer(encodedString);
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.client.token.AccessTokenRequest

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.