當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleCredential.getApplicationDefault方法代碼示例

本文整理匯總了Java中com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleCredential.getApplicationDefault方法的具體用法?Java GoogleCredential.getApplicationDefault怎麽用?Java GoogleCredential.getApplicationDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.googleapis.auth.oauth2.GoogleCredential的用法示例。


在下文中一共展示了GoogleCredential.getApplicationDefault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClient

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/** Builds a new Pubsub client and returns it. */
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory)
    throws IOException {
  checkNotNull(httpTransport);
  checkNotNull(jsonFactory);
  GoogleCredential credential =
      GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
  if (credential.createScopedRequired()) {
    credential = credential.createScoped(PubsubScopes.all());
  }
  if (credential.getClientAuthentication() != null) {
    System.out.println(
        "\n***Warning! You are not using service account credentials to "
            + "authenticate.\nYou need to use service account credentials for this example,"
            + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run "
            + "out of PubSub quota very quickly.\nSee "
            + "https://developers.google.com/identity/protocols/application-default-credentials.");
    System.exit(1);
  }
  HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
  return new Pubsub.Builder(httpTransport, jsonFactory, initializer)
      .setApplicationName(APP_NAME)
      .build();
}
 
開發者ID:mdvorsky,項目名稱:DataflowSME,代碼行數:25,代碼來源:InjectorUtils.java

示例2: BigQueryExporter

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
public BigQueryExporter(BigQueryExporterConfiguration config) {
	this.config = config;
	this.checkedSchemas = new HashSet<String>();
	this.existingSchemaMap = new HashMap<String, com.google.api.services.bigquery.model.TableSchema>();

	HttpTransport transport = new NetHttpTransport();
	JsonFactory jsonFactory = new JacksonFactory();
	GoogleCredential credential;
	try {
		credential = GoogleCredential.getApplicationDefault(transport,
				jsonFactory);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	if (credential.createScopedRequired()) {
		credential = credential.createScoped(BigqueryScopes.all());
	}
	this.bq = new Bigquery.Builder(transport, jsonFactory, credential)
			.setApplicationName(this.config.applicationName).build();
}
 
開發者ID:frew,項目名稱:chute,代碼行數:21,代碼來源:BigQueryExporter.java

示例3: getClient

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/**
 * Builds a new Pubsub client and returns it.
 */
public static Pubsub getClient(final HttpTransport httpTransport,
                               final JsonFactory jsonFactory)
         throws IOException {
    checkNotNull(httpTransport);
    checkNotNull(jsonFactory);
    GoogleCredential credential =
        GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(PubsubScopes.all());
    }
    if (credential.getClientAuthentication() != null) {
      System.out.println("\n***Warning! You are not using service account credentials to "
        + "authenticate.\nYou need to use service account credentials for this example,"
        + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run "
        + "out of PubSub quota very quickly.\nSee "
        + "https://developers.google.com/identity/protocols/application-default-credentials.");
      System.exit(1);
    }
    HttpRequestInitializer initializer =
        new RetryHttpInitializerWrapper(credential);
    return new Pubsub.Builder(httpTransport, jsonFactory, initializer)
            .setApplicationName(APP_NAME)
            .build();
}
 
開發者ID:davorbonaci,項目名稱:beam-portability-demo,代碼行數:28,代碼來源:InjectorUtils.java

示例4: getProjectsApiStub

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/**
 * Return the Projects api object used for accessing the Cloud Resource Manager Projects API.
 * @return Projects api object used for accessing the Cloud Resource Manager Projects API
 * @throws GeneralSecurityException Thrown if there's a permissions error.
 * @throws IOException Thrown if there's an IO error initializing the API object.
 */
