Package org.springframework.security.oauth2.common

Examples of org.springframework.security.oauth2.common.OAuth2AccessToken


   * tests a happy-day flow of the refresh token provider.
   */
  @Test
  public void testHappyDay() throws Exception {

    OAuth2AccessToken accessToken = getAccessToken("read write", "my-trusted-client");

    // now use the refresh token to get a new access token.
    assertNotNull(accessToken.getRefreshToken());
    OAuth2AccessToken newAccessToken = refreshAccessToken(accessToken.getRefreshToken().getValue());
    assertFalse(newAccessToken.getValue().equals(accessToken.getValue()));

    verifyAccessTokens(accessToken, newAccessToken);

  }
View Full Code Here


    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = http.postForMap(tokenPath(), headers, formData);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders()
        .getFirst("Cache-Control").contains("no-store"));
    @SuppressWarnings("unchecked")
    OAuth2AccessToken newAccessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return newAccessToken;

  }
View Full Code Here

    ResponseEntity<Map> response = http.postForMap(tokenPath(), headers, formData);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders()
        .getFirst("Cache-Control").contains("no-store"));

    @SuppressWarnings("unchecked")
    OAuth2AccessToken accessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return accessToken;
  }
View Full Code Here

public class ResourceOwnerPasswordProviderTests extends AbstractResourceOwnerPasswordProviderTests {

  @Test
  @OAuth2ContextConfiguration(ResourceOwner.class)
  public void testCheckToken() throws Exception {
    OAuth2AccessToken token = context.getAccessToken();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = new TestRestTemplate("my-client-with-secret", "secret").exchange(http
        .getUrl(checkTokenPath()), HttpMethod.POST, new HttpEntity<String>("token=" + token.getValue(),
        headers), Map.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> map = (Map<String, Object>) response.getBody();
    assertTrue(map.containsKey(AccessTokenConverter.EXP));
View Full Code Here

   * tests the check_token endpoint
   */
  @Test
  @OAuth2ContextConfiguration(ClientCredentials.class)
  public void testCheckToken() throws Exception {
    OAuth2AccessToken token = context.getAccessToken();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = new TestRestTemplate("my-client-with-secret", "secret").exchange(http
        .getUrl(checkTokenPath()), HttpMethod.POST,
        new HttpEntity<String>("token=" + token.getValue(), headers), Map.class);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> map = (Map<String, Object>) response.getBody();
    assertTrue(map.containsKey(AccessTokenConverter.EXP));
    assertEquals("my-client-with-secret", map.get(AccessTokenConverter.CLIENT_ID));
View Full Code Here

   * tests a happy-day flow of the refresh token provider.
   */
  @Test
  public void testHappyDay() throws Exception {

    OAuth2AccessToken accessToken = getAccessToken("read write", "my-trusted-client");

    // now use the refresh token to get a new access token.
    assertNotNull(accessToken.getRefreshToken());
    OAuth2AccessToken newAccessToken = refreshAccessToken(accessToken.getRefreshToken().getValue());
    assertFalse(newAccessToken.getValue().equals(accessToken.getValue()));

    verifyAccessTokens(accessToken, newAccessToken);

  }
View Full Code Here

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = http.postForMap(tokenPath(), headers, formData);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders()
        .getFirst("Cache-Control").contains("no-store"));
    @SuppressWarnings("unchecked")
    OAuth2AccessToken newAccessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return newAccessToken;

  }
View Full Code Here

    ResponseEntity<Map> response = http.postForMap(tokenPath(), headers, formData);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders()
        .getFirst("Cache-Control").contains("no-store"));

    @SuppressWarnings("unchecked")
    OAuth2AccessToken accessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return accessToken;
  }
View Full Code Here

  }

  @Test
  public void readAccessToken() throws IOException {
    when(inputMessage.getBody()).thenReturn(createInputStream(OAUTH_ACCESSTOKEN));
    OAuth2AccessToken token = converter.read(OAuth2AccessToken.class, inputMessage);
    assertTokenEquals(accessToken,token);
  }
View Full Code Here

  @Test
  public void readAccessTokenNoRefresh() throws IOException {
    accessToken.setRefreshToken(null);
    when(inputMessage.getBody()).thenReturn(createInputStream(OAUTH_ACCESSTOKEN_NOREFRESH));
    OAuth2AccessToken token = converter.read(OAuth2AccessToken.class, inputMessage);
    assertTokenEquals(accessToken,token);
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.common.OAuth2AccessToken

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.