use of org.apache.maven.settings.crypto.SettingsDecryptionResult 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.SettingsDecryptionResult in project maven-plugins by apache.
the class AbstractDeployMojo method getProxy.
/**
* Get proxy information for Maven 3.
*
* @param repository
* @param settingsDecrypter
* @return
*/
private ProxyInfo getProxy(Repository repository, SettingsDecrypter settingsDecrypter) {
String protocol = repository.getProtocol();
String url = repository.getUrl();
getLog().debug("repository protocol " + protocol);
String originalProtocol = protocol;
// so we will check both
if (StringUtils.equalsIgnoreCase("dav", protocol) && url.startsWith("dav:")) {
url = url.substring(4);
if (url.startsWith("http")) {
try {
URL urlSite = new URL(url);
protocol = urlSite.getProtocol();
getLog().debug("found dav protocol so transform to real transport protocol " + protocol);
} catch (MalformedURLException e) {
getLog().warn("fail to build URL with " + url);
}
}
} else {
getLog().debug("getProxy 'protocol': " + protocol);
}
if (mavenSession != null && protocol != null) {
MavenExecutionRequest request = mavenSession.getRequest();
if (request != null) {
List<Proxy> proxies = request.getProxies();
if (proxies != null) {
for (Proxy proxy : proxies) {
if (proxy.isActive() && (protocol.equalsIgnoreCase(proxy.getProtocol()) || originalProtocol.equalsIgnoreCase(proxy.getProtocol()))) {
SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
proxy = result.getProxy();
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost(proxy.getHost());
// so hackish for wagon the protocol is https for site dav:
// dav:https://dav.codehaus.org/mojo/
// proxy.getProtocol() );
proxyInfo.setType(protocol);
proxyInfo.setPort(proxy.getPort());
proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
proxyInfo.setUserName(proxy.getUsername());
proxyInfo.setPassword(proxy.getPassword());
getLog().debug("found proxyInfo " + ("host:port " + proxyInfo.getHost() + ":" + proxyInfo.getPort() + ", " + proxyInfo.getUserName()));
return proxyInfo;
}
}
}
}
}
getLog().debug("getProxy 'protocol': " + protocol + " no ProxyInfo found");
return null;
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project jib by google.
the class MavenSettingsServerCredentials method inferAuth.
/**
* Retrieves credentials for {@code registry} from Maven settings.
*
* @param registry the registry
* @return the auth info for the registry, or {@link Optional#empty} if none could be retrieved
*/
@Override
public Optional<AuthProperty> inferAuth(String registry) throws InferredAuthException {
Server server = getServerFromMavenSettings(registry);
if (server == null) {
return Optional.empty();
}
SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
SettingsDecryptionResult result = decrypter.decrypt(request);
// If there are any ERROR or FATAL problems reported, then decryption failed.
for (SettingsProblem problem : result.getProblems()) {
if (problem.getSeverity() == SettingsProblem.Severity.ERROR || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
throw new InferredAuthException("Unable to decrypt server(" + registry + ") info from settings.xml: " + problem);
}
}
Server resultServer = result.getServer();
String username = resultServer.getUsername();
String password = resultServer.getPassword();
return Optional.of(new AuthProperty() {
@Override
public String getUsername() {
return username;
}
@Override
public String getPassword() {
return password;
}
@Override
public String getAuthDescriptor() {
return CREDENTIAL_SOURCE;
}
@Override
public String getUsernameDescriptor() {
return CREDENTIAL_SOURCE;
}
@Override
public String getPasswordDescriptor() {
return CREDENTIAL_SOURCE;
}
});
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project tycho by eclipse.
the class OSGiProxyConfigurator method setProxy.
private void setProxy(ProxyServiceFacade proxyService, Proxy proxy) {
String protocol = proxy.getProtocol();
if (isSupportedProtocol(protocol)) {
SettingsDecryptionResult result = decrypter.decryptAndLogProblems(proxy);
proxy = result.getProxy();
logger.debug("Configuring proxy for protocol " + protocol + ": host=" + proxy.getHost() + ", port=" + proxy.getPort() + ", nonProxyHosts=" + proxy.getNonProxyHosts());
proxyService.configureProxy(protocol, proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts());
} else {
logger.debug("Ignoring proxy configuration for unsupported protocol: '" + protocol + "'");
}
}
use of org.apache.maven.settings.crypto.SettingsDecryptionResult in project tycho by eclipse.
the class SettingsDecrypterHelper method decryptAndLogProblems.
private SettingsDecryptionResult decryptAndLogProblems(SettingsDecryptionRequest decryptRequest) {
SettingsDecryptionResult result = decrypter.decrypt(decryptRequest);
logProblems(result);
return result;
}
Aggregations