Search in sources :

Example 16 with ProxyConfiguration

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

the class KeenAnalyticsImpl method doTrack.

@Override
protected void doTrack(String name, Map<String, Object> allProps) {
    // Always set the proxy in case its configuration has changed after startup
    ProxyConfiguration proxyConfig = Jenkins.get().proxy;
    Proxy proxy = proxyConfig == null ? null : proxyConfig.createProxy(null);
    CLIENT.setProxy(proxy);
    // Ensure that we are using the right project info
    KeenProject project = KeenConfiguration.get().project();
    CLIENT.setDefaultProject(project);
    // Send the event
    CLIENT.addEventAsync(name, allProps);
}
Also used : Proxy(java.net.Proxy) ProxyConfiguration(hudson.ProxyConfiguration) KeenProject(io.keen.client.java.KeenProject)

Example 17 with ProxyConfiguration

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

the class HttpRequest method connect.

HttpURLConnection connect() throws IOException {
    URL apiUrl = new URL(url);
    ProxyConfiguration proxyConfig = Jenkins.get().proxy;
    Proxy proxy = proxyConfig == null ? Proxy.NO_PROXY : proxyConfig.createProxy(apiUrl.getHost());
    HttpURLConnection connect = (HttpURLConnection) apiUrl.openConnection(proxy);
    if (authorization != null) {
        connect.setRequestProperty("Authorization", authorization);
    }
    connect.setRequestMethod(method);
    connect.setRequestProperty("Accept-Encoding", "gzip");
    connect.setDoOutput(true);
    connect.setRequestProperty("Content-type", contentType);
    connect.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(10));
    connect.setReadTimeout((int) TimeUnit.SECONDS.toMillis(10));
    connect.connect();
    return connect;
}
Also used : Proxy(java.net.Proxy) ProxyConfiguration(hudson.ProxyConfiguration) HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL)

Example 18 with ProxyConfiguration

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

the class GitHubFactory method connect.

/**
 * Connect to github with the correct limit handlers
 * @param accessToken to authorize
 * @param endpointUri endpoint to connect to
 * @return GitHub
 * @throws IOException if GitHub could not be constructed
 */
public static GitHub connect(String accessToken, String endpointUri) throws IOException {
    URL apiUrl = new URL(endpointUri);
    ProxyConfiguration proxyConfig = Jenkins.get().proxy;
    Proxy proxy = proxyConfig == null ? Proxy.NO_PROXY : proxyConfig.createProxy(apiUrl.getHost());
    OkHttpClient.Builder builder = baseClient.newBuilder().proxy(proxy);
    return new GitHubBuilder().withOAuthToken(accessToken).withConnector(new OkHttpConnector(builder.build())).withRateLimitHandler(RateLimitHandlerImpl.INSTANCE).withAbuseLimitHandler(AbuseLimitHandlerImpl.INSTANCE).withProxy(proxy).withEndpoint(endpointUri).build();
}
Also used : Proxy(java.net.Proxy) ProxyConfiguration(hudson.ProxyConfiguration) OkHttpClient(okhttp3.OkHttpClient) OkHttpConnector(org.kohsuke.github.extras.okhttp3.OkHttpConnector) GitHubBuilder(org.kohsuke.github.GitHubBuilder) URL(java.net.URL)

Example 19 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;
    LOG.log(Level.INFO, "-- Proxy info: " + ReflectionToStringBuilder.toString(proxyConfig));
    if (proxyConfig != null) {
        List<Pattern> proxyHostPatterns = proxyConfig.getNoProxyHostPatterns();
        LOG.log(Level.INFO, "-- No proxy host info: " + Arrays.toString(proxyHostPatterns.toArray()));
        if (isUrlMatchWithNoProxyHost(hostUrl, proxyHostPatterns)) {
            LOG.log(Level.INFO, "-- No proxy host has url: " + hostUrl);
            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.useSystemProperties();
        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 20 with ProxyConfiguration

use of hudson.ProxyConfiguration in project configuration-as-code-plugin by jenkinsci.

the class ProxyConfiguratorTest method shouldNotWritePasswordToLog.

@Test
@Env(name = "PROXY_USER", value = "proxy_user")
@Env(name = "PROXY_PASSWORD", value = "proxy_password")
@ConfiguredWithCode("ProxyWithSecrets.yml")
// Fixed in 1.20
@Issue("SECURITY-1303")
public void shouldNotWritePasswordToLog() {
    ProxyConfiguration proxy = j.jenkins.proxy;
    assertEquals(proxy.getUserName(), "proxy_user");
    assertThat(proxy.getSecretPassword(), hasPlainText("proxy_password"));
    // Check logs
    assertLogContains(logging, "secretPassword");
    assertNotInLog(logging, "proxy_password");
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode) Env(io.jenkins.plugins.casc.misc.Env)

Aggregations

ProxyConfiguration (hudson.ProxyConfiguration)42 Test (org.junit.Test)19 Jenkins (jenkins.model.Jenkins)11 HttpHost (org.apache.http.HttpHost)10 Proxy (java.net.Proxy)9 URL (java.net.URL)5 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)5 CredentialsProvider (org.apache.http.client.CredentialsProvider)5 HttpClientOptions (com.atlassian.httpclient.api.factory.HttpClientOptions)4 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 AuthScope (org.apache.http.auth.AuthScope)4 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)4 Response (com.atlassian.httpclient.api.Response)3 EnvVars (hudson.EnvVars)3 Pattern (java.util.regex.Pattern)3 HttpClient (org.apache.commons.httpclient.HttpClient)3 Issue (org.jvnet.hudson.test.Issue)3 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2