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