protected ResourceOwnerPasswordAccessTokenProvider createResourceOwnerPasswordAccessTokenProvider() { ResourceOwnerPasswordAccessTokenProvider resourceOwnerPasswordAccessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider(); resourceOwnerPasswordAccessTokenProvider.setRequestFactory( restTemplate.getRequestFactory()); // copy the http proxy along return resourceOwnerPasswordAccessTokenProvider; }
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); }
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; } }