Search in sources :

Example 1 with JacksonFactory

use of com.google.api.client.json.jackson.JacksonFactory in project google-cloud-eclipse by GoogleCloudPlatform.

the class ProjectRepositoryTest method testHasAppengineApplication_noApplication.

@Test
public void testHasAppengineApplication_noApplication() throws IOException, ProjectRepositoryException {
    Apps.Get get = initializeGetRequest();
    GoogleJsonResponseException notFoundException = GoogleJsonResponseExceptionFactoryTesting.newMock(new JacksonFactory(), 404, "Not found");
    when(get.execute()).thenThrow(notFoundException);
    assertThat(repository.getAppEngineApplication(mock(Credential.class), "projectId"), is(AppEngine.NO_APPENGINE_APPLICATION));
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Apps(com.google.api.services.appengine.v1.Appengine.Apps) JacksonFactory(com.google.api.client.json.jackson.JacksonFactory) Test(org.junit.Test)

Example 2 with JacksonFactory

use of com.google.api.client.json.jackson.JacksonFactory in project appengine-java-standard by GoogleCloudPlatform.

the class RemoteApiOptions method getCredentialBuilder.

private GoogleCredential.Builder getCredentialBuilder(String serviceAccountId) throws GeneralSecurityException, IOException {
    HttpTransport transport = getOrCreateHttpTransportForOAuth();
    JacksonFactory jsonFactory = new JacksonFactory();
    return new GoogleCredential.Builder().setTransport(transport).setJsonFactory(jsonFactory).setServiceAccountId(serviceAccountId).setServiceAccountScopes(OAUTH_SCOPES);
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) JacksonFactory(com.google.api.client.json.jackson.JacksonFactory)

Example 3 with JacksonFactory

use of com.google.api.client.json.jackson.JacksonFactory in project appengine-java-standard by GoogleCloudPlatform.

the class RemoteApiOptions method useComputeEngineCredential.

/**
 * Use a Compute Engine credential for authentication. Overrides any
 * previously-provided credentials.
 *
 * @return this {@code RemoteApiOptions} instance
 * @deprecated Use {@link #useApplicationDefaultCredential}.
 */
@Deprecated
public RemoteApiOptions useComputeEngineCredential() {
    // if there's a problem getting the credential.
    try {
        HttpTransport transport = getOrCreateHttpTransportForOAuth();
        // Try to connect using Google Compute Engine service account credentials.
        ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory());
        // Force token refresh to verify that we are running on Google Compute Engine.
        credential.refreshToken();
        setOAuthCredential(credential);
    } catch (IOException | GeneralSecurityException e) {
        throw new RuntimeException("Failed to acquire Google Compute Engine credential.", e);
    }
    return this;
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) ComputeCredential(com.google.api.client.googleapis.compute.ComputeCredential) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) JacksonFactory(com.google.api.client.json.jackson.JacksonFactory)

Example 4 with JacksonFactory

use of com.google.api.client.json.jackson.JacksonFactory in project muikku by otavanopisto.

the class GoogleCalendarClient method getServiceAccountCredential.

private GoogleCredential getServiceAccountCredential() throws GeneralSecurityException, IOException {
    String accountEmail = System.getProperty("muikku.googleServiceAccount.accountEmail");
    if (StringUtils.isBlank(accountEmail)) {
        throw new GeneralSecurityException("muikku.googleServiceAccount.accountEmail environment property is missing");
    }
    String accountUser = System.getProperty("muikku.googleServiceAccount.accountUser");
    if (StringUtils.isBlank(accountUser)) {
        throw new GeneralSecurityException("muikku.googleServiceAccount.accountUser environment property is missing");
    }
    String keyFilePath = System.getProperty("muikku.googleServiceAccount.keyFile");
    if (StringUtils.isBlank(keyFilePath)) {
        throw new GeneralSecurityException("muikku.googleServiceAccount.keyFile environment property is missing");
    }
    java.io.File keyFile = new java.io.File(keyFilePath);
    if (!keyFile.exists()) {
        throw new GeneralSecurityException("muikku.googleServiceAccount.keyFile environment property is pointing into non-existing file");
    }
    return new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory()).setServiceAccountId(accountEmail).setServiceAccountScopes(Arrays.asList(CalendarScopes.CALENDAR)).setServiceAccountPrivateKeyFromP12File(keyFile).setServiceAccountUser(accountUser).build();
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GeneralSecurityException(java.security.GeneralSecurityException) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson.JacksonFactory)

Example 5 with JacksonFactory

use of com.google.api.client.json.jackson.JacksonFactory in project google-cloud-eclipse by GoogleCloudPlatform.

the class CredentialHelperTest method createCredential.

private static Credential createCredential(String accessToken, String refreshToken) {
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory()).setClientSecrets(Constants.getOAuthClientId(), Constants.getOAuthClientSecret()).build();
    credential.setAccessToken(accessToken);
    credential.setRefreshToken(refreshToken);
    return credential;
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson.JacksonFactory)

Aggregations

JacksonFactory (com.google.api.client.json.jackson.JacksonFactory)7 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)2 ComputeCredential (com.google.api.client.googleapis.compute.ComputeCredential)2 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 HttpTransport (com.google.api.client.http.HttpTransport)2 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)2 Apps (com.google.api.services.appengine.v1.Appengine.Apps)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Test (org.junit.Test)2 Credential (com.google.api.client.auth.oauth2.Credential)1 File (java.io.File)1 IOException (java.io.IOException)1 PrivateKey (java.security.PrivateKey)1