public class AuthSubUtil extends Object
| Constructor and Description |
|---|
AuthSubUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
exchangeForSessionToken(String onetimeUseToken,
PrivateKey key)
Exchanges the one time use token returned in the URL for a session
token.
|
static String |
exchangeForSessionToken(String protocol,
String domain,
String onetimeUseToken,
PrivateKey key)
Exchanges the one time use token returned in the URL for a session
token.
|
static String |
formAuthorizationHeader(String token,
PrivateKey key,
URL requestUrl,
String requestMethod)
Forms the AuthSub authorization header.
|
static PrivateKey |
getPrivateKeyFromKeystore(String keystore,
String keystorePass,
String keyAlias,
String keyPass)
Retrieves the private key from the specified keystore.
|
static String |
getRequestUrl(String nextUrl,
String scope,
boolean secure,
boolean session)
Creates the request URL to be used to retrieve an AuthSub token.
|
static String |
getRequestUrl(String hostedDomain,
String nextUrl,
String scope,
boolean secure,
boolean session)
Creates the request URL to be used to retrieve an AuthSub token for
hosted applications.
|
static String |
getRequestUrl(String protocol,
String domain,
String nextUrl,
String scope,
boolean secure,
boolean session)
Creates the request URL to be used to retrieve an AuthSub token.
|
static String |
getRequestUrl(String protocol,
String domain,
String hostedDomain,
String nextUrl,
String scope,
boolean secure,
boolean session)
Creates the request URL for to be used to retrieve an AuthSub token for
hosted applications.
|
static String |
getTokenFromReply(String queryString)
Parses and returns the AuthSub token returned by Google on a successful
AuthSub login request.
|
static String |
getTokenFromReply(URL url)
Parses and returns the AuthSub token returned by Google on a successful
AuthSub login request.
|
static Map<String,String> |
getTokenInfo(String token,
PrivateKey key)
Retrieves information about the AuthSub token.
|
static Map<String,String> |
getTokenInfo(String protocol,
String domain,
String token,
PrivateKey key)
Retrieves information about the AuthSub token.
|
static void |
revokeToken(String token,
PrivateKey key)
Revokes the specified token.
|
static void |
revokeToken(String protocol,
String domain,
String token,
PrivateKey key)
Revokes the specified token.
|
public static String getRequestUrl(String nextUrl, String scope, boolean secure, boolean session)
On success, the user will be redirected to the next URL with the
AuthSub token appended to the URL. Use getTokenFromReply(String)
to retrieve the token from the reply.
nextUrl - the URL to redirect to on successful token retrievalscope - the scope of the requested AuthSub tokensecure - true if the token will be used securelysession - true if the token will be exchanged for a
session cookiepublic static String getRequestUrl(String protocol, String domain, String nextUrl, String scope, boolean secure, boolean session)
On success, the user will be redirected to the next URL with the
AuthSub token appended to the URL. Use getTokenFromReply(String)
to retrieve the token from the reply.
protocol - the protocol to use to communicate with the serverdomain - the domain at which the authentication server existsnextUrl - the URL to redirect to on successful token retrievalscope - the scope of the requested AuthSub tokensecure - true if the token will be used securelysession - true if the token will be exchanged for a
session cookiepublic static String getRequestUrl(String hostedDomain, String nextUrl, String scope, boolean secure, boolean session)
On success, the user will be redirected to the next URL with the
AuthSub token appended to the URL. Use getTokenFromReply(String)
to retrieve the token from the reply.
hostedDomain - hosted domain name, for example
mydomain.example.comnextUrl - the URL to redirect to on successful token retrievalscope - the scope of the requested AuthSub tokensecure - true if the token will be used securelysession - true if the token will be exchanged for a
session cookiepublic static String getRequestUrl(String protocol, String domain, String hostedDomain, String nextUrl, String scope, boolean secure, boolean session)
On success, the user will be redirected to the next URL with the
AuthSub token appended to the URL. Use getTokenFromReply(String)
to retrieve the token from the reply.
protocol - the protocol to use to communicate with the serverdomain - the domain at which the authentication server existshostedDomain - hosted domain name, for example
mydomain.example.comnextUrl - the URL to redirect to on successful token retrievalscope - the scope of the requested AuthSub tokensecure - true if the token will be used securelysession - true if the token will be exchanged for a
session cookiepublic static String getTokenFromReply(URL url)
url - the redirected-to next URL with the tokenpublic static String getTokenFromReply(String queryString)
queryString - the query portion of the redirected-to URL containing
the token (as the server received it; i.e. what
httpServletRequest.getQueryString() returns)null if there is no
token present in queryString. The token text will have
been run through URLDecoder already, and will not need any
additional decoding before use; however, the token string will
not contain percent (%) characters and therefore
additional url-decoding will do no harm.public static PrivateKey getPrivateKeyFromKeystore(String keystore, String keystorePass, String keyAlias, String keyPass) throws IOException, GeneralSecurityException
keystore - the path to the keystore filekeystorePass - the password that protects the keystore filekeyAlias - the alias under which the private key is storedkeyPass - the password protecting the private keyGeneralSecurityException - if the keystore cannot be loadedIOException - if the file cannot be accessedpublic static String exchangeForSessionToken(String onetimeUseToken, PrivateKey key) throws IOException, GeneralSecurityException, AuthenticationException
If the key is non-null, the token will be used securely
and the request to make the exchange will be signed.
onetimeUseToken - the one time use token sent by Google in the URLkey - the private key to sign the requestnull if the request failedIOException - if error in writing/reading the requestGeneralSecurityException - if error in signing the requestAuthenticationException - if one time use token is rejectedpublic static String exchangeForSessionToken(String protocol, String domain, String onetimeUseToken, PrivateKey key) throws IOException, GeneralSecurityException, AuthenticationException
If the key is non-null, the token will be used securely
and the request to make the exchange will be signed.
protocol - the protocol to use to communicate with the serverdomain - the domain at which the authentication server existsonetimeUseToken - the one time use token sent by Google in the URLkey - the private key to sign the requestnull if the request failedIOException - if error in writing/reading the requestGeneralSecurityException - if error in signing the requestAuthenticationException - if one time use token is rejectedpublic static Map<String,String> getTokenInfo(String token, PrivateKey key) throws IOException, GeneralSecurityException, AuthenticationException
If the key is non-null, the token will be used securely
and the request to revoke the token will be signed.
token - the AuthSub token for which to receive informationkey - the private key to sign the requestIOException - if error in writing/reading the requestGeneralSecurityException - if error in signing the requestAuthenticationException - if the token is rejectedpublic static Map<String,String> getTokenInfo(String protocol, String domain, String token, PrivateKey key) throws IOException, GeneralSecurityException, AuthenticationException
If the key is non-null, the token will be used securely
and the request to revoke the token will be signed.
protocol - the protocol to use to communicate with the serverdomain - the domain at which the authentication server existstoken - the AuthSub token for which to receive informationkey - the private key to sign the requestIOException - if error in writing/reading the requestGeneralSecurityException - if error in signing the requestAuthenticationException - if the token is rejectedpublic static void revokeToken(String token, PrivateKey key) throws IOException, GeneralSecurityException, AuthenticationException
If the key is non-null, the token will be used securely
and the request to revoke the token will be signed.
token - the AuthSub token to revokekey - the private key to sign the requestIOException - if error in writing/reading the requestGeneralSecurityException - if error in signing the requestAuthenticationException - if the token is rejectedpublic static void revokeToken(String protocol, String domain, String token, PrivateKey key) throws IOException, GeneralSecurityException, AuthenticationException
If the key is non-null, the token will be used securely
and the request to revoke the token will be signed.
protocol - the protocol to use to communicate with the serverdomain - the domain at which the authentication server existstoken - the AuthSub token to revokekey - the private key to sign the requestIOException - if error in writing/reading the requestGeneralSecurityException - if error in signing the requestAuthenticationException - if the token is rejectedpublic static String formAuthorizationHeader(String token, PrivateKey key, URL requestUrl, String requestMethod) throws GeneralSecurityException
If the key is null, the token will be used in insecure mode.
If the key is non-null, the token will be used securely and
the header will contain a signature.
token - the AuthSub token to use in the headerkey - the private key used to sign the requestrequestUrl - the URL of the request being issuedrequestMethod - the HTTP method being used to issue the requestGeneralSecurityException - if error occurs while creating signatureCopyright © 2012. All Rights Reserved.