org.springframework.security.oauth2.client
Class OAuth2RestTemplate

java.lang.Object
  extended by org.springframework.http.client.support.HttpAccessor
      extended by org.springframework.http.client.support.InterceptingHttpAccessor
          extended by org.springframework.web.client.RestTemplate
              extended by org.springframework.security.oauth2.client.OAuth2RestTemplate
All Implemented Interfaces:
OAuth2RestOperations, org.springframework.web.client.RestOperations

public class OAuth2RestTemplate
extends org.springframework.web.client.RestTemplate
implements OAuth2RestOperations

Rest template that is able to make OAuth2-authenticated REST requests with the credentials of the provided resource.

Author:
Ryan Heaton, Dave Syer

Field Summary
 
Fields inherited from class org.springframework.http.client.support.HttpAccessor
logger
 
Constructor Summary
OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource)
           
OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext context)
           
 
Method Summary
protected  OAuth2AccessToken acquireAccessToken(OAuth2ClientContext oauth2Context)
           
protected  URI appendQueryParameter(URI uri, OAuth2AccessToken accessToken)
           
protected  org.springframework.http.client.ClientHttpRequest createRequest(URI uri, org.springframework.http.HttpMethod method)
           
protected
<T> T
doExecute(URI url, org.springframework.http.HttpMethod method, org.springframework.web.client.RequestCallback requestCallback, org.springframework.web.client.ResponseExtractor<T> responseExtractor)
           
 OAuth2AccessToken getAccessToken()
          Acquire or renew an access token for the current context if necessary.
 OAuth2ClientContext getOAuth2ClientContext()
           
 void setAccessTokenProvider(AccessTokenProvider accessTokenProvider)
           
 void setErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
           
 void setRetryBadAccessTokens(boolean retryBadAccessTokens)
          Flag to determine whether a request that has an existing access token, and which then leads to an AccessTokenRequiredException should be retried (immediately, once).
 
Methods inherited from class org.springframework.web.client.RestTemplate
delete, delete, delete, exchange, exchange, exchange, execute, execute, execute, getErrorHandler, getForEntity, getForEntity, getForEntity, getForObject, getForObject, getForObject, getMessageConverters, headForHeaders, headForHeaders, headForHeaders, optionsForAllow, optionsForAllow, optionsForAllow, postForEntity, postForEntity, postForEntity, postForLocation, postForLocation, postForLocation, postForObject, postForObject, postForObject, put, put, put, setMessageConverters
 
Methods inherited from class org.springframework.http.client.support.InterceptingHttpAccessor
getInterceptors, getRequestFactory, setInterceptors
 
Methods inherited from class org.springframework.http.client.support.HttpAccessor
setRequestFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.web.client.RestOperations
delete, delete, delete, exchange, exchange, exchange, execute, execute, execute, getForEntity, getForEntity, getForEntity, getForObject, getForObject, getForObject, headForHeaders, headForHeaders, headForHeaders, optionsForAllow, optionsForAllow, optionsForAllow, postForEntity, postForEntity, postForEntity, postForLocation, postForLocation, postForLocation, postForObject, postForObject, postForObject, put, put, put
 

Constructor Detail

OAuth2RestTemplate

public OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource)

OAuth2RestTemplate

public OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource,
                          OAuth2ClientContext context)
Method Detail

setRetryBadAccessTokens

public void setRetryBadAccessTokens(boolean retryBadAccessTokens)
Flag to determine whether a request that has an existing access token, and which then leads to an AccessTokenRequiredException should be retried (immediately, once). Useful if the remote server doesn't recognize an old token which is stored in the client, but is happy to re-grant it.

Parameters:
retryBadAccessTokens - the flag to set (default true)

setErrorHandler

public void setErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
Overrides:
setErrorHandler in class org.springframework.web.client.RestTemplate

createRequest

protected org.springframework.http.client.ClientHttpRequest createRequest(URI uri,
                                                                          org.springframework.http.HttpMethod method)
                                                                   throws IOException
Overrides:
createRequest in class org.springframework.http.client.support.HttpAccessor
Throws:
IOException

doExecute

protected <T> T doExecute(URI url,
                          org.springframework.http.HttpMethod method,
                          org.springframework.web.client.RequestCallback requestCallback,
                          org.springframework.web.client.ResponseExtractor<T> responseExtractor)
               throws org.springframework.web.client.RestClientException
Overrides:
doExecute in class org.springframework.web.client.RestTemplate
Throws:
org.springframework.web.client.RestClientException

getAccessToken

public OAuth2AccessToken getAccessToken()
                                 throws UserRedirectRequiredException
Acquire or renew an access token for the current context if necessary. This method will be called automatically when a request is executed (and the result is cached), but can also be called as a standalone method to pre-populate the token.

Specified by:
getAccessToken in interface OAuth2RestOperations
Returns:
an access token
Throws:
UserRedirectRequiredException

getOAuth2ClientContext

public OAuth2ClientContext getOAuth2ClientContext()
Specified by:
getOAuth2ClientContext in interface OAuth2RestOperations
Returns:
the context for this template

acquireAccessToken

protected OAuth2AccessToken acquireAccessToken(OAuth2ClientContext oauth2Context)
                                        throws UserRedirectRequiredException
Throws:
UserRedirectRequiredException

appendQueryParameter

protected URI appendQueryParameter(URI uri,
                                   OAuth2AccessToken accessToken)

setAccessTokenProvider

public void setAccessTokenProvider(AccessTokenProvider accessTokenProvider)


Copyright © 2012. All Rights Reserved.