![JAR search and dependency download from the Maven repository](/logo.png)
com.sourceclear.plugins.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of srcclr-maven-plugin Show documentation
Show all versions of srcclr-maven-plugin Show documentation
The SRC:CLR Maven Plugin analyzes the dependencies of your project, both immediate and transitive, to
see if you are including any known security vulnerabilities through third-party packages in your
project.
/*
* © Copyright - SourceClear Inc
*/
package com.sourceclear.plugins;
import com.sourceclear.api.client.SourceClearClient;
import org.apache.maven.settings.Proxy;
import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.util.List;
import static java.net.Proxy.Type.HTTP;
/**
*
*/
public class Utils {
////////////////////////////////// Methods \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/**
* Sets the proxy for the sourceclear client
*
* @param clientBuilder the builder object of the sourceclear client
* @param proxies list of proxies configured in maven
*/
static void maybeSetProxy(SourceClearClient.Builder clientBuilder, List proxies) {
final Proxy proxy = findActiveProxy(proxies);
if (proxy == null) {
return;
}
String protocol = proxy.getProtocol();
if ("http".equals(protocol) || "https".equals(protocol)) {
java.net.Proxy javaNetProxy = new java.net.Proxy(HTTP, new InetSocketAddress(proxy.getHost(), proxy.getPort()));
if (proxy.getUsername() != null && proxy.getPassword() != null) {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxy.getUsername(), proxy.getPassword().toCharArray());
}
});
}
clientBuilder.withProxy(javaNetProxy);
}
}
/**
* Returns the first active proxy found in the list of proxies.
* @param proxies list of proxies configured in maven
* @return the active proxy
*/
private static Proxy findActiveProxy(List proxies) {
if (proxies == null) {
return null;
}
for (Proxy proxy : proxies) {
if (proxy.isActive()) {
return proxy;
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy