当前位置: 首页>>代码示例>>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;未经允许,请勿转载。