Search in sources :

Example 21 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 22 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)

Example 23 with SettingsDecryptionResult

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

the class MavenSettingsServerCredentials method inferAuth.

/**
 * Retrieves credentials for {@code registry} from Maven settings.
 *
 * @param registry the registry
 * @return the auth info for the registry, or {@link Optional#empty} if none could be retrieved
 */
@Override
public Optional<AuthProperty> inferAuth(String registry) throws InferredAuthException {
    Server server = getServerFromMavenSettings(registry);
    if (server == null) {
        return Optional.empty();
    }
    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = decrypter.decrypt(request);
    // If there are any ERROR or FATAL problems reported, then decryption failed.
    for (SettingsProblem problem : result.getProblems()) {
        if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
            throw new InferredAuthException("Unable to decrypt server(" + registry + ") info from settings.xml: " + problem);
        }
    }
    Server resultServer = result.getServer();
    String username = resultServer.getUsername();
    String password = resultServer.getPassword();
    return Optional.of(new AuthProperty() {

        @Override
        public String getUsername() {
            return username;
        }

        @Override
        public String getPassword() {
            return password;
        }

        @Override
        public String getAuthDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getUsernameDescriptor() {
            return CREDENTIAL_SOURCE;
        }

        @Override
        public String getPasswordDescriptor() {
            return CREDENTIAL_SOURCE;
        }
    });
}
Also used : InferredAuthException(com.google.cloud.tools.jib.plugins.common.InferredAuthException) AuthProperty(com.google.cloud.tools.jib.plugins.common.AuthProperty) Server(org.apache.maven.settings.Server) 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)

Example 24 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project tycho by eclipse.

the class OSGiProxyConfigurator method setProxy.

private void setProxy(ProxyServiceFacade proxyService, Proxy proxy) {
    String protocol = proxy.getProtocol();
    if (isSupportedProtocol(protocol)) {
        SettingsDecryptionResult result = decrypter.decryptAndLogProblems(proxy);
        proxy = result.getProxy();
        logger.debug("Configuring proxy for protocol " + protocol + ": host=" + proxy.getHost() + ", port=" + proxy.getPort() + ", nonProxyHosts=" + proxy.getNonProxyHosts());
        proxyService.configureProxy(protocol, proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts());
    } else {
        logger.debug("Ignoring proxy configuration for unsupported protocol: '" + protocol + "'");
    }
}
Also used : SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult)

Example 25 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project tycho by eclipse.

the class SettingsDecrypterHelper method decryptAndLogProblems.

private SettingsDecryptionResult decryptAndLogProblems(SettingsDecryptionRequest decryptRequest) {
    SettingsDecryptionResult result = decrypter.decrypt(decryptRequest);
    logProblems(result);
    return result;
}
Also used : SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult)

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