public class GoogleAuthTokenFactory extends 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.OAuth2Token
Encapsulates the OAuth 2.0 information used by 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 String |
GOOGLE_ACCOUNTS_PATH
The path name of the Google accounts management handler.
|
static String |
GOOGLE_LOGIN_PATH
The path name of the Google login handler.
|
| Constructor and Description |
|---|
GoogleAuthTokenFactory(String serviceName,
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(String serviceName,
String applicationName,
String protocol,
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.
|
String |
getAuthToken(String username,
String password,
String captchaToken,
String captchaAnswer,
String serviceName,
String applicationName)
Retrieves the authentication token for the provided set of credentials for
either a Google or a hosted domain.
|
String |
getAuthToken(String username,
String password,
String captchaToken,
String captchaAnswer,
String serviceName,
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 String |
makePostRequest(URL url,
Map<String,String> parameters)
Makes a HTTP POST request to the provided
url given the
provided parameters. |
void |
setAuthSubToken(String token)
Sets the AuthSub token to be used to authenticate a user.
|
void |
setAuthSubToken(String token,
PrivateKey key)
Sets the AuthSub token to be used to authenticate a user.
|
void |
setAuthToken(HttpAuthToken authToken)
Set the authentication token.
|
void |
setOAuth2Credentials(com.google.api.client.auth.oauth2.Credential credential)
Sets the OAuth 2.0 credentials used to generate the authorization header.
|
void |
setOAuthCredentials(OAuthParameters parameters,
OAuthSigner signer)
Sets the OAuth credentials used to generate the authorization header.
|
void |
setUserCredentials(String username,
String password)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserCredentials(String username,
String password,
ClientLoginAccountType accountType)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserCredentials(String username,
String password,
String captchaToken,
String captchaAnswer)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserCredentials(String username,
String password,
String captchaToken,
String captchaAnswer,
ClientLoginAccountType accountType)
Sets the credentials of the user to authenticate requests to the server.
|
void |
setUserToken(String token)
Sets the AuthToken that should be used to authenticate requests to the
server.
|
public static final String GOOGLE_ACCOUNTS_PATH
public static final String GOOGLE_LOGIN_PATH
public GoogleAuthTokenFactory(String serviceName, 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(String serviceName, String applicationName, String protocol, 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(String username, 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(String username, 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(String username, String password, String captchaToken, 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(String username, String password, String captchaToken, 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(String token)
token - the AuthToken in ascii formpublic void setAuthSubToken(String token)
token - the AuthSub token retrieved from Googlepublic void setAuthSubToken(String token, 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 generate the headersigner - the signing method to use for signing the headerOAuthExceptionpublic void setOAuth2Credentials(com.google.api.client.auth.oauth2.Credential credential)
credential - the OAuth 2.0 credentials to use to generate the headerpublic void setAuthToken(HttpAuthToken authToken)
authToken - authentication tokenpublic HttpAuthToken getAuthToken()
AuthTokenFactorygetAuthToken in interface AuthTokenFactorypublic String getAuthToken(String username, String password, String captchaToken, String captchaAnswer, String serviceName, 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 String getAuthToken(String username, String password, String captchaToken, String captchaAnswer, String serviceName, 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 String makePostRequest(URL url, Map<String,String> parameters) throws 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 handlerIOException - if an I/O exception occurs while creating, writing,
or reading the requestpublic void handleSessionExpiredException(GoogleService.SessionExpiredException sessionExpired) throws GoogleService.SessionExpiredException, AuthenticationException
AuthTokenFactoryhandleSessionExpiredException in interface AuthTokenFactoryGoogleService.SessionExpiredExceptionAuthenticationExceptionCopyright © 2012. All Rights Reserved.