本文整理汇总了Java中com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidCredentialsException类的具体用法?Java InvalidCredentialsException怎么用?Java InvalidCredentialsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvalidCredentialsException类属于com.cloudera.director.spi.v1.model.exception包,在下文中一共展示了InvalidCredentialsException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: propagateIfUnrecoverable
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException; //导入依赖的package包/类
/**
* Propagates exception as an unrecoverable error when the relevant
* indicators are present.
*
* @param e the Amazon client exception
*/
public static void propagateIfUnrecoverable(AmazonClientException e) {
if (e instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException) e;
if (AUTHORIZATION_ERROR_CODES.contains(ase.getErrorCode())) {
throw new InvalidCredentialsException(ase.getErrorMessage(), ase);
}
// All exceptions that represent client errors are unrecoverable because the request itself is wrong
// See {@see AmazonServiceException#ErrorType}
// OperationNotPermitted exception is unrecoverable. This can happen when terminating an
// instance that has termination protection enabled, or trying to detach the primary
// network interface (eth0) from an instance.
// Unsupported exception is also unrecoverable, since it represents an unsupported request.
// See docs at http://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html
if (ase.getErrorType() == AmazonServiceException.ErrorType.Client ||
"OperationNotPermitted".equals(ase.getErrorCode()) ||
"Unsupported".equals(ase.getErrorCode())) {
throw new UnrecoverableProviderException(ase.getErrorMessage(), ase);
}
}
if (!e.isRetryable()) {
throw new UnrecoverableProviderException(e.getMessage(), e);
}
}
示例2: createCloudProviderWithInvalidDeprecatedManagementUrlsExpectExceptionThrown
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException; //导入依赖的package包/类
@Test
public void createCloudProviderWithInvalidDeprecatedManagementUrlsExpectExceptionThrown()
throws Exception {
Map<String, String> map = TestHelper.buildValidDirectorLiveTestMap();
map.put(AzureCredentialsConfiguration.MGMT_URL.unwrap().getConfigKey(),
"https://fake-management.azure.com/");
thrown.expect(InvalidCredentialsException.class);
launcher.createCloudProvider(AzureCloudProvider.ID,
new SimpleConfiguration(map), Locale.getDefault());
}
示例3: AzureCredentials
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException; //导入依赖的package包/类
/**
* Builds credentials in a backwards compatible way by:
* 1. If the "MGMT_URL" field (plugin v1) is set then map it to the corresponding Azure Cloud and
* build the credentials. If the field doesn't map then log an error and exit.
* 2. Otherwise Authenticate with the "azureCloudEnvironment" field (plugin v2) normally.
*
* @param config config with Azure Credential fields
* @param local localization context to extract config
*/
public AzureCredentials(Configured config, LocalizationContext local) {
LOG.info("Creating ApplicationTokenCredentials");
this.subId = config.getConfigurationValue(AzureCredentialsConfiguration.SUBSCRIPTION_ID, local);
AzureEnvironment azureEnvironment;
// if MGMT_URL is set use it to find the AzureEnvironment
String managementUrl =
config.getConfigurationValue(AzureCredentialsConfiguration.MGMT_URL, local);
if (managementUrl != null && !managementUrl.isEmpty()) {
LOG.warn("DEPRECATION WARNING: using Management URL is deprecated. It's recommended to " +
"REMOVE the key '{}' from the template (otherwise Director will attempt to use the " +
"deprecated method) and specify an Azure Cloud Environment with the key '{}' " +
"instead.",
AzureCredentialsConfiguration.MGMT_URL.unwrap().getConfigKey(),
AzureCredentialsConfiguration.AZURE_CLOUD_ENVIRONMENT.unwrap().getConfigKey());
azureEnvironment = AzureCloudEnvironment
.getAzureEnvironmentFromDeprecatedConfig(managementUrl);
} else {
azureEnvironment = AzureCloudEnvironment.get(config
.getConfigurationValue(AzureCredentialsConfiguration.AZURE_CLOUD_ENVIRONMENT, local));
}
if (azureEnvironment == null) {
throw new InvalidCredentialsException(String.format("Azure Cloud Environment %s is not a " +
"valid environment. Valid environments: %s",
config.getConfigurationValue(
AzureCredentialsConfiguration.AZURE_CLOUD_ENVIRONMENT, local),
AzureCloudEnvironment.keysToString()));
}
this.credentials = new ApplicationTokenCredentials(
config.getConfigurationValue(AzureCredentialsConfiguration.CLIENT_ID, local),
config.getConfigurationValue(AzureCredentialsConfiguration.TENANT_ID, local),
config.getConfigurationValue(AzureCredentialsConfiguration.CLIENT_SECRET, local),
azureEnvironment);
}
示例4: testUnauthorizedOperationException
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException; //导入依赖的package包/类
@Test(expected = InvalidCredentialsException.class)
public void testUnauthorizedOperationException() {
AmazonServiceException e =
new AmazonServiceException("Test Amazon UnauthorizedOperation exception");
e.setErrorCode("UnauthorizedOperation");
AWSExceptions.propagate(e);
}
示例5: testAuthFailureException
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException; //导入依赖的package包/类
@Test(expected = InvalidCredentialsException.class)
public void testAuthFailureException() {
AmazonServiceException e =
new AmazonServiceException("Test Amazon AuthFailure exception");
e.setErrorCode("AuthFailure");
AWSExceptions.propagate(e);
}
示例6: createCloudProvider
import com.cloudera.director.spi.v1.model.exception.InvalidCredentialsException; //导入依赖的package包/类
@Override
public CloudProvider createCloudProvider(String cloudProviderId, Configured configuration,
Locale locale) {
if (!GoogleCloudProvider.ID.equals(cloudProviderId)) {
throw new IllegalArgumentException("Cloud provider not found: " + cloudProviderId);
}
LocalizationContext localizationContext = getLocalizationContext(locale);
// At this point the configuration object will already contain
// the required data for authentication.
CredentialsProvider<GoogleCredentials> provider = new GoogleCredentialsProvider(applicationProperties);
GoogleCredentials credentials = provider.createCredentials(configuration, localizationContext);
Compute compute = credentials.getCompute();
if (compute == null) {
throw new InvalidCredentialsException("Invalid cloud provider credentials.");
} else {
String projectId = credentials.getProjectId();
try {
// Attempt GCP api call to verify credentials.
compute.regions().list(projectId).execute();
} catch (IOException e) {
throw new InvalidCredentialsException(
"Invalid cloud provider credentials for project '" + projectId + "'.", e);
}
}
return new GoogleCloudProvider(credentials, applicationProperties, googleConfig, localizationContext);
}