public class GoogleAuthTokenFactory extends java.lang.Object implements AuthTokenFactory
Modifier and Type | Class and Description |
---|---|
static class |
GoogleAuthTokenFactory.AuthSubToken
Encapsulates the token used by web applications to login on behalf of
a user.
|
static class |
GoogleAuthTokenFactory.OAuthToken
Encapsulates the OAuth information used by applications to login on behalf
of a user.
|
static class |
GoogleAuthTokenFactory.UserToken
The UserToken encapsulates the token retrieved as a result of
authenticating to Google using a user's credentials.
|
AuthTokenFactory.AuthToken, AuthTokenFactory.TokenListener
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
GOOGLE_ACCOUNTS_PATH
The path name of the Google accounts management handler.
|
static java.lang.String |
GOOGLE_LOGIN_PATH
The path name of the Google login handler.
|
Constructor and Description |
---|
GoogleAuthTokenFactory(java.lang.String serviceName,
java.lang.String applicationName,
AuthTokenFactory.TokenListener tokenListener)
Constructs a factory for creating authentication tokens for connecting
to a Google service with name
serviceName for an application
with the name applicationName . |
GoogleAuthTokenFactory(java.lang.String serviceName,
java.lang.String applicationName,
java.lang.String protocol,
java.lang.String domainName,
AuthTokenFactory.TokenListener tokenListener)
Constructs a factory for creating authentication tokens for connecting
to a Google service with name
serviceName for an application
with the name applicationName . |
Modifier and Type | Method and Description |
---|---|
HttpAuthToken |
getAuthToken()
Get an authentication token.
|
java.lang.String |
getAuthToken(java.lang.String username,
java.lang.String password,
java.lang.String captchaToken,
java.lang.String captchaAnswer,
java.lang.String serviceName,
java.lang.String applicationName)
Retrieves the authentication token for the provided set of credentials for
either a Google or a hosted domain.
|
java.lang.String |
getAuthToken(java.lang.String username,
java.lang.String password,
java.lang.String captchaToken,
java.lang.String captchaAnswer,
java.lang.String serviceName,
java.lang.String applicationName,
ClientLoginAccountType accountType)
Retrieves the authentication token for the provided set of credentials.
|
void |
handleSessionExpiredException(GoogleService.SessionExpiredException sessionExpired)
Handles a session expired exception.
|
static java.lang.String |
makePostRequest(java.net.URL url,
java.util.Map<java.lang.String,java.lang.String> parameters)
Makes a HTTP POST request to the provided
url given the
provided parameters . |
void |
setAuthSubToken(java.lang.String token)
Sets the AuthSub token to be used to authenticate a user.
|
void |
setAuthSubToken(java.lang.String token,
java.security.PrivateKey key)
Sets the AuthSub token to be used to authenticate a user.
|
void |
setAuthToken(HttpAuthToken authToken)
Set the authentication token.
|
void |
setOAuthCredentials(OAuthParameters parameters,
OAuthSigner signer)
Sets the OAuth credentials used to generate the authorization header.
|
void |
setUserCredentials(java.lang.String username,
java.lang.String password)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserCredentials(java.lang.String username,
java.lang.String password,
ClientLoginAccountType accountType)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserCredentials(java.lang.String username,
java.lang.String password,
java.lang.String captchaToken,
java.lang.String captchaAnswer)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserCredentials(java.lang.String username,
java.lang.String password,
java.lang.String captchaToken,
java.lang.String captchaAnswer,
ClientLoginAccountType accountType)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserToken(java.lang.String token)
Sets the AuthToken that should be used to authenticate requests to the
server.
|
public static final java.lang.String GOOGLE_ACCOUNTS_PATH
public static final java.lang.String GOOGLE_LOGIN_PATH
public GoogleAuthTokenFactory(java.lang.String serviceName, java.lang.String applicationName, AuthTokenFactory.TokenListener tokenListener)
serviceName
for an application
with the name applicationName
. The default domain
(www.google.com) will be used to authenticate.serviceName
- the name of the Google service to which we are
connecting. Sample names of services might include
"cl" (Calendar), "mail" (GMail), or
"blogger" (Blogger)applicationName
- the name of the client application accessing the
service. Application names should preferably have
the format [company-id]-[app-name]-[app-version].
The name will be used by the Google servers to
monitor the source of authentication.tokenListener
- listener for token changespublic GoogleAuthTokenFactory(java.lang.String serviceName, java.lang.String applicationName, java.lang.String protocol, java.lang.String domainName, AuthTokenFactory.TokenListener tokenListener)
serviceName
for an application
with the name applicationName
. The service will authenticate
at the provided domainName
.serviceName
- the name of the Google service to which we are
connecting. Sample names of services might include
"cl" (Calendar), "mail" (GMail), or
"blogger" (Blogger)applicationName
- the name of the client application accessing the
service. Application names should preferably have
the format [company-id]-[app-name]-[app-version].
The name will be used by the Google servers to
monitor the source of authentication.protocol
- name of protocol to use for authentication
("http"/"https")domainName
- the name of the domain hosting the login handlertokenListener
- listener for token changespublic void setUserCredentials(java.lang.String username, java.lang.String password) throws AuthenticationException
username
- the name of the user (an email address)password
- the password of the userAuthenticationException
- if authentication failed.public void setUserCredentials(java.lang.String username, java.lang.String password, ClientLoginAccountType accountType) throws AuthenticationException
username
- the name of the user (an email address)password
- the password of the useraccountType
- the account type: HOSTED, GOOGLE, or HOSTED_OR_GOOGLEAuthenticationException
- if authentication failed.public void setUserCredentials(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer) throws AuthenticationException
username
- the name of the user (an email id)password
- the password of the usercaptchaToken
- the CAPTCHA token issued by the servercaptchaAnswer
- the answer to the respective CAPTCHA tokenAuthenticationException
- if authentication failedpublic void setUserCredentials(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer, ClientLoginAccountType accountType) throws AuthenticationException
username
- the name of the user (an email id)password
- the password of the usercaptchaToken
- the CAPTCHA token issued by the servercaptchaAnswer
- the answer to the respective CAPTCHA tokenaccountType
- the account type: HOSTED, GOOGLE, or HOSTED_OR_GOOGLEAuthenticationException
- if authentication failedpublic void setUserToken(java.lang.String token)
token
- the AuthToken in ascii formpublic void setAuthSubToken(java.lang.String token)
token
- the AuthSub token retrieved from Googlepublic void setAuthSubToken(java.lang.String token, java.security.PrivateKey key)
token
- the AuthSub token retrieved from Googlekey
- the private key to be used to sign all requestspublic void setOAuthCredentials(OAuthParameters parameters, OAuthSigner signer) throws OAuthException
parameters
- the OAuth parameters to use to generated the headersigner
- the signing method to use for signing the headerOAuthException
public void setAuthToken(HttpAuthToken authToken)
authToken
- authentication tokenpublic HttpAuthToken getAuthToken()
AuthTokenFactory
getAuthToken
in interface AuthTokenFactory
public java.lang.String getAuthToken(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer, java.lang.String serviceName, java.lang.String applicationName) throws AuthenticationException
username
- the name of the user (an email address)password
- the password of the usercaptchaToken
- the CAPTCHA token if CAPTCHA is required (Optional)captchaAnswer
- the respective answer of the CAPTCHA token (Optional)serviceName
- the name of the service to which a token is requiredapplicationName
- the application requesting the tokenAuthenticationException
- if authentication failedpublic java.lang.String getAuthToken(java.lang.String username, java.lang.String password, java.lang.String captchaToken, java.lang.String captchaAnswer, java.lang.String serviceName, java.lang.String applicationName, ClientLoginAccountType accountType) throws AuthenticationException
username
- the name of the user (an email address)password
- the password of the usercaptchaToken
- the CAPTCHA token if CAPTCHA is required (Optional)captchaAnswer
- the respective answer of the CAPTCHA token (Optional)serviceName
- the name of the service to which a token is requiredapplicationName
- the application requesting the tokenaccountType
- the account type: HOSTED, GOOGLE, or HOSTED_OR_GOOGLEAuthenticationException
- if authentication failedpublic static java.lang.String makePostRequest(java.net.URL url, java.util.Map<java.lang.String,java.lang.String> parameters) throws java.io.IOException
url
given the
provided parameters
. It returns the output from the POST
handler as a String object.url
- the URL to post the requestparameters
- the parameters to post to the handlerjava.io.IOException
- if an I/O exception occurs while creating, writing,
or reading the requestpublic void handleSessionExpiredException(GoogleService.SessionExpiredException sessionExpired) throws GoogleService.SessionExpiredException, AuthenticationException
AuthTokenFactory
handleSessionExpiredException
in interface AuthTokenFactory
GoogleService.SessionExpiredException
AuthenticationException