Search in sources :

Example 1 with MavenAuthConfiguration

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;
}
Also used : AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) MavenAuthConfiguration(com.microsoft.azure.maven.model.MavenAuthConfiguration) AuthConfiguration(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration) InvalidConfigurationException(com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException)

Example 2 with MavenAuthConfiguration

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;
}
Also used : MavenAuthConfiguration(com.microsoft.azure.maven.model.MavenAuthConfiguration)

Example 3 with MavenAuthConfiguration

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;
}
Also used : MavenAuthConfiguration(com.microsoft.azure.maven.model.MavenAuthConfiguration) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Server(org.apache.maven.settings.Server) InvalidConfigurationException(com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException)

Example 4 with MavenAuthConfiguration

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;
}
Also used : MavenAuthConfiguration(com.microsoft.azure.maven.model.MavenAuthConfiguration) AuthConfiguration(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration) InvalidConfigurationException(com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException)

Aggregations

MavenAuthConfiguration (com.microsoft.azure.maven.model.MavenAuthConfiguration)4 InvalidConfigurationException (com.microsoft.azure.toolkit.lib.auth.exception.InvalidConfigurationException)3 AuthConfiguration (com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration)2 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)1 Server (org.apache.maven.settings.Server)1 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)1