Search in sources :

Example 11 with DefaultSettingsDecryptionRequest

use of org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getProxy.

private 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 12 with DefaultSettingsDecryptionRequest

use of org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest in project frontend-maven-plugin by eirslett.

the class MojoUtils method decryptServer.

static Server decryptServer(String serverId, MavenSession mavenSession, SettingsDecrypter decrypter) {
    if (StringUtils.isEmpty(serverId)) {
        return null;
    }
    Server server = mavenSession.getSettings().getServer(serverId);
    if (server != null) {
        synchronized (server) {
            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)

Example 13 with DefaultSettingsDecryptionRequest

use of org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest 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)

Aggregations

DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)13 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)13 Server (org.apache.maven.settings.Server)8 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)4 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)4 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)3 Proxy (org.apache.maven.settings.Proxy)3 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)3 MavenSession (org.apache.maven.execution.MavenSession)2 IssueManagement (org.apache.maven.model.IssueManagement)2 Log (org.apache.maven.plugin.logging.Log)2 Settings (org.apache.maven.settings.Settings)2 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)2 Field (java.lang.reflect.Field)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Map (java.util.Map)1 DefaultSettingsProblem (org.apache.maven.settings.building.DefaultSettingsProblem)1 DefaultSettingsDecrypter (org.apache.maven.settings.crypto.DefaultSettingsDecrypter)1 ReleaseDescriptor (org.apache.maven.shared.release.config.ReleaseDescriptor)1