Examples of OAuth2AccessToken


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

  @RequestMapping(value = "/oauth/check_token")
  @ResponseBody
  public Map<String, ?> checkToken(@RequestParam("token") String value) {

    OAuth2AccessToken token = resourceServerTokenServices.readAccessToken(value);
    if (token == null) {
      throw new InvalidTokenException("Token was not recognised");
    }

    if (token.isExpired()) {
      throw new InvalidTokenException("Token has expired");
    }

    OAuth2Authentication authentication = resourceServerTokenServices.loadAuthentication(token.getValue());

    Map<String, ?> response = accessTokenConverter.convertAccessToken(token, authentication);

    return response;
  }
View Full Code Here

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

    this.tokenGranters = new ArrayList<TokenGranter>(tokenGranters);
  }
 
  public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
    for (TokenGranter granter : tokenGranters) {
      OAuth2AccessToken grant = granter.grant(grantType, tokenRequest);
      if (grant!=null) {
        return grant;
      }
    }
    return null;
View Full Code Here

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

   *
   * @see org.springframework.security.oauth2.provider.token.TokenEnhancer#enhance(org.springframework.security.oauth2.common.OAuth2AccessToken,
   * org.springframework.security.oauth2.provider.OAuth2Authentication)
   */
  public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
    OAuth2AccessToken result = accessToken;
    for (TokenEnhancer enhancer : delegates) {
      result = enhancer.enhance(result, authentication);
    }
    return result;
  }
View Full Code Here

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

  // We can grant a token and return it with implicit approval.
  private ModelAndView getImplicitGrantResponse(AuthorizationRequest authorizationRequest) {
    try {
      TokenRequest tokenRequest = getOAuth2RequestFactory().createTokenRequest(authorizationRequest, "implicit");
      OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest);
      OAuth2AccessToken accessToken = getAccessTokenForImplicitGrant(tokenRequest, storedOAuth2Request);
      if (accessToken == null) {
        throw new UnsupportedResponseTypeException("Unsupported response type: token");
      }
      return new ModelAndView(new RedirectView(appendAccessToken(authorizationRequest, accessToken), false, true,
          false));
View Full Code Here

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

    }
  }

  private OAuth2AccessToken getAccessTokenForImplicitGrant(TokenRequest tokenRequest,
      OAuth2Request storedOAuth2Request) {
    OAuth2AccessToken accessToken = null;
    // These 1 method calls have to be atomic, otherwise the ImplicitGrantService can have a race condition where
    // one thread removes the token request before another has a chance to redeem it.
    synchronized (this.implicitLock) {
      accessToken = getTokenGranter().grant("implicit", new ImplicitTokenRequest(tokenRequest, storedOAuth2Request));
    }
View Full Code Here

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

    Assert.notNull(tokenStore, "tokenStore must be set");
  }

  public OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) throws AuthenticationException {

    OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
    OAuth2RefreshToken refreshToken = null;
    if (existingAccessToken != null) {
      if (existingAccessToken.isExpired()) {
        if (existingAccessToken.getRefreshToken() != null) {
          refreshToken = existingAccessToken.getRefreshToken();
          // The token store could remove the refresh token when the
          // access token is removed, but we want to
          // be sure...
          tokenStore.removeRefreshToken(refreshToken);
        }
        tokenStore.removeAccessToken(existingAccessToken);
      }
      else {
        // Re-store the access token in case the authentication has changed
        tokenStore.storeAccessToken(existingAccessToken, authentication);
        return existingAccessToken;
      }
    }

    // Only create a new refresh token if there wasn't an existing one
    // associated with an expired access token.
    // Clients might be holding existing refresh tokens, so we re-use it in
    // the case that the old access token
    // expired.
    if (refreshToken == null) {
      refreshToken = createRefreshToken(authentication);
    }
    // But the refresh token itself might need to be re-issued if it has
    // expired.
    else if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
      ExpiringOAuth2RefreshToken expiring = (ExpiringOAuth2RefreshToken) refreshToken;
      if (System.currentTimeMillis() > expiring.getExpiration().getTime()) {
        refreshToken = createRefreshToken(authentication);
      }
    }

    OAuth2AccessToken accessToken = createAccessToken(authentication, refreshToken);
    tokenStore.storeAccessToken(accessToken, authentication);
    // In case it was modified
    refreshToken = accessToken.getRefreshToken();
    if (refreshToken != null) {
      tokenStore.storeRefreshToken(refreshToken, authentication);
    }
    return accessToken;
View Full Code Here

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

    if (!reuseRefreshToken) {
      tokenStore.removeRefreshToken(refreshToken);
      refreshToken = createRefreshToken(authentication);
    }

    OAuth2AccessToken accessToken = createAccessToken(authentication, refreshToken);
    tokenStore.storeAccessToken(accessToken, authentication);
    if (!reuseRefreshToken) {
      tokenStore.storeRefreshToken(refreshToken, authentication);
    }
    return accessToken;
View Full Code Here

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

  public OAuth2AccessToken readAccessToken(String accessToken) {
    return tokenStore.readAccessToken(accessToken);
  }

  public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException, InvalidTokenException {
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(accessTokenValue);
    if (accessToken == null) {
      throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
    }
    else if (accessToken.isExpired()) {
      tokenStore.removeAccessToken(accessToken);
      throw new InvalidTokenException("Access token expired: " + accessTokenValue);
    }

    OAuth2Authentication result = tokenStore.readAuthentication(accessToken);
View Full Code Here

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

    }
    return clientAuth.getClientId();
  }

  public boolean revokeToken(String tokenValue) {
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
    if (accessToken == null) {
      return false;
    }
    if (accessToken.getRefreshToken() != null) {
      tokenStore.removeRefreshToken(accessToken.getRefreshToken());
    }
    tokenStore.removeAccessToken(accessToken);
    return true;
  }
View Full Code Here

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

*/
public class DefaultOAuth2RequestAuthenticator implements OAuth2RequestAuthenticator {

  @Override
  public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest request) {
    OAuth2AccessToken accessToken = clientContext.getAccessToken();
    String tokenType = accessToken.getTokenType();
    if (!StringUtils.hasText(tokenType)) {
      tokenType = OAuth2AccessToken.BEARER_TYPE; // we'll assume basic bearer token type if none is specified.
    }
    request.getHeaders().set("Authorization", String.format("%s %s", tokenType, accessToken.getValue()));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.