Package org.springframework.security.oauth2.common

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


        return client;
      }
    });
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    assertNull(token.getRefreshToken());
  }
View Full Code Here


  }

  private static class StubAccessTokenProvider implements AccessTokenProvider {
    public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details, AccessTokenRequest parameters)
        throws UserRedirectRequiredException, AccessDeniedException {
      return new DefaultOAuth2AccessToken("FOO");
    }
View Full Code Here

  public void testTokenEnhancerUpdatesStoredTokens() throws Exception {
    final ExpiringOAuth2RefreshToken refreshToken = new DefaultExpiringOAuth2RefreshToken("testToken", new Date(
        System.currentTimeMillis() + 100000));
    getTokenServices().setTokenEnhancer(new TokenEnhancer() {
      public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
        result.setRefreshToken(refreshToken);
        return result;
      }
    });
    OAuth2Authentication authentication = createAuthentication();
    OAuth2AccessToken original = getTokenServices().createAccessToken(authentication);
    assertTrue(original.getRefreshToken().equals(refreshToken));
    OAuth2AccessToken result = getTokenStore().getAccessToken(authentication);
    assertEquals(original, result);
    assertEquals(refreshToken, result.getRefreshToken());
    assertEquals(refreshToken, getTokenStore().readRefreshToken(refreshToken.getValue()));
  }
View Full Code Here

  @Test
  public void testRefreshedTokenIsEnhanced() throws Exception {
    getTokenServices().setTokenEnhancer(new TokenEnhancer() {
      public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
        result.setValue("I'mEnhanced");
        return result;
      }
    });

    OAuth2AccessToken accessToken = getTokenServices().createAccessToken(createAuthentication());
View Full Code Here

  @Test
  public void testAuthentication() throws Exception {
    filter.setRestTemplate(restTemplate);
    filter.setTokenServices(tokenServices);
    Mockito.when(restTemplate.getAccessToken()).thenReturn(new DefaultOAuth2AccessToken("FOO"));
    Set<String> scopes = new HashSet<String>();
    scopes.addAll(Arrays.asList("read", "write"));
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("client", false, scopes);
    this.authentication = new OAuth2Authentication(storedOAuth2Request, null);
    Mockito.when(tokenServices.loadAuthentication("FOO")).thenReturn(authentication);
View Full Code Here

  private OAuth2Authentication authentication;

  @Before
  public void init() {
    token = new DefaultOAuth2AccessToken("FOO");
    ClientDetails client = new BaseClientDetails("client", null, "read", "client_credentials", "ROLE_CLIENT");
    authentication = new OAuth2Authentication(
        new TokenRequest(null, "client", null, "client_credentials").createOAuth2Request(client), null);
    tokenStore.clear();
  }
View Full Code Here

  }

  private Collection<OAuth2AccessToken> enhance(Collection<OAuth2AccessToken> tokens) {
    Collection<OAuth2AccessToken> result = new ArrayList<OAuth2AccessToken>();
    for (OAuth2AccessToken prototype : tokens) {
      DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(prototype);
      OAuth2Authentication authentication = tokenStore.readAuthentication(token);
      if (authentication == null) {
        continue;
      }
      String clientId = authentication.getOAuth2Request().getClientId();
      if (clientId != null) {
        Map<String, Object> map = new HashMap<String, Object>(token.getAdditionalInformation());
        map.put("client_id", clientId);
        token.setAdditionalInformation(map);
        result.add(token);
      }
    }
    return result;
  }
View Full Code Here

  public void testGetAccessTokenWithNoClientId() {

    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put(OAuth2Utils.GRANT_TYPE, "authorization_code");

    OAuth2AccessToken expectedToken = new DefaultOAuth2AccessToken("FOO");
    when(tokenGranter.grant(Mockito.eq("authorization_code"), Mockito.any(TokenRequest.class))).thenReturn(
        expectedToken);
    @SuppressWarnings("unchecked")
    Map<String, String> anyMap = Mockito.any(Map.class);
    when(authorizationRequestFactory.createTokenRequest(anyMap, Mockito.any(ClientDetails.class))).thenReturn(
View Full Code Here

    parameters.put("client_id", clientId);
    parameters.put("scope", "read");
    parameters.put("grant_type", "authorization_code");
    parameters.put("code", "kJAHDFG");

    OAuth2AccessToken expectedToken = new DefaultOAuth2AccessToken("FOO");
    ArgumentCaptor<TokenRequest> captor = ArgumentCaptor.forClass(TokenRequest.class);

    when(tokenGranter.grant(Mockito.eq("authorization_code"), captor.capture())).thenReturn(expectedToken);
    @SuppressWarnings("unchecked")
    Map<String, String> anyMap = Mockito.any(Map.class);
View Full Code Here

  @Test
  public void testImplicitPreApproved() throws Exception {
    endpoint.setTokenGranter(new TokenGranter() {

      public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
        DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
        token.setAdditionalInformation(Collections.singletonMap("foo", (Object) "bar"));
        return token;

      }
    });
    endpoint.setUserApprovalHandler(new DefaultUserApprovalHandler() {
View Full Code Here

TOP

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

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.