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));
}
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);
}
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;
}
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();
}
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;
}
Aggregations