Search in sources :

Example 6 with DefaultSettingsDecryptionRequest

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

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

the class GitHubDownloaderTestCase method testConfigureAuthenticationWithProblems.

public void testConfigureAuthenticationWithProblems() throws Exception {
    IssueManagement issueManagement = newGitHubIssueManagement();
    GitHubDownloader gitHubDownloader = newGitHubDownloader(issueManagement);
    Settings settings = new Settings();
    Server server = newServer("github-server");
    settings.addServer(server);
    SettingsDecrypter decrypter = mock(SettingsDecrypter.class);
    SettingsDecryptionResult result = mock(SettingsDecryptionResult.class);
    Log log = mock(Log.class);
    when(result.getProblems()).thenReturn(Arrays.<SettingsProblem>asList(new DefaultSettingsProblem("Ups " + server.getId(), Severity.ERROR, null, -1, -1, null)));
    when(result.getServer()).thenReturn(server);
    when(decrypter.decrypt(any(SettingsDecryptionRequest.class))).thenReturn(result);
    gitHubDownloader.configureAuthentication(decrypter, "github-server", settings, log);
    verify(log).error("Ups github-server", null);
    ArgumentCaptor<SettingsDecryptionRequest> argument = ArgumentCaptor.forClass(SettingsDecryptionRequest.class);
    verify(decrypter).decrypt(argument.capture());
    List<Server> servers = ((DefaultSettingsDecryptionRequest) argument.getValue()).getServers();
    assertEquals(1, servers.size());
    assertSame(server, servers.get(0));
}
Also used : DefaultSettingsProblem(org.apache.maven.settings.building.DefaultSettingsProblem) Server(org.apache.maven.settings.Server) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) Log(org.apache.maven.plugin.logging.Log) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionRequest(org.apache.maven.settings.crypto.SettingsDecryptionRequest) IssueManagement(org.apache.maven.model.IssueManagement) Settings(org.apache.maven.settings.Settings)

Aggregations

DefaultSettingsDecryptionRequest (org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest)7 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)7 Server (org.apache.maven.settings.Server)5 IssueManagement (org.apache.maven.model.IssueManagement)2 Log (org.apache.maven.plugin.logging.Log)2 Settings (org.apache.maven.settings.Settings)2 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)2 SettingsDecryptionRequest (org.apache.maven.settings.crypto.SettingsDecryptionRequest)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Map (java.util.Map)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 Proxy (org.apache.maven.settings.Proxy)1 DefaultSettingsProblem (org.apache.maven.settings.building.DefaultSettingsProblem)1 SettingsProblem (org.apache.maven.settings.building.SettingsProblem)1 ReleaseDescriptor (org.apache.maven.shared.release.config.ReleaseDescriptor)1 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)1