use of org.apache.http.impl.client.BasicCredentialsProvider in project kylo by Teradata.
the class MetadataClient method createCredentialProvider.
/**
* creates a credentials provider
*
* @param username the user name f
* @param password the password
* @return a credentials provider
*/
public static CredentialsProvider createCredentialProvider(String username, String password) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
return credsProvider;
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project vorto by eclipse.
the class RestClient method getProxyConfiguration.
private ProxyConfiguration getProxyConfiguration() {
IProxyService proxyService = getProxyService();
IProxyData[] proxyDataForHost = proxyService.select(java.net.URI.create(connectionInfo.getUrl()));
CredentialsProvider credsProvider = new BasicCredentialsProvider();
RequestConfig.Builder configBuilder = RequestConfig.custom();
for (IProxyData data : proxyDataForHost) {
if (!Strings.isNullOrEmpty(data.getHost())) {
HttpHost proxyConfig = new HttpHost(data.getHost(), data.getPort(), data.getType());
configBuilder.setProxy(proxyConfig);
if (!Strings.isNullOrEmpty(data.getUserId())) {
credsProvider.setCredentials(new AuthScope(data.getHost(), data.getPort()), new UsernamePasswordCredentials(data.getUserId(), data.getPassword()));
}
}
}
return new ProxyConfiguration(configBuilder.build(), credsProvider);
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project thingsboard by thingsboard.
the class ElasticsearchAuditLogSink method init.
@PostConstruct
public void init() {
try {
log.trace("Adding elastic rest endpoint... host [{}], port [{}], scheme name [{}]", host, port, schemeName);
RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, schemeName));
if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
log.trace("...using username [{}] and password ***", userName);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
}
this.restClient = builder.build();
} catch (Exception e) {
log.error("Sink init failed!", e);
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project fabric8 by jboss-fuse.
the class FabricMavenProxyTest method testUpload.
@Test
public void testUpload() throws Exception {
String featureLocation = System.getProperty("feature.location");
System.out.println("Testing with feature from:" + featureLocation);
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("maven").withProfiles("fabric").waitForProvisioning(10 * 60 * 1000L).assertProvisioningResult().build();
try {
List<String> uploadUrls = new ArrayList<String>();
ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext, CuratorFramework.class);
try {
CuratorFramework curator = curatorProxy.getService();
List<String> children = ZooKeeperUtils.getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload"));
for (String child : children) {
String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
uploadUrls.add(uploadeUrl);
}
} finally {
curatorProxy.close();
}
// Pick a random maven proxy from the list.
Random random = new Random();
int index = random.nextInt(uploadUrls.size());
String targetUrl = uploadUrls.get(index);
String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
System.out.println("Using URI: " + uploadUrl);
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));
CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
HttpPut put = new HttpPut(uploadUrl);
NFileEntity entity = new NFileEntity(new File(featureLocation), ContentType.TEXT_XML);
put.setEntity(entity);
HttpResponse response = client.execute(put);
System.out.println("Response:" + response.getStatusLine());
Assert.assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202);
System.out.println(executeCommand("fabric:profile-edit --repository mvn:itest/itest/1.0/xml/features default"));
System.out.println(executeCommand("fabric:profile-edit --feature example-cbr default"));
Provision.containerStatus(containers, PROVISION_TIMEOUT);
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project Signal-Android by signalapp.
the class LegacyMmsConnection method constructHttpClient.
protected CloseableHttpClient constructHttpClient() throws IOException {
RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000).setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build();
URL mmsc = new URL(apn.getMmsc());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
if (apn.hasAuthentication()) {
credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()), new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
}
return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()).setRedirectStrategy(new LaxRedirectStrategy()).setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT)).setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config).setDefaultCredentialsProvider(credsProvider).build();
}
Aggregations