Search in sources :

Example 46 with BasicCredentialsProvider

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;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 47 with BasicCredentialsProvider

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);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) IProxyData(org.eclipse.core.net.proxy.IProxyData) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) IProxyService(org.eclipse.core.net.proxy.IProxyService) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 48 with BasicCredentialsProvider

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);
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) PostConstruct(javax.annotation.PostConstruct)

Example 49 with BasicCredentialsProvider

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();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) NFileEntity(org.apache.http.nio.entity.NFileEntity) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) CuratorFramework(org.apache.curator.framework.CuratorFramework) Random(java.util.Random) FabricService(io.fabric8.api.FabricService) File(java.io.File) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) Test(org.junit.Test)

Example 50 with BasicCredentialsProvider

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();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) NoConnectionReuseStrategyHC4(org.apache.http.impl.NoConnectionReuseStrategyHC4) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) URL(java.net.URL) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)192 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)162 CredentialsProvider (org.apache.http.client.CredentialsProvider)147 AuthScope (org.apache.http.auth.AuthScope)104 HttpHost (org.apache.http.HttpHost)76 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)53 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)41 HttpResponse (org.apache.http.HttpResponse)38 IOException (java.io.IOException)35 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)31 HttpGet (org.apache.http.client.methods.HttpGet)30 HttpClient (org.apache.http.client.HttpClient)29 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)29 AuthCache (org.apache.http.client.AuthCache)28 BasicScheme (org.apache.http.impl.auth.BasicScheme)27 RequestConfig (org.apache.http.client.config.RequestConfig)25 HttpPost (org.apache.http.client.methods.HttpPost)20 Credentials (org.apache.http.auth.Credentials)19 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)19 Test (org.junit.Test)16