use of com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException in project azure-maven-plugins by microsoft.
the class MavenAuthUtils method buildAuthConfiguration.
public static AuthConfiguration buildAuthConfiguration(MavenSession session, SettingsDecrypter settingsDecrypter, @Nonnull MavenAuthConfiguration auth) throws AzureExecutionException, MavenDecryptException {
final String serverId = auth.getServerId();
final AuthConfiguration authConfiguration;
try {
authConfiguration = convertToAuthConfiguration(StringUtils.isNotBlank(auth.getServerId()) ? buildAuthConfigurationByServerId(session, settingsDecrypter, serverId) : auth);
} catch (InvalidConfigurationException ex) {
final String messagePostfix = StringUtils.isNotBlank(serverId) ? ("in server: '" + serverId + "' at maven settings.xml.") : "in <auth> configuration.";
throw new AzureExecutionException(String.format("%s %s", ex.getMessage(), messagePostfix));
}
return authConfiguration;
}
use of com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException in project azure-gradle-plugins by microsoft.
the class GradleAuthHelper method login.
public static String login(GradleAuthConfig auth, String subscriptionId) {
try {
Account account = login(toAuthConfiguration(ObjectUtils.firstNonNull(auth, new GradleAuthConfig())));
final List<Subscription> subscriptions = account.getSubscriptions();
final String targetSubscriptionId = getTargetSubscriptionId(subscriptionId, subscriptions, account.getSelectedSubscriptions());
checkSubscription(subscriptions, targetSubscriptionId);
Azure.az(AzureAccount.class).account().selectSubscription(Collections.singletonList(targetSubscriptionId));
printCurrentSubscription(account);
return targetSubscriptionId;
} catch (InvalidConfigurationException e) {
throw new AzureToolkitAuthenticationException("Failed to authenticate with Azure due to error: " + e.getMessage());
}
}
use of com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException in project azure-maven-plugins by microsoft.
the class MavenSettingHelper method buildAuthConfigurationByServerId.
/**
* Build maven auth configuration from serverId.
*
* @param session the maven session
* @param settingsDecrypter the decrypter
* @param serverId the server id
* @return the auth configuration
* @throws MavenDecryptException when there are errors decrypting maven generated password
* @throws InvalidConfigurationException where are any illegal configurations
*/
public static MavenAuthConfiguration buildAuthConfigurationByServerId(MavenSession session, SettingsDecrypter settingsDecrypter, String serverId) throws InvalidConfigurationException, MavenDecryptException {
if (StringUtils.isBlank(serverId)) {
throw new IllegalArgumentException("Parameter 'serverId' cannot be null or empty.");
}
final Server server = session.getSettings().getServer(serverId);
if (server == null) {
throw new InvalidConfigurationException(String.format("serverId '%s' cannot be found in maven settings.xml.", serverId));
}
final MavenAuthConfiguration configurationFromServer = new MavenAuthConfiguration();
final Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration();
configurationFromServer.setServerId(serverId);
if (configuration == null) {
return configurationFromServer;
}
configurationFromServer.setTenant(getPropertyValue(configuration, "tenant"));
configurationFromServer.setClient(getPropertyValue(configuration, "client"));
final String rawKey = getPropertyValue(configuration, "key");
configurationFromServer.setKey(isPropertyEncrypted(rawKey) ? decryptMavenSettingProperty(settingsDecrypter, "key", rawKey) : rawKey);
configurationFromServer.setCertificate(getPropertyValue(configuration, "certificate"));
final String rawCertificatePassword = getPropertyValue(configuration, "certificatePassword");
configurationFromServer.setCertificatePassword(isPropertyEncrypted(rawCertificatePassword) ? decryptMavenSettingProperty(settingsDecrypter, "certificatePassword", rawCertificatePassword) : rawCertificatePassword);
configurationFromServer.setEnvironment(getPropertyValue(configuration, "environment"));
configurationFromServer.setServerId(serverId);
return configurationFromServer;
}
use of com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException in project azure-maven-plugins by microsoft.
the class MavenAuthUtils method convertToAuthConfiguration.
private static AuthConfiguration convertToAuthConfiguration(MavenAuthConfiguration mavenAuthConfiguration) throws InvalidConfigurationException {
if (Objects.isNull(mavenAuthConfiguration)) {
return new AuthConfiguration();
}
final AuthConfiguration authConfiguration = new AuthConfiguration();
authConfiguration.setClient(mavenAuthConfiguration.getClient());
authConfiguration.setTenant(mavenAuthConfiguration.getTenant());
authConfiguration.setCertificate(mavenAuthConfiguration.getCertificate());
authConfiguration.setCertificatePassword(mavenAuthConfiguration.getCertificatePassword());
authConfiguration.setKey(mavenAuthConfiguration.getKey());
final String authTypeStr = mavenAuthConfiguration.getType();
authConfiguration.setType(AuthType.parseAuthType(authTypeStr));
authConfiguration.setEnvironment(AzureEnvironmentUtils.stringToAzureEnvironment(mavenAuthConfiguration.getEnvironment()));
if (StringUtils.isNotBlank(mavenAuthConfiguration.getEnvironment()) && Objects.isNull(authConfiguration.getEnvironment())) {
throw new InvalidConfigurationException(String.format(INVALID_AZURE_ENVIRONMENT, mavenAuthConfiguration.getEnvironment()));
}
// if user doesn't specify any authType
if (StringUtils.isBlank(mavenAuthConfiguration.getType())) {
if (!StringUtils.isAllBlank(mavenAuthConfiguration.getCertificate(), mavenAuthConfiguration.getKey(), mavenAuthConfiguration.getCertificatePassword())) {
ValidationUtil.validateAuthConfiguration(authConfiguration);
}
} else if (authConfiguration.getType() == AuthType.SERVICE_PRINCIPAL) {
ValidationUtil.validateAuthConfiguration(authConfiguration);
}
return authConfiguration;
}
use of com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException in project azure-gradle-plugins by microsoft.
the class GradleAuthHelper method toAuthConfiguration.
private static AuthConfiguration toAuthConfiguration(GradleAuthConfig gradleAuthConfig) throws InvalidConfigurationException {
final AuthConfiguration authConfiguration = new AuthConfiguration();
authConfiguration.setClient(gradleAuthConfig.getClient());
authConfiguration.setTenant(gradleAuthConfig.getTenant());
authConfiguration.setCertificate(gradleAuthConfig.getCertificate());
authConfiguration.setCertificatePassword(gradleAuthConfig.getCertificatePassword());
authConfiguration.setKey(gradleAuthConfig.getKey());
final String authTypeStr = gradleAuthConfig.getType();
authConfiguration.setType(AuthType.parseAuthType(authTypeStr));
authConfiguration.setEnvironment(AzureEnvironmentUtils.stringToAzureEnvironment(gradleAuthConfig.getEnvironment()));
if (StringUtils.isNotBlank(gradleAuthConfig.getEnvironment()) && Objects.isNull(authConfiguration.getEnvironment())) {
throw new InvalidConfigurationException(String.format(INVALID_AZURE_ENVIRONMENT, gradleAuthConfig.getEnvironment()));
}
return authConfiguration;
}
Aggregations