Search in sources :

Example 26 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 27 with SettingsDecryptionResult

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

the class MavenConfigurationSupport method decryptSettings.

/**
 * <p>Decrypts passwords inside correctly read <code>settings.xml</code>. Also tries to decrypt master password.</p>
 * <p>Not called implicitly for each action invocation.</p>
 */
private void decryptSettings() throws Exception {
    if (mavenSecuritySettings != null && mavenSettings != null) {
        masterPassword = cipher.decryptDecorated(mavenSecuritySettings.getMaster(), masterMasterPassword);
        DefaultSecDispatcher dispatcher = new DefaultSecDispatcher();
        DefaultSettingsDecrypter decrypter = new DefaultSettingsDecrypter(new DefaultSecDispatcher());
        try {
            dispatcher.setConfigurationFile(securitySettings.value.getAbsolutePath());
            Field f = dispatcher.getClass().getDeclaredField("_cipher");
            f.setAccessible(true);
            f.set(dispatcher, cipher);
            f = decrypter.getClass().getDeclaredField("securityDispatcher");
            f.setAccessible(true);
            f.set(decrypter, dispatcher);
            DefaultSettingsDecryptionRequest req = new DefaultSettingsDecryptionRequest(mavenSettings);
            SettingsDecryptionResult res = decrypter.decrypt(req);
            if (res.getProblems() != null && res.getProblems().size() > 0) {
                for (SettingsProblem sp : res.getProblems()) {
                    System.err.println(sp);
                }
            }
            for (Proxy proxy : res.getProxies()) {
                if (!cipher.isEncryptedString(proxy.getPassword())) {
                    proxyPasswords.put(proxy.getId(), proxy.getPassword());
                }
            }
            for (Server server : res.getServers()) {
                if (!cipher.isEncryptedString(server.getPassword())) {
                    serverPasswords.put(server.getId(), server.getPassword());
                }
            }
        } catch (Throwable t) {
            LOG.warn("Can't decrypt " + securitySettings.value, t);
        }
    }
}
Also used : Field(java.lang.reflect.Field) Proxy(org.apache.maven.settings.Proxy) Server(org.apache.maven.settings.Server) DefaultSettingsDecrypter(org.apache.maven.settings.crypto.DefaultSettingsDecrypter) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) DefaultSecDispatcher(org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher) SettingsProblem(org.apache.maven.settings.building.SettingsProblem)

Example 28 with SettingsDecryptionResult

use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project decrypt-maven-plugin by davidmoten.

the class DecryptMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Server server = null;
    for (Server s : settings.getServers()) {
        if (s.getId().equals(serverId)) {
            server = s;
        }
    }
    if (server == null) {
        throw new MojoExecutionException("serverId not found in settings: " + serverId);
    } else {
        SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
        SettingsDecryptionResult result = decrypter.decrypt(request);
        String password = result.getServer().getPassword();
        try {
            outputFile.getParentFile().mkdirs();
            Files.write(outputFile.toPath(), password.getBytes(Charset.forName("UTF-8")));
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}
Also used : Server(org.apache.maven.settings.Server) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) 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) IOException(java.io.IOException)

Example 29 with SettingsDecryptionResult

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

the class LegacyRepositorySystem method injectProxy.

public void injectProxy(List<ArtifactRepository> repositories, List<org.apache.maven.settings.Proxy> proxies) {
    if (repositories != null) {
        for (ArtifactRepository repository : repositories) {
            org.apache.maven.settings.Proxy proxy = getProxy(repository, proxies);
            if (proxy != null) {
                SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(proxy);
                SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
                proxy = result.getProxy();
                if (logger.isDebugEnabled()) {
                    for (SettingsProblem problem : result.getProblems()) {
                        logger.debug(problem.getMessage(), problem.getException());
                    }
                }
                Proxy p = new Proxy();
                p.setHost(proxy.getHost());
                p.setProtocol(proxy.getProtocol());
                p.setPort(proxy.getPort());
                p.setNonProxyHosts(proxy.getNonProxyHosts());
                p.setUserName(proxy.getUsername());
                p.setPassword(proxy.getPassword());
                repository.setProxy(p);
            } else {
                repository.setProxy(null);
            }
        }
    }
}
Also used : Proxy(org.apache.maven.repository.Proxy) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) LocalArtifactRepository(org.apache.maven.repository.LocalArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DelegatingLocalArtifactRepository(org.apache.maven.repository.DelegatingLocalArtifactRepository) 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 30 with SettingsDecryptionResult

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

the class LegacyRepositorySystem method injectAuthentication.

public void injectAuthentication(List<ArtifactRepository> repositories, List<Server> servers) {
    if (repositories != null) {
        Map<String, Server> serversById = new HashMap<>();
        if (servers != null) {
            for (Server server : servers) {
                if (!serversById.containsKey(server.getId())) {
                    serversById.put(server.getId(), server);
                }
            }
        }
        for (ArtifactRepository repository : repositories) {
            Server server = serversById.get(repository.getId());
            if (server != null) {
                SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
                SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
                server = result.getServer();
                if (logger.isDebugEnabled()) {
                    for (SettingsProblem problem : result.getProblems()) {
                        logger.debug(problem.getMessage(), problem.getException());
                    }
                }
                Authentication authentication = new Authentication(server.getUsername(), server.getPassword());
                authentication.setPrivateKey(server.getPrivateKey());
                authentication.setPassphrase(server.getPassphrase());
                repository.setAuthentication(authentication);
            } else {
                repository.setAuthentication(null);
            }
        }
    }
}
Also used : Server(org.apache.maven.settings.Server) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Authentication(org.apache.maven.artifact.repository.Authentication) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) LocalArtifactRepository(org.apache.maven.repository.LocalArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DelegatingLocalArtifactRepository(org.apache.maven.repository.DelegatingLocalArtifactRepository) 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)

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