public class CoreOAuthConsumerSupport extends Object implements OAuthConsumerSupport, InitializingBean
URLConnection
to interface with the
OAuth provider. A proxy will be selected, but it is assumed that the TrustManager
s
and other connection-related environment variables are already set up.Modifier and Type | Class and Description |
---|---|
static class |
CoreOAuthConsumerSupport.QueryParameterValue
Marker class for an oauth parameter value that is a query parameter and should therefore not be included in the authorization header.
|
Constructor and Description |
---|
CoreOAuthConsumerSupport() |
CoreOAuthConsumerSupport(OAuthURLStreamHandlerFactory streamHandlerFactory) |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected URL |
configureURLForProtectedAccess(URL url,
OAuthConsumerToken requestToken,
ProtectedResourceDetails details,
String httpMethod,
Map<String,String> additionalParameters)
Internal use of configuring the URL for protected access, the resource details already having been loaded.
|
URL |
configureURLForProtectedAccess(URL url,
OAuthConsumerToken accessToken,
String httpMethod,
Map<String,String> additionalParameters)
Create a configured URL.
|
protected String |
findValidHeaderValue(Set<CharSequence> paramValues)
Finds a valid header value that is valid for the OAuth header.
|
OAuthConsumerToken |
getAccessToken(OAuthConsumerToken requestToken,
String verifier)
Get an access token for a protected resource.
|
OAuthConsumerToken |
getAccessToken(ProtectedResourceDetails details,
OAuthConsumerToken requestToken,
String verifier)
Get an access token for a protected resource.
|
String |
getAuthorizationHeader(ProtectedResourceDetails details,
OAuthConsumerToken accessToken,
URL url,
String httpMethod,
Map<String,String> additionalParameters)
Get the authorization header using the given access token that should be applied to the specified URL.
|
int |
getConnectionTimeout()
The connection timeout (default 60 seconds).
|
NonceFactory |
getNonceFactory()
The nonce factory.
|
String |
getOAuthQueryString(ProtectedResourceDetails details,
OAuthConsumerToken accessToken,
URL url,
String httpMethod,
Map<String,String> additionalParameters)
Get the query string that is to be used in the given request.
|
ProtectedResourceDetailsService |
getProtectedResourceDetailsService()
The protected resource details service.
|
ProxySelector |
getProxySelector()
The proxy selector to use.
|
int |
getReadTimeout()
The read timeout (default 60 seconds).
|
protected String |
getSignatureBaseString(Map<String,Set<CharSequence>> oauthParams,
URL requestURL,
String httpMethod)
Get the signature base string for the specified parameters.
|
OAuthSignatureMethodFactory |
getSignatureFactory()
The signature factory to use.
|
OAuthURLStreamHandlerFactory |
getStreamHandlerFactory()
The URL stream handler factory for connections to an OAuth resource.
|
protected OAuthConsumerToken |
getTokenFromProvider(ProtectedResourceDetails details,
URL tokenURL,
String httpMethod,
OAuthConsumerToken requestToken,
Map<String,String> additionalParameters)
Get the consumer token with the given parameters and URL.
|
OAuthConsumerToken |
getUnauthorizedRequestToken(ProtectedResourceDetails details,
String callback)
Get an unauthorized request token for a protected resource.
|
OAuthConsumerToken |
getUnauthorizedRequestToken(String resourceId,
String callback)
Get an unauthorized request token for a protected resource.
|
protected Map<String,Set<CharSequence>> |
loadOAuthParameters(ProtectedResourceDetails details,
URL requestURL,
OAuthConsumerToken requestToken,
String httpMethod,
Map<String,String> additionalParameters)
Loads the OAuth parameters for the given resource at the given URL and the given token.
|
protected HttpURLConnection |
openConnection(URL requestTokenURL)
Open a connection to the given URL.
|
InputStream |
readProtectedResource(URL url,
OAuthConsumerToken accessToken,
String httpMethod)
Read a protected resource from the given URL using the specified access token and HTTP method.
|
protected InputStream |
readResource(ProtectedResourceDetails details,
URL url,
String httpMethod,
OAuthConsumerToken token,
Map<String,String> additionalParameters,
Map<String,String> additionalRequestHeaders)
Read a resource.
|
protected Proxy |
selectProxy(URL requestTokenURL)
Selects a proxy for the given URL.
|
void |
setConnectionTimeout(int connectionTimeout)
The connection timeout.
|
void |
setNonceFactory(NonceFactory nonceFactory)
The nonce factory.
|
void |
setProtectedResourceDetailsService(ProtectedResourceDetailsService protectedResourceDetailsService)
The protected resource details service.
|
void |
setProxySelector(ProxySelector proxySelector)
The proxy selector to use.
|
void |
setReadTimeout(int readTimeout)
The read timeout.
|
void |
setSignatureFactory(OAuthSignatureMethodFactory signatureFactory)
The signature factory to use.
|
void |
setStreamHandlerFactory(OAuthURLStreamHandlerFactory streamHandlerFactory)
The URL stream handler factory for connections to an OAuth resource.
|
protected String |
urlDecode(String token)
URL-decode a token.
|
protected String |
urlEncode(String value)
URL-encode a value.
|
public CoreOAuthConsumerSupport()
public CoreOAuthConsumerSupport(OAuthURLStreamHandlerFactory streamHandlerFactory)
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
public OAuthConsumerToken getUnauthorizedRequestToken(String resourceId, String callback) throws OAuthRequestFailedException
OAuthConsumerSupport
getUnauthorizedRequestToken
in interface OAuthConsumerSupport
resourceId
- The id of the protected resource for which to get a consumer token.callback
- The callback URL.OAuthRequestFailedException
public OAuthConsumerToken getUnauthorizedRequestToken(ProtectedResourceDetails details, String callback) throws OAuthRequestFailedException
OAuthConsumerSupport
getUnauthorizedRequestToken
in interface OAuthConsumerSupport
details
- The protected resource for which to get a consumer token.callback
- The callback URL.OAuthRequestFailedException
public OAuthConsumerToken getAccessToken(OAuthConsumerToken requestToken, String verifier) throws OAuthRequestFailedException
OAuthConsumerSupport
getAccessToken
in interface OAuthConsumerSupport
requestToken
- The (presumably authorized) request token.verifier
- The token verifier.OAuthRequestFailedException
public OAuthConsumerToken getAccessToken(ProtectedResourceDetails details, OAuthConsumerToken requestToken, String verifier)
OAuthConsumerSupport
getAccessToken
in interface OAuthConsumerSupport
details
- The resource for which to get the access token.requestToken
- The (presumably authorized) request token.verifier
- The token verifier.public InputStream readProtectedResource(URL url, OAuthConsumerToken accessToken, String httpMethod) throws OAuthRequestFailedException
OAuthConsumerSupport
readProtectedResource
in interface OAuthConsumerSupport
url
- The URL.accessToken
- The access token.httpMethod
- The HTTP method.OAuthRequestFailedException
protected InputStream readResource(ProtectedResourceDetails details, URL url, String httpMethod, OAuthConsumerToken token, Map<String,String> additionalParameters, Map<String,String> additionalRequestHeaders)
details
- The details of the resource.url
- The URL of the resource.httpMethod
- The http method.token
- The token.additionalParameters
- Any additional request parameters.additionalRequestHeaders
- Any additional request parameters.public URL configureURLForProtectedAccess(URL url, OAuthConsumerToken accessToken, String httpMethod, Map<String,String> additionalParameters) throws OAuthRequestFailedException
configureURLForProtectedAccess
in interface OAuthConsumerSupport
url
- The base URL.accessToken
- The access token.httpMethod
- The HTTP method.additionalParameters
- Any additional request parameters.OAuthRequestFailedException
protected URL configureURLForProtectedAccess(URL url, OAuthConsumerToken requestToken, ProtectedResourceDetails details, String httpMethod, Map<String,String> additionalParameters)
url
- The URL.requestToken
- The request token.details
- The details.httpMethod
- The http method.additionalParameters
- Any additional request parameters.public String getAuthorizationHeader(ProtectedResourceDetails details, OAuthConsumerToken accessToken, URL url, String httpMethod, Map<String,String> additionalParameters)
OAuthConsumerSupport
getAuthorizationHeader
in interface OAuthConsumerSupport
details
- The details of the protected resource.accessToken
- The access token.url
- The URL of the request.httpMethod
- The http method for the protected resource.additionalParameters
- Any additional request parameters.protected String findValidHeaderValue(Set<CharSequence> paramValues)
paramValues
- The possible values for the oauth header.public String getOAuthQueryString(ProtectedResourceDetails details, OAuthConsumerToken accessToken, URL url, String httpMethod, Map<String,String> additionalParameters)
OAuthConsumerSupport
getOAuthQueryString
in interface OAuthConsumerSupport
details
- The resource details.accessToken
- The access token.url
- The URLhttpMethod
- The http method.additionalParameters
- Any additional OAuth request parameters.protected OAuthConsumerToken getTokenFromProvider(ProtectedResourceDetails details, URL tokenURL, String httpMethod, OAuthConsumerToken requestToken, Map<String,String> additionalParameters)
details
- The resource details.tokenURL
- The token URL.httpMethod
- The http method.requestToken
- The request token, or null if none.additionalParameters
- The additional request parameter.protected Map<String,Set<CharSequence>> loadOAuthParameters(ProtectedResourceDetails details, URL requestURL, OAuthConsumerToken requestToken, String httpMethod, Map<String,String> additionalParameters)
details
- The resource details.requestURL
- The request URL.requestToken
- The request token.httpMethod
- The http method.additionalParameters
- Additional oauth parameters (outside of the core oauth spec).protected String urlEncode(String value)
value
- The value to encode.protected String urlDecode(String token)
token
- The token to URL-decode.protected HttpURLConnection openConnection(URL requestTokenURL)
requestTokenURL
- The request token URL.protected Proxy selectProxy(URL requestTokenURL)
requestTokenURL
- The URLprotected String getSignatureBaseString(Map<String,Set<CharSequence>> oauthParams, URL requestURL, String httpMethod)
oauthParams
- The parameters (NOT oauth-encoded).requestURL
- The request URL.httpMethod
- The http method.public ProtectedResourceDetailsService getProtectedResourceDetailsService()
@Autowired public void setProtectedResourceDetailsService(ProtectedResourceDetailsService protectedResourceDetailsService)
protectedResourceDetailsService
- The protected resource details service.public OAuthURLStreamHandlerFactory getStreamHandlerFactory()
@Autowired(required=false) public void setStreamHandlerFactory(OAuthURLStreamHandlerFactory streamHandlerFactory)
streamHandlerFactory
- The URL stream handler factory for connections to an OAuth resource.public NonceFactory getNonceFactory()
@Autowired(required=false) public void setNonceFactory(NonceFactory nonceFactory)
nonceFactory
- The nonce factory.public OAuthSignatureMethodFactory getSignatureFactory()
@Autowired(required=false) public void setSignatureFactory(OAuthSignatureMethodFactory signatureFactory)
signatureFactory
- The signature factory to use.public ProxySelector getProxySelector()
@Autowired(required=false) public void setProxySelector(ProxySelector proxySelector)
proxySelector
- The proxy selector to use.public int getConnectionTimeout()
public void setConnectionTimeout(int connectionTimeout)
connectionTimeout
- The connection timeout.public int getReadTimeout()
public void setReadTimeout(int readTimeout)
readTimeout
- The read timeout.Copyright © 2019. All rights reserved.