use of com.hp.octane.integrations.dto.configuration.CIProxyConfiguration in project octane-gitlab-service by MicroFocus.
the class OctaneServices method getProxyConfiguration.
// @Override
// public File getAllowedOctaneStorage() {
// File sdkStorage = new File("sdk_storage");
// boolean available = sdkStorage.exists();
// if (!available) {
// available = sdkStorage.mkdirs();
// }
// return available ? sdkStorage : null;
// }
@Override
public CIProxyConfiguration getProxyConfiguration(URL targetUrl) {
try {
CIProxyConfiguration result = null;
if (ProxyHelper.isProxyNeeded(applicationSettings, targetUrl)) {
log.debug("proxy is required for host " + targetUrl);
ConfigStructure config = applicationSettings.getConfig();
String protocol = targetUrl.getProtocol();
URL proxyUrl = new URL(config.getProxyField(protocol, "proxyUrl"));
String proxyPassword = config.getProxyField(protocol, "proxyPassword");
if (proxyPassword != null && proxyPassword.startsWith(PREFIX)) {
try {
proxyPassword = PasswordEncryption.decrypt(proxyPassword.substring(PREFIX.length()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
result = dtoFactory.newDTO(CIProxyConfiguration.class).setHost(proxyUrl.getHost()).setPort(proxyUrl.getPort()).setUsername(config.getProxyField(protocol, "proxyUser")).setPassword(proxyPassword);
}
return result;
} catch (Exception e) {
log.warn("Failed to return the proxy configuration, using null as default.", e);
return null;
}
}
use of com.hp.octane.integrations.dto.configuration.CIProxyConfiguration in project octane-ci-java-sdk by MicroFocus.
the class GeneralRestClient method createHttpContext.
private HttpClientContext createHttpContext(String requestUrl, int requestTimeoutSec) {
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(new BasicCookieStore());
// prepare request config
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD);
// configure proxy if needed
CIProxyConfiguration proxyConfiguration = CIPluginSDKUtils.getProxyConfiguration(requestUrl, null);
if (proxyConfiguration != null) {
HttpHost proxyHost = new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort());
if (proxyConfiguration.getUsername() != null && !proxyConfiguration.getUsername().isEmpty()) {
AuthScope authScope = new AuthScope(proxyHost);
Credentials credentials = new UsernamePasswordCredentials(proxyConfiguration.getUsername(), proxyConfiguration.getPassword());
CredentialsProvider credentialsProvider = new SystemDefaultCredentialsProvider();
credentialsProvider.setCredentials(authScope, credentials);
context.setCredentialsProvider(credentialsProvider);
}
requestConfigBuilder.setProxy(proxyHost);
}
// set timeout if needed
if (requestTimeoutSec > 0) {
int timeoutMs = requestTimeoutSec * 1000;
requestConfigBuilder.setConnectTimeout(timeoutMs).setConnectionRequestTimeout(timeoutMs).setSocketTimeout(timeoutMs);
}
context.setRequestConfig(requestConfigBuilder.build());
authentication.onCreateContext(context);
return context;
}
use of com.hp.octane.integrations.dto.configuration.CIProxyConfiguration in project octane-ci-java-sdk by MicroFocus.
the class OctaneRestClientImpl method createHttpContext.
private HttpClientContext createHttpContext(String requestUrl, int requestTimeoutSec, boolean isLoginRequest) {
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(new BasicCookieStore());
// add security token if needed
if (!isLoginRequest) {
context.getCookieStore().addCookie(LWSSO_TOKEN);
}
// prepare request config
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD);
// configure proxy if needed
CIProxyConfiguration proxyConfiguration = CIPluginSDKUtils.getProxyConfiguration(requestUrl, configurer);
if (proxyConfiguration != null) {
logger.debug(configurer.octaneConfiguration.getLocationForLog() + "proxy will be used with the following setup: " + proxyConfiguration);
HttpHost proxyHost = new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort());
if (proxyConfiguration.getUsername() != null && !proxyConfiguration.getUsername().isEmpty()) {
AuthScope authScope = new AuthScope(proxyHost);
Credentials credentials = new UsernamePasswordCredentials(proxyConfiguration.getUsername(), proxyConfiguration.getPassword());
CredentialsProvider credentialsProvider = new SystemDefaultCredentialsProvider();
credentialsProvider.setCredentials(authScope, credentials);
context.setCredentialsProvider(credentialsProvider);
}
requestConfigBuilder.setProxy(proxyHost);
}
// set timeout if needed
if (requestTimeoutSec > 0) {
int timeoutMs = requestTimeoutSec * 1000;
requestConfigBuilder.setConnectTimeout(timeoutMs).setConnectionRequestTimeout(timeoutMs).setSocketTimeout(timeoutMs);
}
context.setRequestConfig(requestConfigBuilder.build());
return context;
}
use of com.hp.octane.integrations.dto.configuration.CIProxyConfiguration in project octane-ci-java-sdk by MicroFocus.
the class FODConnector method initConnection.
public void initConnection(OctaneSDK.SDKServicesConfigurer configurer) {
logger.debug("init FOD connector");
try {
CIProxyConfiguration proxyConfiguration = configurer.pluginServices.getProxyConfiguration(new URL(this.fodConfig.authURL));
if (proxyConfiguration != null) {
logger.warn("FOD connection needs proxy");
HttpClientBuilder clientBuilder = HttpClients.custom();
String proxyHost = proxyConfiguration.getHost();
Integer proxyPortNumber = proxyConfiguration.getPort();
clientBuilder.setProxy(new HttpHost(proxyHost, proxyPortNumber));
httpClient = clientBuilder.build();
} else {
logger.warn("FOD connection does not need proxy");
httpClient = HttpClients.createDefault();
}
getAccessToken();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
use of com.hp.octane.integrations.dto.configuration.CIProxyConfiguration in project octane-ci-java-sdk by MicroFocus.
the class CIPluginSDKUtils method getProxyConfiguration.
public static CIProxyConfiguration getProxyConfiguration(String url, OctaneSDK.SDKServicesConfigurer configurer) {
Function<URL, CIProxyConfiguration> proxySupplier;
if (configurer != null) {
proxySupplier = configurer.pluginServices::getProxyConfiguration;
} else if (OctaneSDK.hasClients()) {
proxySupplier = OctaneSDK.getClients().get(0).getRestService().getProxySupplier();
} else {
return null;
}
URL octaneUrl = CIPluginSDKUtils.parseURL(url);
return proxySupplier.apply(octaneUrl);
}
Aggregations