示例#1
0
 protected ResourceOwnerPasswordAccessTokenProvider
     createResourceOwnerPasswordAccessTokenProvider() {
   ResourceOwnerPasswordAccessTokenProvider resourceOwnerPasswordAccessTokenProvider =
       new ResourceOwnerPasswordAccessTokenProvider();
   resourceOwnerPasswordAccessTokenProvider.setRequestFactory(
       restTemplate.getRequestFactory()); // copy the http proxy along
   return resourceOwnerPasswordAccessTokenProvider;
 }
示例#2
0
  public OAuth2AccessToken refreshToken(
      OAuth2AccessToken currentToken, String username, String password, String clientId) {
    OAuth2ProtectedResourceDetails resource = getResourceDetails(username, password, clientId);
    AccessTokenRequest request = createAccessTokenRequest(username, password);

    ResourceOwnerPasswordAccessTokenProvider provider =
        createResourceOwnerPasswordAccessTokenProvider();

    return provider.refreshAccessToken(resource, currentToken.getRefreshToken(), request);
  }
示例#3
0
  public OAuth2AccessToken getToken(String username, String password, String clientId) {
    OAuth2ProtectedResourceDetails resource = getResourceDetails(username, password, clientId);
    AccessTokenRequest request = createAccessTokenRequest(username, password);

    ResourceOwnerPasswordAccessTokenProvider provider =
        createResourceOwnerPasswordAccessTokenProvider();
    try {
      return provider.obtainAccessToken(resource, request);
    } catch (OAuth2AccessDeniedException oauthEx) {
      HttpStatus status = HttpStatus.valueOf(oauthEx.getHttpErrorCode());
      CloudFoundryException cfEx = new CloudFoundryException(status, oauthEx.getMessage());
      cfEx.setDescription(oauthEx.getSummary());
      throw cfEx;
    }
  }