Search in sources :

Example 16 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project m2e-core by eclipse-m2e.

the class MavenImpl method decryptPassword.

@Override
public Server decryptPassword(Server server) throws CoreException {
    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) DefaultSettingsProblem(org.apache.maven.settings.building.DefaultSettingsProblem)

Example 17 with SettingsDecryptionResult

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

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 18 with SettingsDecryptionResult

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

the class GitHubDownloaderTestCase method testConfigureAuthenticationWithProblems.

public void testConfigureAuthenticationWithProblems() throws Exception {
    IssueManagement issueManagement = newGitHubIssueManagement();
    GitHubDownloader gitHubDownloader = newGitHubDownloader(issueManagement);
    Settings settings = new Settings();
    Server server = newServer("github-server");
    settings.addServer(server);
    SettingsDecrypter decrypter = mock(SettingsDecrypter.class);
    SettingsDecryptionResult result = mock(SettingsDecryptionResult.class);
    Log log = mock(Log.class);
    when(result.getProblems()).thenReturn(Arrays.<SettingsProblem>asList(new DefaultSettingsProblem("Ups " + server.getId(), Severity.ERROR, null, -1, -1, null)));
    when(result.getServer()).thenReturn(server);
    when(decrypter.decrypt(any(SettingsDecryptionRequest.class))).thenReturn(result);
    gitHubDownloader.configureAuthentication(decrypter, "github-server", settings, log);
    verify(log).error("Ups github-server", null);
    ArgumentCaptor<SettingsDecryptionRequest> argument = ArgumentCaptor.forClass(SettingsDecryptionRequest.class);
    verify(decrypter).decrypt(argument.capture());
    List<Server> servers = ((DefaultSettingsDecryptionRequest) argument.getValue()).getServers();
    assertEquals(1, servers.size());
    assertSame(server, servers.get(0));
}
Also used : DefaultSettingsProblem(org.apache.maven.settings.building.DefaultSettingsProblem) 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) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) IssueManagement(org.apache.maven.model.IssueManagement) Settings(org.apache.maven.settings.Settings)

Example 19 with SettingsDecryptionResult

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

the class GitHubDownloader method configureAuthentication.

public void configureAuthentication(SettingsDecrypter decrypter, String githubAPIServerId, Settings settings, Log log) {
    boolean configured = false;
    List<Server> servers = settings.getServers();
    for (Server server : servers) {
        if (server.getId().equals(githubAPIServerId)) {
            SettingsDecryptionResult result = decrypter.decrypt(new DefaultSettingsDecryptionRequest(server));
            for (SettingsProblem problem : result.getProblems()) {
                log.error(problem.getMessage(), problem.getException());
            }
            server = result.getServer();
            String user = server.getUsername();
            String password = server.getPassword();
            this.client.setCredentials(user, password);
            configured = true;
            break;
        }
    }
    if (!configured) {
        log.warn("Can't find server id [" + githubAPIServerId + "] configured in githubAPIServerId.");
    }
}
Also used : Server(org.apache.maven.settings.Server) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 20 with SettingsDecryptionResult

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

the class AbstractDeployMojo method getProxy.

/**
 * Get proxy information for Maven 3.
 *
 * @param repository
 * @param settingsDecrypter
 * @return
 */
private ProxyInfo getProxy(Repository repository, SettingsDecrypter settingsDecrypter) {
    String protocol = repository.getProtocol();
    String url = repository.getUrl();
    getLog().debug("repository protocol " + protocol);
    String originalProtocol = protocol;
    // so we will check both
    if (StringUtils.equalsIgnoreCase("dav", protocol) && url.startsWith("dav:")) {
        url = url.substring(4);
        if (url.startsWith("http")) {
            try {
                URL urlSite = new URL(url);
                protocol = urlSite.getProtocol();
                getLog().debug("found dav protocol so transform to real transport protocol " + protocol);
            } catch (MalformedURLException e) {
                getLog().warn("fail to build URL with " + url);
            }
        }
    } else {
        getLog().debug("getProxy 'protocol': " + protocol);
    }
    if (mavenSession != null && protocol != null) {
        MavenExecutionRequest request = mavenSession.getRequest();
        if (request != null) {
            List<Proxy> proxies = request.getProxies();
            if (proxies != null) {
                for (Proxy proxy : proxies) {
                    if (proxy.isActive() && (protocol.equalsIgnoreCase(proxy.getProtocol()) || originalProtocol.equalsIgnoreCase(proxy.getProtocol()))) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
                        proxy = result.getProxy();
                        ProxyInfo proxyInfo = new ProxyInfo();
                        proxyInfo.setHost(proxy.getHost());
                        // so hackish for wagon the protocol is https for site dav:
                        // dav:https://dav.codehaus.org/mojo/
                        // proxy.getProtocol() );
                        proxyInfo.setType(protocol);
                        proxyInfo.setPort(proxy.getPort());
                        proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
                        proxyInfo.setUserName(proxy.getUsername());
                        proxyInfo.setPassword(proxy.getPassword());
                        getLog().debug("found proxyInfo " + ("host:port " + proxyInfo.getHost() + ":" + proxyInfo.getPort() + ", " + proxyInfo.getUserName()));
                        return proxyInfo;
                    }
                }
            }
        }
    }
    getLog().debug("getProxy 'protocol': " + protocol + " no ProxyInfo found");
    return null;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) MalformedURLException(java.net.MalformedURLException) Proxy(org.apache.maven.settings.Proxy) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) URL(java.net.URL)

Aggregations

SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)30 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)26 Server (org.apache.maven.settings.Server)13 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)12 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)10 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)6 MavenSession (org.apache.maven.execution.MavenSession)6 Proxy (org.apache.maven.settings.Proxy)6 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 Settings (org.apache.maven.settings.Settings)4 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 File (java.io.File)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2