Class SalesforceAccessToken
- java.lang.Object
-
- com.adaptris.core.oauth.salesforce.SalesforceAccessToken
-
- All Implemented Interfaces:
ComponentLifecycle
,AccessTokenBuilder
public class SalesforceAccessToken extends java.lang.Object implements AccessTokenBuilder
Wraps the salesforce username/password OAuth authentication flow for machine/machine data flow.Based on the java example available within the salesforce-rest-starter project and relies on the jackson json jars being available on the classpath (built against
com.fasterxml.jackson.core:jackson-databind:2.6.2
) which has been marked as optional in the dependency list to avoid additional jars if you want to just use Apache HTTP.It is perfectly possible to achieve the same thing with standard configuration; it would be a combination of
AddMetadataService
+CreateQueryStringFromMetadata
+ (StandardHttpProducer
||ApacheHttpProducer
) +JsonPathService
+AddFormattedMetadataService
. This encapsulates all of that into a single class.- See Also:
GetOauthToken
,AccessTokenBuilder
In the adapter configuration file this class is aliased as salesforce-access-token which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_TOKEN_URL
The default URL for getting access tokens "https://login.salesforce.com/services/oauth2/token".
-
Constructor Summary
Constructors Constructor Description SalesforceAccessToken()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AccessToken
build(AdaptrisMessage msg)
void
close()
java.lang.String
getConsumerKey()
java.lang.String
getConsumerSecret()
java.lang.String
getHttpProxy()
java.lang.String
getPassword()
java.lang.String
getTokenUrl()
java.lang.String
getUsername()
void
init()
void
setConsumerKey(java.lang.String s)
Set your consumer key.void
setConsumerSecret(java.lang.String s)
Set your consumer secret.void
setHttpProxy(java.lang.String proxy)
Explicitly configure a proxy server.void
setPassword(java.lang.String s)
Set the password.void
setTokenUrl(java.lang.String tokenUrl)
Set the token URL.void
setUsername(java.lang.String s)
Set the username.void
start()
void
stop()
SalesforceAccessToken
withConsumerCredentials(java.lang.String key, java.lang.String secret)
SalesforceAccessToken
withUsernamePassword(java.lang.String user, java.lang.String password)
-
-
-
Field Detail
-
DEFAULT_TOKEN_URL
public static final java.lang.String DEFAULT_TOKEN_URL
The default URL for getting access tokens "https://login.salesforce.com/services/oauth2/token".- See Also:
- Constant Field Values
-
-
Method Detail
-
withUsernamePassword
public SalesforceAccessToken withUsernamePassword(java.lang.String user, java.lang.String password)
-
withConsumerCredentials
public SalesforceAccessToken withConsumerCredentials(java.lang.String key, java.lang.String secret)
-
init
public void init() throws CoreException
- Specified by:
init
in interfaceComponentLifecycle
- Throws:
CoreException
-
start
public void start() throws CoreException
- Specified by:
start
in interfaceComponentLifecycle
- Throws:
CoreException
-
stop
public void stop()
- Specified by:
stop
in interfaceComponentLifecycle
-
close
public void close()
- Specified by:
close
in interfaceComponentLifecycle
-
build
public AccessToken build(AdaptrisMessage msg) throws java.io.IOException, CoreException
- Specified by:
build
in interfaceAccessTokenBuilder
- Throws:
java.io.IOException
CoreException
-
getUsername
public java.lang.String getUsername()
-
setUsername
public void setUsername(java.lang.String s)
Set the username.- Parameters:
s
- the username
-
getPassword
public java.lang.String getPassword()
-
setPassword
public void setPassword(java.lang.String s)
Set the password.Remember the password is really your password + security token
- Parameters:
s
- the password which may be encoded viaPassword.encode(String, String)
-
getConsumerKey
public java.lang.String getConsumerKey()
-
setConsumerKey
public void setConsumerKey(java.lang.String s)
Set your consumer key.- Parameters:
s
- the consumer key
-
getConsumerSecret
public java.lang.String getConsumerSecret()
-
setConsumerSecret
public void setConsumerSecret(java.lang.String s)
Set your consumer secret.- Parameters:
s
- the consumer secret which may be encoded viaPassword.encode(String, String)
-
getHttpProxy
public java.lang.String getHttpProxy()
-
setHttpProxy
public void setHttpProxy(java.lang.String proxy)
Explicitly configure a proxy server.- Parameters:
proxy
- the httpProxy to generallyscheme://host:port
or more simplyhost:port
-
getTokenUrl
public java.lang.String getTokenUrl()
-
setTokenUrl
public void setTokenUrl(java.lang.String tokenUrl)
Set the token URL.- Parameters:
tokenUrl
- the URL, if not specified, defaults to "https://login.salesforce.com/services/oauth2/token"
-
-