use of com.microsoft.azure.maven.model.MavenAuthConfiguration 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.maven.model.MavenAuthConfiguration in project azure-maven-plugins by microsoft.
the class AbstractAzureMojo method getAzureAccount.
protected Account getAzureAccount() throws MavenDecryptException, AzureExecutionException, LoginFailureException {
if (azureAccount == null) {
final MavenAuthConfiguration mavenAuthConfiguration = auth == null ? new MavenAuthConfiguration() : auth;
mavenAuthConfiguration.setType(getAuthType());
SystemPropertyUtils.injectCommandLineParameter("auth", mavenAuthConfiguration, MavenAuthConfiguration.class);
Azure.az().config().setUserAgent(getUserAgent());
azureAccount = login(MavenAuthUtils.buildAuthConfiguration(session, settingsDecrypter, mavenAuthConfiguration));
}
return azureAccount;
}
use of com.microsoft.azure.maven.model.MavenAuthConfiguration 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.maven.model.MavenAuthConfiguration 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;
}
Aggregations