Search in sources :

Example 11 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project maven-plugins by apache.

the class GitHubDownloaderTestCase method testConfigureAuthenticationWithNoServer.

public void testConfigureAuthenticationWithNoServer() throws Exception {
    IssueManagement issueManagement = newGitHubIssueManagement();
    GitHubDownloader gitHubDownloader = newGitHubDownloader(issueManagement);
    Settings settings = new Settings();
    Server server = newServer("not-the-right-one");
    settings.addServer(server);
    SettingsDecrypter decrypter = mock(SettingsDecrypter.class);
    SettingsDecryptionResult result = mock(SettingsDecryptionResult.class);
    Log log = mock(Log.class);
    when(result.getProblems()).thenReturn(Collections.<SettingsProblem>emptyList());
    when(result.getServer()).thenReturn(server);
    when(decrypter.decrypt(new DefaultSettingsDecryptionRequest(server))).thenReturn(result);
    gitHubDownloader.configureAuthentication(decrypter, "github-server", settings, log);
    verify(log).warn("Can't find server id [github-server] configured in githubAPIServerId.");
}
Also used : Server(org.apache.maven.settings.Server) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) Log(org.apache.maven.plugin.logging.Log) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) IssueManagement(org.apache.maven.model.IssueManagement) Settings(org.apache.maven.settings.Settings)

Example 12 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project maven-plugins by apache.

the class AbstractScmPublishMojo method setupScm.

private ReleaseDescriptor setupScm() throws ScmRepositoryException, NoSuchScmProviderException {
    String scmUrl;
    if (localCheckout) {
        // in the release phase we have to change the checkout URL
        // to do a local checkout instead of going over the network.
        String provider = ScmUrlUtils.getProvider(pubScmUrl);
        String delimiter = ScmUrlUtils.getDelimiter(pubScmUrl);
        String providerPart = "scm:" + provider + delimiter;
        // X TODO: also check the information from releaseDescriptor.getScmRelativePathProjectDirectory()
        // X TODO: in case our toplevel git directory has no pom.
        // X TODO: fix pathname once I understand this.
        scmUrl = providerPart + "file://" + "target/localCheckout";
        logInfo("Performing a LOCAL checkout from " + scmUrl);
    }
    ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
    releaseDescriptor.setInteractive(settings.isInteractiveMode());
    if (username == null || password == null) {
        for (Server server : settings.getServers()) {
            if (server.getId().equals(serverId)) {
                SettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(server);
                SettingsDecryptionResult decryptionResult = settingsDecrypter.decrypt(decryptionRequest);
                if (!decryptionResult.getProblems().isEmpty()) {
                // todo throw exception?
                }
                if (username == null) {
                    username = decryptionResult.getServer().getUsername();
                }
                if (password == null) {
                    password = decryptionResult.getServer().getPassword();
                }
                break;
            }
        }
    }
    releaseDescriptor.setScmPassword(password);
    releaseDescriptor.setScmUsername(username);
    releaseDescriptor.setWorkingDirectory(basedir.getAbsolutePath());
    releaseDescriptor.setLocalCheckout(localCheckout);
    releaseDescriptor.setScmSourceUrl(pubScmUrl);
    if (providerImplementations != null) {
        for (Map.Entry<String, String> providerEntry : providerImplementations.entrySet()) {
            logInfo("Changing the default '%s' provider implementation to '%s'.", providerEntry.getKey(), providerEntry.getValue());
            scmManager.setScmProviderImplementation(providerEntry.getKey(), providerEntry.getValue());
        }
    }
    scmRepository = scmRepositoryConfigurator.getConfiguredRepository(releaseDescriptor, settings);
    scmProvider = scmRepositoryConfigurator.getRepositoryProvider(scmRepository);
    return releaseDescriptor;
}
Also used : Server(org.apache.maven.settings.Server) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) ReleaseDescriptor(org.apache.maven.shared.release.config.ReleaseDescriptor) Map(java.util.Map)

Example 13 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project sts4 by spring-projects.

the class MavenBridge method decryptPassword.

public Server decryptPassword(Server server) throws MavenException {
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = lookup(SettingsDecrypter.class).decrypt(request);
    for (SettingsProblem problem : result.getProblems()) {
        log.warn(problem.getMessage(), problem.getException());
    }
    return result.getServer();
}
Also used : SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 14 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project spring-cloud-function by spring-cloud.

the class MavenSettingsReader method readSettings.

public MavenSettings readSettings() {
    Settings settings = loadSettings();
    SettingsDecryptionResult decrypted = decryptSettings(settings);
    if (!decrypted.getProblems().isEmpty()) {
        log.error("Maven settings decryption failed. Some Maven repositories may be inaccessible");
    // Continue - the encrypted credentials may not be used
    }
    return new MavenSettings(settings, decrypted);
}
Also used : SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) Settings(org.apache.maven.settings.Settings)

Example 15 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project jib by google.

the class MavenSettingsProxyProvider method activateHttpAndHttpsProxies.

/**
 * Initializes proxy settings based on Maven settings if they are not already set by the user
 * directly.
 *
 * @param settings Maven settings
 */
static void activateHttpAndHttpsProxies(Settings settings, SettingsDecrypter decrypter) throws MojoExecutionException {
    List<Proxy> proxies = new ArrayList<>(2);
    for (String protocol : ImmutableList.of("http", "https")) {
        if (areProxyPropertiesSet(protocol)) {
            continue;
        }
        settings.getProxies().stream().filter(Proxy::isActive).filter(proxy -> protocol.equals(proxy.getProtocol())).findFirst().ifPresent(proxies::add);
    }
    if (proxies.isEmpty()) {
        return;
    }
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest().setProxies(proxies);
    SettingsDecryptionResult result = decrypter.decrypt(request);
    for (SettingsProblem problem : result.getProblems()) {
        if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
            throw new MojoExecutionException("Unable to decrypt proxy info from settings.xml: " + problem);
        }
    }
    result.getProxies().forEach(MavenSettingsProxyProvider::setProxyProperties);
}
Also used : Proxy(org.apache.maven.settings.Proxy) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Aggregations

SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)37 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)33 Server (org.apache.maven.settings.Server)17 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)16 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)14 Proxy (org.apache.maven.settings.Proxy)7 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)6 MavenSession (org.apache.maven.execution.MavenSession)6 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)5 Settings (org.apache.maven.settings.Settings)5 IOException (java.io.IOException)3 Map (java.util.Map)3 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)3 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)2 LayerConfiguration (com.google.cloud.tools.jib.api.LayerConfiguration)2 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)2 AuthProperty (com.google.cloud.tools.jib.plugins.common.AuthProperty)2 InferredAuthException (com.google.cloud.tools.jib.plugins.common.InferredAuthException)2 File (java.io.File)2