Search in sources :

Example 6 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 7 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 8 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)8 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)7 Server (org.apache.maven.settings.Server)5 Settings (org.apache.maven.settings.Settings)3 IssueManagement (org.apache.maven.model.IssueManagement)2 Log (org.apache.maven.plugin.logging.Log)2 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)2 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Map (java.util.Map)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 Proxy (org.apache.maven.settings.Proxy)1 DefaultSettingsProblem (org.apache.maven.settings.building.DefaultSettingsProblem)1 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)1 ReleaseDescriptor (org.apache.maven.shared.release.config.ReleaseDescriptor)1 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)1