Search in sources :

Example 6 with SettingsProblem

use of org.apache.maven.settings.building.SettingsProblem in project karaf by apache.

the class MavenConfigurationSupport method readSettings.

/**
 * Reads on demand <code>settings.xml</code> file - without password decryption. Also
 * collects declared servers by ID.
 * @param settingsFile
 */
protected synchronized Settings readSettings(File settingsFile) throws SettingsBuildingException {
    if (!settingsFile.isFile() || !settingsFile.canRead()) {
        return null;
    }
    try {
        DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
        DefaultSettingsBuilder builder = factory.newInstance();
        SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
        request.setUserSettingsFile(settingsFile);
        SettingsBuildingResult result = builder.build(request);
        if (result.getProblems().size() > 0) {
            for (SettingsProblem problem : result.getProblems()) {
                System.err.println(problem);
            }
            return null;
        } else {
            Settings settings = result.getEffectiveSettings();
            if (settings.getServers() != null) {
                for (Server server : settings.getServers()) {
                    servers.put(server.getId(), server);
                }
            }
            return settings;
        }
    } catch (Throwable e) {
        System.err.println(e.getMessage());
        LOG.error(e.getMessage(), e);
        throw e;
    }
}
Also used : Server(org.apache.maven.settings.Server) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) DefaultSettingsBuilder(org.apache.maven.settings.building.DefaultSettingsBuilder) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) SettingsProblem(org.apache.maven.settings.building.SettingsProblem) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 7 with SettingsProblem

use of org.apache.maven.settings.building.SettingsProblem in project fabric8 by jboss-fuse.

the class MavenSettingsDecrypter method decrypt.

public SettingsDecryptionResult decrypt(SettingsDecryptionRequest request) {
    List<SettingsProblem> problems = new ArrayList<SettingsProblem>();
    List<Server> servers = new ArrayList<Server>();
    for (Server server : request.getServers()) {
        server = server.clone();
        servers.add(server);
        try {
            server.setPassword(decrypt(server.getPassword()));
        } catch (SecDispatcherException e) {
            problems.add(new DefaultSettingsProblem("Failed to decrypt password for server " + server.getId() + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
        }
        try {
            server.setPassphrase(decrypt(server.getPassphrase()));
        } catch (SecDispatcherException e) {
            problems.add(new DefaultSettingsProblem("Failed to decrypt passphrase for server " + server.getId() + ": " + e.getMessage(), Severity.ERROR, "server: " + server.getId(), -1, -1, e));
        }
    }
    List<Proxy> proxies = new ArrayList<Proxy>();
    for (Proxy proxy : request.getProxies()) {
        proxy = proxy.clone();
        proxies.add(proxy);
        try {
            proxy.setPassword(decrypt(proxy.getPassword()));
        } catch (SecDispatcherException e) {
            problems.add(new DefaultSettingsProblem("Failed to decrypt password for proxy " + proxy.getId() + ": " + e.getMessage(), Severity.ERROR, "proxy: " + proxy.getId(), -1, -1, e));
        }
    }
    return new MavenSettingsDecryptionResult(servers, proxies, problems);
}
Also used : DefaultSettingsProblem(org.apache.maven.settings.building.DefaultSettingsProblem) Proxy(org.apache.maven.settings.Proxy) Server(org.apache.maven.settings.Server) ArrayList(java.util.ArrayList) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) SettingsProblem(org.apache.maven.settings.building.SettingsProblem) DefaultSettingsProblem(org.apache.maven.settings.building.DefaultSettingsProblem)

Example 8 with SettingsProblem

use of org.apache.maven.settings.building.SettingsProblem 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 9 with SettingsProblem

use of org.apache.maven.settings.building.SettingsProblem 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

SettingsProblem (org.apache.maven.settings.building.SettingsProblem)9 Server (org.apache.maven.settings.Server)5 DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)4 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)4 SettingsBuildingResult (org.apache.maven.settings.building.SettingsBuildingResult)3 FileNotFoundException (java.io.FileNotFoundException)2 Path (java.nio.file.Path)2 CommandLine (org.apache.commons.cli.CommandLine)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 Proxy (org.apache.maven.settings.Proxy)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Settings (org.apache.maven.settings.Settings)1 DefaultSettingsBuilder (org.apache.maven.settings.building.DefaultSettingsBuilder)1 DefaultSettingsBuilderFactory (org.apache.maven.settings.building.DefaultSettingsBuilderFactory)1 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)1 DefaultSettingsProblem (org.apache.maven.settings.building.DefaultSettingsProblem)1 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)1 DefaultSettingsDecrypter (org.apache.maven.settings.crypto.DefaultSettingsDecrypter)1 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)1