public final class GoogleLogger extends java.lang.Object implements IGoogleLogger
IGoogleLogger
implementation.Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
AUTHORIZATION_ERROR_MESSAGE
Error message displayed when an error occurs during OAuth login.
|
private com.google.api.client.auth.oauth2.AuthorizationCodeFlow |
flow
AuthorizationCodeFlow instance used for managing OAuth login. |
private static java.lang.String |
JOB_NAME
Name used for the job task that wait for the code reception.
|
private static com.google.api.client.json.JsonFactory |
JSON_FACTORY
Default factory used to parse JSON data.
|
private java.util.Collection<java.lang.Runnable> |
listeners
Listeners that are triggered when authorization is completed.
|
private com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver |
receiver
Jetty server uses for token response handling.
|
private java.lang.String |
redirectUri
Redirection URI generated by the code flow.
|
private static java.util.Collection<java.lang.String> |
SCOPES
Scopes of the created session.
|
private static java.lang.String |
SECRET_PATH
Default path of the JSON secret file.
|
private static java.lang.String |
SERVER_STOP_ERROR_MESSAGE
Error message displayed when an error occurs while stoping server.
|
private static java.lang.String |
SERVER_WAIT_ERROR_MESSGAGE
Error message displayed when an error occurs while server is waiting.
|
private java.util.function.Consumer<Session> |
sessionConsumer
Session consumer used when session is created.
|
Modifier | Constructor and Description |
---|---|
private |
GoogleLogger(com.google.api.client.auth.oauth2.AuthorizationCodeFlow.Builder builder,
java.util.function.Consumer<Session> sessionConsumer)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(java.lang.Runnable listener)
Adds the given runnable as a listener that will
be triggered when the authorization process is finished.
|
private void |
authorize(java.lang.String code)
Finalizes OAuth login by executing token
request using the given code.
|
void |
cancel()
Performs a cancel in the authorization process,
which consists in stopping the waiting server.
|
static IGoogleLogger |
createLogger(java.util.function.Consumer<Session> sessionConsumer)
Creates and returns a valid
IGoogleLogger instance. |
private static com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets |
getSecret()
Static tool method that retrieves google client secret
instance from internal JSON file.
|
java.lang.String |
getURL()
Returns a valid authorization URL that can be used for
authorize this application to work with google API.
|
private org.eclipse.core.runtime.IStatus |
waitForCode(org.eclipse.core.runtime.IProgressMonitor monitor)
Functional method that aims to act as an
IJobFunction . |
private static final java.lang.String SECRET_PATH
private static final com.google.api.client.json.JsonFactory JSON_FACTORY
private static final java.util.Collection<java.lang.String> SCOPES
private static final java.lang.String SERVER_STOP_ERROR_MESSAGE
private static final java.lang.String SERVER_WAIT_ERROR_MESSGAGE
private static final java.lang.String AUTHORIZATION_ERROR_MESSAGE
private final com.google.api.client.auth.oauth2.AuthorizationCodeFlow flow
AuthorizationCodeFlow
instance used for managing OAuth login.private final com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver receiver
private final java.util.function.Consumer<Session> sessionConsumer
private final java.util.Collection<java.lang.Runnable> listeners
private java.lang.String redirectUri
private static final java.lang.String JOB_NAME
private GoogleLogger(com.google.api.client.auth.oauth2.AuthorizationCodeFlow.Builder builder, java.util.function.Consumer<Session> sessionConsumer)
builder
- Flow builder used to create flow instance.sessionConsumer
- Session consumer used when session is created.public void addListener(java.lang.Runnable listener)
addListener
in interface IGoogleLogger
listener
- Runnable instance that will be registered as a listener.public void cancel()
cancel
in interface IGoogleLogger
private void authorize(java.lang.String code)
code
- Code to use for retrieving the authorization token.private org.eclipse.core.runtime.IStatus waitForCode(org.eclipse.core.runtime.IProgressMonitor monitor)
IJobFunction
.
This function wait for code to be received and starts token
request once it is done.monitor
- Monitor to use for tracking login progress.Status.OK_STATUS
public java.lang.String getURL() throws java.io.IOException
getURL
in interface IGoogleLogger
java.io.IOException
- If any error occurs while creating URL or starting receiver server.public static IGoogleLogger createLogger(java.util.function.Consumer<Session> sessionConsumer) throws java.security.GeneralSecurityException, java.io.IOException
IGoogleLogger
instance.java.security.GeneralSecurityException
- If any error occurs while creating the HTTP transport.java.io.IOException
- If any error occurs while creating the HTTP transport, or reading the application secret.private static com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets getSecret() throws java.io.IOException
GoogleClientSecrets
instance created.java.io.IOException
- If any error occurs while reading JSON file.