Search in sources :

Example 31 with SettingsDecryptionResult

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

the class DefaultWagonManager method getProxy.

public ProxyInfo getProxy(String protocol) {
    MavenSession session = legacySupport.getSession();
    if (session != null && protocol != null) {
        MavenExecutionRequest request = session.getRequest();
        if (request != null) {
            List<Proxy> proxies = request.getProxies();
            if (proxies != null) {
                for (Proxy proxy : proxies) {
                    if (proxy.isActive() && protocol.equalsIgnoreCase(proxy.getProtocol())) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
                        proxy = result.getProxy();
                        ProxyInfo proxyInfo = new ProxyInfo();
                        proxyInfo.setHost(proxy.getHost());
                        proxyInfo.setType(proxy.getProtocol());
                        proxyInfo.setPort(proxy.getPort());
                        proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
                        proxyInfo.setUserName(proxy.getUsername());
                        proxyInfo.setPassword(proxy.getPassword());
                        return proxyInfo;
                    }
                }
            }
        }
    }
    return null;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) 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)

Example 32 with SettingsDecryptionResult

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

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

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project quarkus by quarkusio.

the class BootstrapMavenContext method newRepositorySystemSession.

private DefaultRepositorySystemSession newRepositorySystemSession() throws BootstrapMavenException {
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    final Settings settings = getEffectiveSettings();
    final List<Mirror> mirrors = settings.getMirrors();
    if (mirrors != null && !mirrors.isEmpty()) {
        final boolean isBlockedMethodAvailable = mirrorIsBlockedMethodAvailable();
        final DefaultMirrorSelector ms = new DefaultMirrorSelector();
        for (Mirror m : mirrors) {
            if (isBlockedMethodAvailable) {
                ms.add(m.getId(), m.getUrl(), m.getLayout(), false, m.isBlocked(), m.getMirrorOf(), m.getMirrorOfLayouts());
            } else {
                // Maven pre-3.8.x
                ms.add(m.getId(), m.getUrl(), m.getLayout(), false, m.getMirrorOf(), m.getMirrorOfLayouts());
            }
        }
        session.setMirrorSelector(ms);
    }
    final String localRepoPath = getLocalRepo();
    session.setLocalRepositoryManager(getRepositorySystem().newLocalRepositoryManager(session, new LocalRepository(localRepoPath)));
    session.setOffline(isOffline());
    final BootstrapMavenOptions mvnArgs = getCliOptions();
    if (!mvnArgs.isEmpty()) {
        if (mvnArgs.hasOption(BootstrapMavenOptions.SUPRESS_SNAPSHOT_UPDATES)) {
            session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER);
        } else if (mvnArgs.hasOption(BootstrapMavenOptions.UPDATE_SNAPSHOTS)) {
            session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
        }
        if (mvnArgs.hasOption(BootstrapMavenOptions.CHECKSUM_FAILURE_POLICY)) {
            session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);
        } else if (mvnArgs.hasOption(BootstrapMavenOptions.CHECKSUM_WARNING_POLICY)) {
            session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
        }
    }
    final DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
    decrypt.setProxies(settings.getProxies());
    decrypt.setServers(settings.getServers());
    final SettingsDecryptionResult decrypted = new SettingsDecrypterImpl().decrypt(decrypt);
    if (!decrypted.getProblems().isEmpty() && log.isDebugEnabled()) {
        // this is how maven handles these
        for (SettingsProblem p : decrypted.getProblems()) {
            log.debug(p.getMessage(), p.getException());
        }
    }
    final DefaultProxySelector proxySelector = new DefaultProxySelector();
    for (org.apache.maven.settings.Proxy p : decrypted.getProxies()) {
        if (p.isActive()) {
            proxySelector.add(toAetherProxy(p), p.getNonProxyHosts());
        }
    }
    session.setProxySelector(proxySelector);
    final Map<Object, Object> configProps = new LinkedHashMap<>(session.getConfigProperties());
    configProps.put(ConfigurationProperties.USER_AGENT, getUserAgent());
    configProps.put(ConfigurationProperties.INTERACTIVE, settings.isInteractiveMode());
    final DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
    for (Server server : decrypted.getServers()) {
        AuthenticationBuilder authBuilder = new AuthenticationBuilder();
        authBuilder.addUsername(server.getUsername()).addPassword(server.getPassword());
        authBuilder.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
        authSelector.add(server.getId(), authBuilder.build());
        if (server.getConfiguration() != null) {
            Xpp3Dom dom = (Xpp3Dom) server.getConfiguration();
            for (int i = dom.getChildCount() - 1; i >= 0; i--) {
                Xpp3Dom child = dom.getChild(i);
                if ("wagonProvider".equals(child.getName())) {
                    dom.removeChild(i);
                }
            }
            XmlPlexusConfiguration config = new XmlPlexusConfiguration(dom);
            configProps.put("aether.connector.wagon.config." + server.getId(), config);
        }
        configProps.put("aether.connector.perms.fileMode." + server.getId(), server.getFilePermissions());
        configProps.put("aether.connector.perms.dirMode." + server.getId(), server.getDirectoryPermissions());
    }
    session.setAuthenticationSelector(authSelector);
    session.setConfigProperties(configProps);
    if (session.getCache() == null) {
        session.setCache(new DefaultRepositoryCache());
    }
    if (workspace != null) {
        session.setWorkspaceReader(workspace);
    }
    if (session.getTransferListener() == null && artifactTransferLogging) {
        TransferListener transferListener;
        if (mvnArgs.hasOption(BootstrapMavenOptions.NO_TRANSFER_PROGRESS)) {
            transferListener = new QuietMavenTransferListener();
        } else if (mvnArgs.hasOption(BootstrapMavenOptions.BATCH_MODE)) {
            transferListener = new BatchModeMavenTransferListener(System.out);
        } else {
            transferListener = new ConsoleMavenTransferListener(System.out, true);
        }
        session.setTransferListener(transferListener);
    }
    return session;
}
Also used : ConsoleMavenTransferListener(org.apache.maven.cli.transfer.ConsoleMavenTransferListener) QuietMavenTransferListener(org.apache.maven.cli.transfer.QuietMavenTransferListener) TransferListener(org.eclipse.aether.transfer.TransferListener) BatchModeMavenTransferListener(org.apache.maven.cli.transfer.BatchModeMavenTransferListener) Server(org.apache.maven.settings.Server) DefaultProxySelector(org.eclipse.aether.util.repository.DefaultProxySelector) SettingsProblem(org.apache.maven.settings.building.SettingsProblem) LinkedHashMap(java.util.LinkedHashMap) BatchModeMavenTransferListener(org.apache.maven.cli.transfer.BatchModeMavenTransferListener) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultAuthenticationSelector(org.eclipse.aether.util.repository.DefaultAuthenticationSelector) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) QuietMavenTransferListener(org.apache.maven.cli.transfer.QuietMavenTransferListener) Settings(org.apache.maven.settings.Settings) ConsoleMavenTransferListener(org.apache.maven.cli.transfer.ConsoleMavenTransferListener) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultMirrorSelector(org.eclipse.aether.util.repository.DefaultMirrorSelector) DefaultRepositoryCache(org.eclipse.aether.DefaultRepositoryCache) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) Mirror(org.apache.maven.settings.Mirror) BootstrapMavenOptions(io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions)

Example 34 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project flutter-maven-plugin by BlackBeltTechnology.

the class MojoUtils method decryptProxy.

private static Proxy decryptProxy(Proxy proxy, SettingsDecrypter decrypter) {
    final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(proxy);
    SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
    return decryptedResult.getProxy();
}
Also used : DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult)

Example 35 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project flutter-maven-plugin by BlackBeltTechnology.

the class MojoUtils method decryptServer.

public static Server decryptServer(String serverId, MavenSession mavenSession, SettingsDecrypter decrypter) {
    if (StringUtils.isEmpty(serverId)) {
        return null;
    }
    Server server = mavenSession.getSettings().getServer(serverId);
    if (server != null) {
        final DefaultSettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(server);
        SettingsDecryptionResult decryptedResult = decrypter.decrypt(decryptionRequest);
        return decryptedResult.getServer();
    } else {
        LOGGER.warn("Could not find server '" + serverId + "' in settings.xml");
        return null;
    }
}
Also used : Server(org.apache.maven.settings.Server) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) 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