Search in sources :

Example 1 with ProxyConfiguration

use of hudson.ProxyConfiguration in project contrast-continuous-application-security-plugin by jenkinsci.

the class VulnerabilityTrendHelper method createSDK.

public static ContrastSDK createSDK(String username, String serviceKey, String apiKey, String teamServerUrl) {
    ContrastSDK contrastSDK;
    Jenkins jenkinsInstance = Jenkins.getInstance();
    ProxyConfiguration proxyConfig = null;
    if (jenkinsInstance != null) {
        proxyConfig = jenkinsInstance.proxy;
    }
    URL url = null;
    Proxy proxyToUse = Proxy.NO_PROXY;
    try {
        url = new URL(teamServerUrl);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    if (proxyConfig != null && url != null) {
        Proxy proxy = proxyConfig.createProxy(url.getHost());
        if (proxy != null && proxy.type() == Proxy.Type.HTTP) {
            proxyToUse = proxy;
        }
    }
    contrastSDK = new ContrastSDK(username, serviceKey, apiKey, teamServerUrl, proxyToUse);
    return contrastSDK;
}
Also used : Jenkins(jenkins.model.Jenkins) ContrastSDK(com.contrastsecurity.sdk.ContrastSDK) Proxy(java.net.Proxy) MalformedURLException(java.net.MalformedURLException) ProxyConfiguration(hudson.ProxyConfiguration) URL(java.net.URL)

Example 2 with ProxyConfiguration

use of hudson.ProxyConfiguration in project nodejs-plugin by jenkinsci.

the class NodeJSInstallerProxyTest method test_proxy_settings.

@Issue("JENKINS-29266")
@Test
public void test_proxy_settings() throws Exception {
    r.getInstance().proxy = new ProxyConfiguration(host, port, username, password);
    NodeJSInstaller installer = new NodeJSInstaller("test-id", "grunt", NodeJSInstaller.DEFAULT_NPM_PACKAGES_REFRESH_HOURS);
    EnvVars env = new EnvVars();
    Whitebox.invokeMethod(installer, "buildProxyEnvVars", env, log);
    assertThat(env.keySet(), hasItems("HTTP_PROXY", "HTTPS_PROXY"));
    assertThat(env.get("HTTP_PROXY"), is(expectedURL));
    assertThat(env.get("HTTPS_PROXY"), is(expectedURL));
    assertThat(env.keySet(), not(hasItem("NO_PROXY")));
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) EnvVars(hudson.EnvVars) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 3 with ProxyConfiguration

use of hudson.ProxyConfiguration in project nodejs-plugin by jenkinsci.

the class NodeJSInstallerProxyTest method test_no_proxy_settings.

@Test
public void test_no_proxy_settings() throws Exception {
    r.getInstance().proxy = new ProxyConfiguration(host, port, username, password, noProxy);
    NodeJSInstaller installer = new NodeJSInstaller("test-id", "grunt", NodeJSInstaller.DEFAULT_NPM_PACKAGES_REFRESH_HOURS);
    EnvVars env = new EnvVars();
    Whitebox.invokeMethod(installer, "buildProxyEnvVars", env, log);
    assertThat(env.keySet(), hasItems("HTTP_PROXY", "HTTPS_PROXY"));
    assertThat(env.get("NO_PROXY"), is("*.npm.org,registry.npm.org"));
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 4 with ProxyConfiguration

use of hudson.ProxyConfiguration in project jenkin-qtest-plugin by QASymphony.

the class HttpClientUtils method setHttpProxy.

private static void setHttpProxy(HttpClientBuilder httpClientBuilder, String hostUrl) {
    ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
    if (proxyConfig != null) {
        List<Pattern> proxyHostPatterns = proxyConfig.getNoProxyHostPatterns();
        if (isUrlMatchWithNoProxyHost(hostUrl, proxyHostPatterns) == true) {
            return;
        }
        HttpHost proxy = new HttpHost(proxyConfig.name, proxyConfig.port);
        String username = proxyConfig.getUserName();
        String password = proxyConfig.getPassword();
        Credentials credentials;
        if (username != null && StringUtils.isNotEmpty(username) == true) {
            credentials = new UsernamePasswordCredentials(username, password);
        } else {
            credentials = new UsernamePasswordCredentials("", "");
        }
        AuthScope authScope = new AuthScope(proxyConfig.name, proxyConfig.port);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(authScope, credentials);
        httpClientBuilder.setProxy(proxy).setDefaultCredentialsProvider(credsProvider).build();
    }
}
Also used : Pattern(java.util.regex.Pattern) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ProxyConfiguration(hudson.ProxyConfiguration) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 5 with ProxyConfiguration

use of hudson.ProxyConfiguration in project dependency-check-plugin by jenkinsci.

the class AbstractDependencyCheckBuilder method configureProxySettings.

void configureProxySettings(final Options options, final boolean isNvdProxyBypassed) {
    final ProxyConfiguration proxy = Jenkins.getInstance() != null ? Jenkins.getInstance().proxy : null;
    if (!isNvdProxyBypassed && proxy != null) {
        if (!StringUtils.isBlank(proxy.name)) {
            options.setProxyServer(proxy.name);
            options.setProxyPort(proxy.port);
        }
        if (!StringUtils.isBlank(proxy.getUserName())) {
            options.setProxyUsername(proxy.getUserName());
        }
        if (!StringUtils.isBlank(proxy.getPassword())) {
            options.setProxyPassword(proxy.getPassword());
        }
    }
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration)

Aggregations

ProxyConfiguration (hudson.ProxyConfiguration)11 Proxy (java.net.Proxy)5 URL (java.net.URL)5 Test (org.junit.Test)3 EnvVars (hudson.EnvVars)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 HttpHost (org.apache.http.HttpHost)2 ContrastSDK (com.contrastsecurity.sdk.ContrastSDK)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 KeenProject (io.keen.client.java.KeenProject)1 URI (java.net.URI)1 Pattern (java.util.regex.Pattern)1 Jenkins (jenkins.model.Jenkins)1 OkHttpClient (okhttp3.OkHttpClient)1 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1