Package org.springframework.security.oauth2.common

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


  }

  @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


  }

  public DefaultOAuth2AccessToken getToken(HashMap<String, String> target) {
    final String token = target.get(ACCESS_TOKEN_KEY);
    final String[] tokens = token.split(" ");
    return new DefaultOAuth2AccessToken(tokens[1]);
  }
View Full Code Here

    if (targetInfo == null) {
      return null;
    }

    DefaultOAuth2RefreshToken refreshToken = targetInfos.getRefreshToken(targetInfo);
    DefaultOAuth2AccessToken token = targetInfos.getToken(targetInfo);
    token.setRefreshToken(refreshToken);

    return token;
  }
View Full Code Here

  @Override
  public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
    OAuth2AccessToken token = super.grant(grantType, tokenRequest);
    if (token != null) {
      DefaultOAuth2AccessToken norefresh = new DefaultOAuth2AccessToken(token);
      // The spec says that client credentials should not be allowed to get a refresh token
      if (!allowRefresh) {
        norefresh.setRefreshToken(null);
      }
      token = norefresh;
    }
    return token;
  }
View Full Code Here

    }
    return jaxbAccessToken;
  }

  protected OAuth2AccessToken convertToExternal(JaxbOAuth2AccessToken jaxbAccessToken) {
    DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(jaxbAccessToken.getAccessToken());
    String refreshToken = jaxbAccessToken.getRefreshToken();
    if(refreshToken != null) {
      accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
    }
    Date expiration = jaxbAccessToken.getExpiration();
    if(expiration != null) {
      accessToken.setExpiration(expiration);
    }
    return accessToken;
  }
View Full Code Here

      // Expected
    }
  }

  public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
    Map<String, Object> info = new LinkedHashMap<String, Object>(accessToken.getAdditionalInformation());
    String tokenId = result.getValue();
    if (!info.containsKey(TOKEN_ID)) {
      info.put(TOKEN_ID, tokenId);
    }
    result.setAdditionalInformation(info);
    result.setValue(encode(result, authentication));
    OAuth2RefreshToken refreshToken = result.getRefreshToken();
    if (refreshToken != null) {
      DefaultOAuth2AccessToken encodedRefreshToken = new DefaultOAuth2AccessToken(accessToken);
      encodedRefreshToken.setValue(refreshToken.getValue());
      Map<String, Object> refreshTokenInfo = new LinkedHashMap<String, Object>(accessToken.getAdditionalInformation());
      refreshTokenInfo.put(TOKEN_ID, encodedRefreshToken.getValue());
      encodedRefreshToken.setAdditionalInformation(refreshTokenInfo);
      DefaultOAuth2RefreshToken token = new DefaultOAuth2RefreshToken(encode(encodedRefreshToken, authentication));
      if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
        Date expiration = ((ExpiringOAuth2RefreshToken) refreshToken).getExpiration();
        encodedRefreshToken.setExpiration(expiration);
        token = new DefaultExpiringOAuth2RefreshToken(encode(encodedRefreshToken, authentication), expiration);
      }
      result.setRefreshToken(token);
    }
    return result;
View Full Code Here

    }
    return response;
  }

  public OAuth2AccessToken extractAccessToken(String value, Map<String, ?> map) {
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(value);
    Map<String, Object> info = new HashMap<String, Object>(map);
    info.remove(EXP);
    info.remove(AUD);
    info.remove(CLIENT_ID);
    info.remove(SCOPE);
    if (map.containsKey(EXP)) {
      token.setExpiration(new Date((Long) map.get(EXP) * 1000L));
    }
    if (map.containsKey(JTI)) {
      info.put(JTI, map.get(JTI));
    }
    @SuppressWarnings("unchecked")
    Collection<String> scope = (Collection<String>) map.get(SCOPE);
    if (scope != null) {
      token.setScope(new HashSet<String>(scope));
    }
    token.setAdditionalInformation(info);
    return token;
  }
View Full Code Here

        new Date(System.currentTimeMillis() + (validitySeconds * 1000L)));
    return refreshToken;
  }

  private OAuth2AccessToken createAccessToken(OAuth2Authentication authentication, OAuth2RefreshToken refreshToken) {
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(UUID.randomUUID().toString());
    int validitySeconds = getAccessTokenValiditySeconds(authentication.getOAuth2Request());
    if (validitySeconds > 0) {
      token.setExpiration(new Date(System.currentTimeMillis() + (validitySeconds * 1000L)));
    }
    token.setRefreshToken(refreshToken);
    token.setScope(authentication.getOAuth2Request().getScope());

    return accessTokenEnhancer != null ? accessTokenEnhancer.enhance(token, authentication) : token;
  }
View Full Code Here

    public CustomTestTokenGranter() {}

    public OAuth2AccessToken grant(String grantType,
        TokenRequest tokenRequest) {
      if (grantType.equals("test-grant")) {
        return new DefaultOAuth2AccessToken("test");
      }
      return null;
    }
View Full Code Here

  private DefaultOAuth2AccessToken accessToken;

  @Before
  public void before() throws Exception {
    converter = new JaxbOAuth2AccessTokenMessageConverter();
    accessToken = new DefaultOAuth2AccessToken("SlAV32hkKG");
    accessToken.setExpiration(expiration);
    accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("8xLOxBtZp8"));
  }
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.