public static synchronized Projects getProjectsApiStub()
    throws GeneralSecurityException, IOException {
  if (projectApiStub != null) {
    return projectApiStub;
  }
  HttpTransport transport;
  GoogleCredential credential;
  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  transport = GoogleNetHttpTransport.newTrustedTransport();
  credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
  if (credential.createScopedRequired()) {
    Collection<String> scopes = CloudResourceManagerScopes.all();
    credential = credential.createScoped(scopes);
  }
  projectApiStub = new CloudResourceManager
      .Builder(transport, jsonFactory, credential)
      .build()
      .projects();
  return projectApiStub;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:27,代碼來源:GCPProject.java

示例5: getServiceAccountsApiStub

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/**
 * Get the API stub for accessing the IAM Service Accounts API.
 * @return ServiceAccounts api stub for accessing the IAM Service Accounts API.
 * @throws IOException Thrown if there's an IO error initializing the api connection.
 * @throws GeneralSecurityException Thrown if there's a security error
 * initializing the connection.
 */
public static ServiceAccounts getServiceAccountsApiStub() throws IOException, GeneralSecurityException {
  if (serviceAccountsApiStub == null) {
    HttpTransport transport;
    GoogleCredential credential;
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    transport = GoogleNetHttpTransport.newTrustedTransport();
    credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
    if (credential.createScopedRequired()) {
      Collection<String> scopes = IamScopes.all();
      credential = credential.createScoped(scopes);
    }
    serviceAccountsApiStub = new Iam.Builder(transport, jsonFactory, credential)
        .build()
        .projects()
        .serviceAccounts();
  }
  return serviceAccountsApiStub;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:26,代碼來源:GCPServiceAccount.java

示例6: create

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
@Override
public Credential create() {
  GoogleCredential credential;
  try {
    credential = GoogleCredential.getApplicationDefault();
  } catch (IOException e) {
    throw
        new RuntimeException(
            "Unable to obtain credentials to communicate with the Cloud SQL API", e);
  }
  if (credential.createScopedRequired()) {
    credential = credential.createScoped(
        Collections.singletonList(SQLAdminScopes.SQLSERVICE_ADMIN));
  }
  return credential;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-sql-jdbc-socket-factory,代碼行數:17,代碼來源:SslSocketFactory.java

示例7: loadStorageCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private static GoogleCredential loadStorageCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException {
  GoogleCredential credential;
  if (!jsonPath.isEmpty()) {
    FileInputStream stream = new FileInputStream(jsonPath);
    credential = GoogleCredential.fromStream(stream, transport, factory);
    log.info("Loaded storage credentials from " + jsonPath);
  } else {
    log.info("Using storage default application credentials.");
    credential = GoogleCredential.getApplicationDefault();
  }

  if (credential.createScopedRequired()) {
    credential = credential.createScoped(StorageScopes.all());
  }

  return credential;
}
 
開發者ID:spinnaker,項目名稱:halyard,代碼行數:18,代碼來源:GoogleStorage.java

示例8: loadKmsCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private static GoogleCredential loadKmsCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException {
  GoogleCredential credential;
  if (!jsonPath.isEmpty()) {
    FileInputStream stream = new FileInputStream(jsonPath);
    credential = GoogleCredential.fromStream(stream, transport, factory);
    log.info("Loaded kms credentials from " + jsonPath);
  } else {
    log.info("Using kms default application credentials.");
    credential = GoogleCredential.getApplicationDefault();
  }

  if (credential.createScopedRequired()) {
    credential = credential.createScoped(CloudKMSScopes.all());
  }

  return credential;
}
 
開發者ID:spinnaker,項目名稱:halyard,代碼行數:18,代碼來源:GoogleKms.java

示例9: provideBigqueryConnection

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/**
 * Constructs a BigqueryConnection with default settings.
 *
 * <p>We use Bigquery to generate ICANN monthly reports via large aggregate SQL queries.
 *
 * @see ActivityReportingQueryBuilder
 * @see google.registry.tools.BigqueryParameters for justifications of defaults.
 */
@Provides
static BigqueryConnection provideBigqueryConnection(HttpTransport transport) {
  try {
    GoogleCredential credential = GoogleCredential
        .getApplicationDefault(transport, new JacksonFactory());
    BigqueryConnection connection =
        new BigqueryConnection.Builder()
            .setExecutorService(MoreExecutors.newDirectExecutorService())
            .setCredential(credential.createScoped(ImmutableList.of(BIGQUERY_SCOPE)))
            .setDatasetId(ICANN_REPORTING_DATA_SET)
            .setOverwrite(true)
            .setPollInterval(Duration.standardSeconds(1))
            .build();
    connection.initialize();
    return connection;
  } catch (Throwable e) {
    throw new RuntimeException("Could not initialize BigqueryConnection!", e);
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:28,代碼來源:IcannReportingModule.java

示例10: createComputeService

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/**
 * Set up the Compute Engine service
 * 
 * @return Compute.Builder
 * 
 * @throws IOException
 * @throws GeneralSecurityException
 */
public static Compute createComputeService() throws IOException, GeneralSecurityException {
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

    GoogleCredential credential = GoogleCredential.getApplicationDefault();
    if (credential.createScopedRequired()) {
      credential =
          credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/cloud-platform"));
    }

    return new Compute.Builder(httpTransport, jsonFactory, credential)
        .setApplicationName("b612_BetterWorld/1.0")
        .build();
  }
 
開發者ID:DanielHawes,項目名稱:AsteroidEndpointTest,代碼行數:23,代碼來源:AsteroidList.java

示例11: constructStorageApiStub

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private static Storage constructStorageApiStub() throws GeneralSecurityException, IOException {
  JsonFactory jsonFactory = new JacksonFactory();
  HttpTransport transport;
  transport = GoogleNetHttpTransport.newTrustedTransport();
  GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
  if (credential.createScopedRequired()) {
    Collection<String> scopes = StorageScopes.all();
    credential = credential.createScoped(scopes);
  }
  return new Storage.Builder(transport, jsonFactory, credential)
      .setApplicationName("GCS Samples")
      .build();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:14,代碼來源:GCSFilesSource.java

示例12: buildService

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private static Storage buildService() throws IOException, GeneralSecurityException {
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);

    if (credential.createScopedRequired()) {
        Collection<String> bigqueryScopes = StorageScopes.all();
        credential = credential.createScoped(bigqueryScopes);
    }

    return new Storage.Builder(transport, jsonFactory, credential)
            .setApplicationName("MCSFS")
            .build();
}
 
開發者ID:darshanmaiya,項目名稱:MCSFS,代碼行數:15,代碼來源:StorageFactory.java

示例13: getGoogleCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private GoogleCredential getGoogleCredential() {
  try {
    if (StringUtils.isNotEmpty(config.getCredentialPath())) {
      return GoogleCredential.fromStream(new FileInputStream(config.getCredentialPath()));
    } else {
      return GoogleCredential.getApplicationDefault();
    }
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  }
}
 
開發者ID:spinnaker,項目名稱:fiat,代碼行數:12,代碼來源:GoogleDirectoryUserRolesProvider.java

示例14: loadCredential

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private synchronized void loadCredential() throws IOException {
  if (credential != null) {
    return;
  }

  credential = GoogleCredential.getApplicationDefault();
}
 
開發者ID:spotify,項目名稱:dataproc-java-submitter,代碼行數:8,代碼來源:DefaultCredentialProvider.java

示例15: newGCEController

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/** Returns a GCEController using default application credentials. */
public static GCEController newGCEController(
    String projectName,
    Map<String, Map<ClientParams, Integer>> types,
    int cores,
    ScheduledExecutorService executor) {
  try {
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
    if (credential.createScopedRequired()) {
      credential =
          credential.createScoped(
              Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
    }
    return new GCEController(
        projectName,
        types,
        cores,
        executor,
        new Storage.Builder(transport, jsonFactory, credential)
            .setApplicationName("Cloud Pub/Sub Loadtest Framework")
            .build(),
        new Compute.Builder(transport, jsonFactory, credential)
            .setApplicationName("Cloud Pub/Sub Loadtest Framework")
            .build(),
        new Pubsub.Builder(transport, jsonFactory, credential)
            .setApplicationName("Cloud Pub/Sub Loadtest Framework")
            .build());
  } catch (Throwable t) {
    log.error("Unable to initialize GCE: ", t);
    return null;
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:pubsub,代碼行數:35,代碼來源:GCEController.java


注:本文中的com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。