当前位置: 首页>>代码示例>>Java>>正文


Java Credentials类代码示例

本文整理汇总了Java中com.google.auth.Credentials的典型用法代码示例。如果您正苦于以下问题:Java Credentials类的具体用法?Java Credentials怎么用?Java Credentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Credentials类属于com.google.auth包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import com.google.auth.Credentials; //导入依赖的package包/类
@Before
public void setUp() {
	this.gcpConfigProperties = mock(GcpConfigPropertiesProvider.class);
	when(this.gcpConfigProperties.getName()).thenReturn("test");
	when(this.gcpConfigProperties.isEnabled()).thenReturn(true);
	org.springframework.cloud.gcp.core.Credentials configCredentials =
			mock(org.springframework.cloud.gcp.core.Credentials.class);
	when(this.gcpConfigProperties.getCredentials()).thenReturn(configCredentials);
	when(this.gcpConfigProperties.getProfile()).thenReturn("default");
	this.expectedProperties = new HashMap<>();
	this.expectedProperties.put("property-int", 10);
	this.expectedProperties.put("property-bool", true);
	this.projectIdProvider = () -> "projectid";
	this.credentialsProvider = () -> mock(Credentials.class);

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:17,代码来源:GoogleConfigPropertySourceLocatorTest.java

示例2: newCloudResourceManagerClient

import com.google.auth.Credentials; //导入依赖的package包/类
/**
 * Returns a CloudResourceManager client builder using the specified
 * {@link CloudResourceManagerOptions}.
 */
@VisibleForTesting
static CloudResourceManager.Builder newCloudResourceManagerClient(
    CloudResourceManagerOptions options) {
  Credentials credentials = options.getGcpCredential();
  if (credentials == null) {
    NullCredentialInitializer.throwNullCredentialException();
  }
  return new CloudResourceManager.Builder(Transport.getTransport(), Transport.getJsonFactory(),
      chainHttpRequestInitializer(
          credentials,
          // Do not log 404. It clutters the output and is possibly even required by the caller.
          new RetryHttpRequestInitializer(ImmutableList.of(404))))
      .setApplicationName(options.getAppName())
      .setGoogleClientRequestInitializer(options.getGoogleApiTrace());
}
 
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:GcpOptions.java

示例3: ChannelOptions

import com.google.auth.Credentials; //导入依赖的package包/类
/**
 * Construct a ChannelOptions object
 * @param credential A credential to use, may be null.
 * @param authority The authority to be passed in the HTTP/2 headers, or {@code null}
 * to use the default.
 * @param callTimingReportPath A client-local file to which a report of call timings
 * will be appended
 * @param callStatusReportPath A client-local file to which a report of call statuses
 * will be appended
 * @param unaryCallRetryOptions Options for how to handle retriable failed UnaryCalls.
 * @param scheduledExecutorService ScheduledExecutorService on which to retry RPCs.
 */
public ChannelOptions(Credentials credential,
    String authority,
    String callTimingReportPath,
    String callStatusReportPath,
    RetryOptions unaryCallRetryOptions,
    ScheduledExecutorService scheduledExecutorService,
    long timeoutMs,
    int channelCount) {
  this.credential = credential;
  this.authority = authority;
  this.callTimingReportPath = callTimingReportPath;
  this.callStatusReportPath = callStatusReportPath;
  this.scheduledExecutorService = scheduledExecutorService;
  this.unaryCallRetryOptions = unaryCallRetryOptions;
  this.timeoutMs = timeoutMs;
  this.channelCount = channelCount;
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:30,代码来源:ChannelOptions.java

示例4: PubSubClient

import com.google.auth.Credentials; //导入依赖的package包/类
public PubSubClient(PubSubDatastoreProperties datastore) {

        Credentials credentials = null;
        if (datastore.serviceAccountFile.getValue() == null) {
            try {
                credentials = GoogleCredentials.getApplicationDefault().createScoped(PubsubScopes.all());
            } catch (IOException e) {
                throw TalendRuntimeException.createUnexpectedException(e);
            }
        } else {
            credentials = createCredentials(datastore);
        }
        this.PROJECT_NAME = datastore.projectName.getValue();
        this.client = new Pubsub.Builder(Transport.getTransport(), Transport.getJsonFactory(),
                chainHttpRequestInitializer(credentials,
                        // Do not log 404. It clutters the output and is possibly even required by the caller.
                        new RetryHttpRequestInitializer(ImmutableList.of(404)))).build();
    }
 
开发者ID:Talend,项目名称:components,代码行数:19,代码来源:PubSubClient.java

示例5: newCredentials

import com.google.auth.Credentials; //导入依赖的package包/类
/**
 * Create a new {@link Credentials} object.
 *
 * @throws IOException in case the credentials can't be constructed.
 */
public static Credentials newCredentials(AuthAndTLSOptions options) throws IOException {
  if (options.googleCredentials != null) {
    // Credentials from file
    try (InputStream authFile = new FileInputStream(options.googleCredentials)) {
      return newCredentials(authFile, options.googleAuthScopes);
    } catch (FileNotFoundException e) {
      String message =
          String.format(
              "Could not open auth credentials file '%s': %s",
              options.googleCredentials, e.getMessage());
      throw new IOException(message, e);
    }
  } else if (options.useGoogleDefaultCredentials) {
    return newCredentials(
        null /* Google Application Default Credentials */, options.googleAuthScopes);
  }
  return null;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:24,代码来源:GoogleAuthUtils.java

示例6: setUp

import com.google.auth.Credentials; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) {
      Credentials mock = (Credentials) invocation.getMock();
      URI uri = (URI) invocation.getArguments()[0];
      RequestMetadataCallback callback = (RequestMetadataCallback) invocation.getArguments()[2];
      Map<String, List<String>> metadata;
      try {
        // Default to calling the blocking method, since it is easier to mock
        metadata = mock.getRequestMetadata(uri);
      } catch (Exception ex) {
        callback.onFailure(ex);
        return null;
      }
      callback.onSuccess(metadata);
      return null;
    }
  }).when(credentials).getRequestMetadata(
      any(URI.class),
      any(Executor.class),
      any(RequestMetadataCallback.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:GoogleAuthLibraryCallCredentialsTest.java

示例7: GoogleConfigPropertySourceLocator

import com.google.auth.Credentials; //导入依赖的package包/类
public GoogleConfigPropertySourceLocator(GcpProjectIdProvider projectIdProvider,
		CredentialsProvider credentialsProvider,
		GcpConfigPropertiesProvider gcpConfigPropertiesProvider) throws IOException {
	Assert.notNull(gcpConfigPropertiesProvider, "Google Config properties must not be null");

	if (gcpConfigPropertiesProvider.isEnabled()) {
		Assert.notNull(credentialsProvider, "Credentials provider cannot be null");
		Assert.notNull(projectIdProvider, "Project ID provider cannot be null");
		org.springframework.cloud.gcp.core.Credentials configCredentials =
				gcpConfigPropertiesProvider.getCredentials();
		this.credentials = configCredentials != null && configCredentials.getLocation() != null
				? GoogleCredentials.fromStream(
						gcpConfigPropertiesProvider.getCredentials().getLocation().getInputStream())
				.createScoped(gcpConfigPropertiesProvider.getCredentials().getScopes())
				: credentialsProvider.getCredentials();
		this.projectId = gcpConfigPropertiesProvider.getProjectId() != null
				? gcpConfigPropertiesProvider.getProjectId()
				: projectIdProvider.getProjectId();
		Assert.notNull(this.credentials, "Credentials must not be null");

		Assert.notNull(this.projectId, "Project ID must not be null");

		this.timeout = gcpConfigPropertiesProvider.getTimeoutMillis();
		this.name = gcpConfigPropertiesProvider.getName();
		this.profile = gcpConfigPropertiesProvider.getProfile();
		this.enabled = gcpConfigPropertiesProvider.isEnabled();
		Assert.notNull(this.name, "Config name must not be null");
		Assert.notNull(this.profile, "Config profile must not be null");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:31,代码来源:GoogleConfigPropertySourceLocator.java

示例8: getCredentials

import com.google.auth.Credentials; //导入依赖的package包/类
/** Returns a set of {@link Credentials} which can be used to authenticate requests. */
public Credentials getCredentials() {
  if (oauthConfig.getCredentialsCase() == CredentialsCase.ACCESS_TOKEN_CREDENTIALS) {
    return createAccessTokenCredentials(oauthConfig.getAccessTokenCredentials());
  } else if (oauthConfig.getCredentialsCase() == CredentialsCase.REFRESH_TOKEN_CREDENTIALS) {
    return createRefreshTokenCredentials(oauthConfig.getRefreshTokenCredentials());
  } else {
    throw new IllegalArgumentException(
        "Unknown oauth credential type: " + oauthConfig.getCredentialsCase());
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:12,代码来源:OauthCredentialsFactory.java

示例9: createAccessTokenCredentials

import com.google.auth.Credentials; //导入依赖的package包/类
private Credentials createAccessTokenCredentials(AccessTokenCredentials accessTokenCreds) {
  AccessToken accessToken = new AccessToken(
      readFile(Paths.get(accessTokenCreds.getAccessTokenPath())), null);

  logger.info("Using access token credentials");
  return new OAuth2Credentials(accessToken);
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:8,代码来源:OauthCredentialsFactory.java

示例10: createRefreshTokenCredentials

import com.google.auth.Credentials; //导入依赖的package包/类
private Credentials createRefreshTokenCredentials(
    OauthConfiguration.RefreshTokenCredentials refreshTokenCreds) {
  String exchangeUrl = oauthConfig.getRefreshTokenCredentials().getTokenEndpointUrl();
  String refreshToken = readFile(
      Paths.get(oauthConfig.getRefreshTokenCredentials().getRefreshTokenPath()));
  OauthClient oauthClient = oauthConfig.getRefreshTokenCredentials().getClient();

  logger.info("Using refresh token credentials");
  return RefreshTokenCredentials.create(oauthClient, refreshToken, exchangeUrl);
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:11,代码来源:OauthCredentialsFactory.java

示例11: getCredentials

import com.google.auth.Credentials; //导入依赖的package包/类
/**
 * Creates and returns the credentials from the given connection parameters.
 * 
 * @param parameters
 *          the connection parameters
 * @return the credentials for authenticating with the Datastore service.
 * @throws IOException
 *           if any error occurs such as not able to read the credentials file.
 */
private static Credentials getCredentials(ConnectionParameters parameters) throws IOException {
  if (parameters.isEmulator()) {
    return NoCredentials.getInstance();
  }
  InputStream jsonCredentialsStream = parameters.getJsonCredentialsStream();
  if (jsonCredentialsStream != null) {
    return ServiceAccountCredentials.fromStream(jsonCredentialsStream);
  }
  File jsonCredentialsFile = parameters.getJsonCredentialsFile();
  if (jsonCredentialsFile != null) {
    return ServiceAccountCredentials.fromStream(new FileInputStream(jsonCredentialsFile));
  }
  return ServiceAccountCredentials.getApplicationDefault();
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:24,代码来源:EntityManagerFactory.java

示例12: createInternal

import com.google.auth.Credentials; //导入依赖的package包/类
private static void createInternal(
    @Nullable Credentials credentials,
    @Nullable String projectId,
    @Nullable Duration exportInterval,
    @Nullable MonitoredResource monitoredResource)
    throws IOException {
  projectId = projectId == null ? ServiceOptions.getDefaultProjectId() : projectId;
  exportInterval = exportInterval == null ? DEFAULT_INTERVAL : exportInterval;
  monitoredResource = monitoredResource == null ? DEFAULT_RESOURCE : monitoredResource;
  synchronized (monitor) {
    checkState(exporter == null, "Stackdriver stats exporter is already created.");
    MetricServiceClient metricServiceClient;
    // Initialize MetricServiceClient inside lock to avoid creating multiple clients.
    if (credentials == null) {
      metricServiceClient = MetricServiceClient.create();
    } else {
      metricServiceClient =
          MetricServiceClient.create(
              MetricServiceSettings.newBuilder()
                  .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
                  .build());
    }
    exporter =
        new StackdriverStatsExporter(
            projectId,
            metricServiceClient,
            exportInterval,
            Stats.getViewManager(),
            monitoredResource);
    exporter.workerThread.start();
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:33,代码来源:StackdriverStatsExporter.java

示例13: createWithCredentials

import com.google.auth.Credentials; //导入依赖的package包/类
static StackdriverV2ExporterHandler createWithCredentials(
    Credentials credentials, String projectId) throws IOException {
  checkNotNull(credentials, "credentials");
  TraceServiceSettings traceServiceSettings =
      TraceServiceSettings.newBuilder()
          .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
          .build();
  return new StackdriverV2ExporterHandler(
      projectId, TraceServiceClient.create(traceServiceSettings));
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:11,代码来源:StackdriverV2ExporterHandler.java

示例14: chainHttpRequestInitializer

import com.google.auth.Credentials; //导入依赖的package包/类
private static HttpRequestInitializer chainHttpRequestInitializer(
    Credentials credential, HttpRequestInitializer httpRequestInitializer) {
  if (credential == null) {
    return new ChainingHttpRequestInitializer(
        new NullCredentialInitializer(), httpRequestInitializer);
  } else {
    return new ChainingHttpRequestInitializer(
        new HttpCredentialsAdapter(credential),
        httpRequestInitializer);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:ExampleUtils.java

示例15: getGcpCredential

import com.google.auth.Credentials; //导入依赖的package包/类
/**
 * The credential instance that should be used to authenticate against GCP services.
 * If no credential has been set explicitly, the default is to use the instance factory
 * that constructs a credential based upon the currently set credentialFactoryClass.
 */
@JsonIgnore
@Description("The credential instance that should be used to authenticate against GCP services. "
    + "If no credential has been set explicitly, the default is to use the instance factory "
    + "that constructs a credential based upon the currently set credentialFactoryClass.")
@Default.InstanceFactory(GcpUserCredentialsFactory.class)
Credentials getGcpCredential();
 
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:GcpOptions.java


注:本文中的com.google.auth.Credentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。