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.");
}
}
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));
}
Aggregations