當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicCredentialsProvider類代碼示例

本文整理匯總了Java中org.apache.http.impl.client.BasicCredentialsProvider的典型用法代碼示例。如果您正苦於以下問題:Java BasicCredentialsProvider類的具體用法?Java BasicCredentialsProvider怎麽用?Java BasicCredentialsProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BasicCredentialsProvider類屬於org.apache.http.impl.client包,在下文中一共展示了BasicCredentialsProvider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: constructHttpClient

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
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();
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:26,代碼來源:LegacyMmsConnection.java

示例2: createTemplate

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
public RestTemplate createTemplate(final String host, final Integer port, final String username, final String password)
{
	Preconditions.checkArgument(StringUtils.isNotBlank(host));
	Preconditions.checkArgument(port != null);
	Preconditions.checkArgument(StringUtils.isNotBlank(username));
	Preconditions.checkArgument(StringUtils.isNotBlank(password));

	final AuthScope authscope = new AuthScope(host, port.intValue());
	final Credentials credentials = new UsernamePasswordCredentials(username, password);
	final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
	credentialsProvider.setCredentials(authscope, credentials);

	final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
	clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
	final CloseableHttpClient httpClient = clientBuilder.build();

	final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
	requestFactory.setHttpClient(httpClient);

	return new RestTemplate(requestFactory);
}
 
開發者ID:fredhopper,項目名稱:hybris-connector,代碼行數:22,代碼來源:RestTemplateProvider.java

示例3: handleError

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
public static void handleError(String url, String login, String password, Scenario scenario) throws Exception {
	String issueId = "";
	for(String tag : scenario.getSourceTagNames()) {
		if (tag.contains("SAM-")) {
			issueId = tag.substring(1);
			break;
		}
	}
	if (issueId.equals("")) {
		return;
	}
	CredentialsProvider provider = new BasicCredentialsProvider();
	UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(login, password);
	provider.setCredentials(AuthScope.ANY, credentials);
	HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
       URI uri = UriBuilder.fromUri(url)
               .path("/rest/api/2/issue/" + issueId).build();
       
       String status = "Passed";
       if (scenario != null && scenario.isFailed()) {
       	status = "Failed";
       }
       HttpPut request = new HttpPut(uri);
       HttpEntity entity = new StringEntity("{\"fields\":{\"customfield_10007\": \"" + status + "\"}}");
       request.setEntity(entity);
       request.addHeader("Content-Type", "application/json");
	HttpResponse response = client.execute(request);
	client.getConnectionManager().shutdown();
}
 
開發者ID:mkolisnyk,項目名稱:0686OS,代碼行數:30,代碼來源:JiraUtils.java

示例4: setAuth

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
@Override
public void setAuth(SensorThingsService service) {
    try {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        URL url = service.getEndpoint().toURL();
        credsProvider.setCredentials(
                new AuthScope(url.getHost(), url.getPort()),
                new UsernamePasswordCredentials(editorUsername.getValue(), editorPassword.getValue()));
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider)
                .build();
        service.setClient(httpclient);
    } catch (MalformedURLException ex) {
        LOGGER.error("Failed to initialise basic auth.", ex);
    }
}
 
開發者ID:hylkevds,項目名稱:SensorThingsProcessor,代碼行數:17,代碼來源:AuthBasic.java

示例5: generateClient

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
@Override
public CloseableHttpAsyncClient generateClient ()
{
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
   credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
           new UsernamePasswordCredentials(serviceUser, servicePass));
   RequestConfig rqconf = RequestConfig.custom()
         .setCookieSpec(CookieSpecs.DEFAULT)
         .setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
         .setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
         .setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
         .build();
   CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
         .setDefaultCredentialsProvider (credsProvider)
         .setDefaultRequestConfig(rqconf)
         .build ();
   res.start ();
   return res;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:20,代碼來源:ODataProductSynchronizer.java

示例6: generateClient

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
@Override
public CloseableHttpAsyncClient generateClient ()
{
   CredentialsProvider credsProvider = new BasicCredentialsProvider();
   credsProvider.setCredentials(new AuthScope (AuthScope.ANY),
            new UsernamePasswordCredentials(username, password));
   RequestConfig rqconf = RequestConfig.custom()
         .setCookieSpec(CookieSpecs.DEFAULT)
         .setSocketTimeout(Timeouts.SOCKET_TIMEOUT)
         .setConnectTimeout(Timeouts.CONNECTION_TIMEOUT)
         .setConnectionRequestTimeout(Timeouts.CONNECTION_REQUEST_TIMEOUT)
         .build();
   CloseableHttpAsyncClient res = HttpAsyncClients.custom ()
         .setDefaultCredentialsProvider (credsProvider)
         .setDefaultRequestConfig(rqconf)
         .build ();
   res.start ();
   return res;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:20,代碼來源:ODataClient.java

示例7: ElasticBulkSender

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
public ElasticBulkSender(String user, String password, HttpHost... hosts) {
	this.user = user;
	this.password = password;
	this.hosts = hosts;
	this.restClient = RestClient.builder(hosts)
			.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
				@Override
				public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
					if (!Strings.isBlank(user)) {
						CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
						credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
		                return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
					} else {
						return httpClientBuilder;
					}
				}
	        })
			.build();
}
 
開發者ID:magrossi,項目名稱:es-log4j2-appender,代碼行數:20,代碼來源:ElasticBulkSender.java

示例8: setProxy

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
public void setProxy(String proxyHost, Integer proxyPort, Credentials credentials) {
      this.proxyHost = proxyHost;
      this.proxyPort = proxyPort;
      
if (this.proxyHost.length() > 0 && !this.proxyPort.equals(0)) {
          HttpClientBuilder clientBuilder = HttpClients.custom()
              .useSystemProperties()
              .setProxy(new HttpHost(proxyHost, proxyPort, "http"));
              
          if (credentials != null) {
              CredentialsProvider credsProvider = new BasicCredentialsProvider();
              credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), credentials);
              clientBuilder.setDefaultCredentialsProvider(credsProvider);
              Loggers.SERVER.debug("MsTeamsNotification ::using proxy credentials " + credentials.getUserPrincipal().getName());
          }
          
          this.client = clientBuilder.build();
}
  }
 
開發者ID:spyder007,項目名稱:teamcity-msteams-notifier,代碼行數:20,代碼來源:MsTeamsNotificationImpl.java

示例9: getProxyExecutor

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
public static HttpCommandExecutor getProxyExecutor(URL url, Properties prop) {

        prop = decrypt(prop);

        String proxyHost = prop.getProperty("proxyHost");
        int proxyPort = Integer.valueOf(prop.getProperty("proxyPort"));
        String proxyUserDomain = prop.getProperty("proxyUserDomain");
        String proxyUser = prop.getProperty("proxyUser");
        String proxyPassword = prop.getProperty("proxyPassword");

        HttpClientBuilder builder = HttpClientBuilder.create();
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();

        credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                new NTCredentials(proxyUser, proxyPassword, getWorkstation(), proxyUserDomain));
        if (url.getUserInfo() != null && !url.getUserInfo().isEmpty()) {
            credsProvider.setCredentials(new AuthScope(url.getHost(), (url.getPort() > 0 ? url.getPort() : url.getDefaultPort())),
                    new UsernamePasswordCredentials(proxyUser, proxyPassword));
        }
        builder.setProxy(proxy);
        builder.setDefaultCredentialsProvider(credsProvider);
        HttpClient.Factory factory = new SimpleHttpClientFactory(builder);
        return new HttpCommandExecutor(new HashMap<String, CommandInfo>(), url, factory);

    }
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:27,代碼來源:RemoteProxy.java

示例10: setUsernamePassword

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
@Override public void setUsernamePassword(AuthenticationType authType, String username,
    String password) {
  this.credentials = new UsernamePasswordCredentials(
      Objects.requireNonNull(username), Objects.requireNonNull(password));

  this.credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY, credentials);

  RegistryBuilder<AuthSchemeProvider> authRegistryBuilder = RegistryBuilder.create();
  switch (authType) {
  case BASIC:
    authRegistryBuilder.register(AuthSchemes.BASIC, new BasicSchemeFactory());
    break;
  case DIGEST:
    authRegistryBuilder.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
    break;
  default:
    throw new IllegalArgumentException("Unsupported authentiation type: " + authType);
  }
  this.authRegistry = authRegistryBuilder.build();
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:22,代碼來源:AvaticaCommonsHttpClientImpl.java

示例11: determineProxy

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
@Override
protected HttpHost determineProxy(HttpHost host, HttpRequest request, HttpContext context) throws HttpException {
    HttpClientContext httpClientContext = HttpClientContext.adapt(context);
    Proxy proxy = proxyPlanner.determineProxy(host, request, context, ipPool, crawlerSession);

    if (proxy == null) {
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("{} 當前使用IP為:{}:{}", host.getHostName(), proxy.getIp(), proxy.getPort());
    }
    context.setAttribute(VSCRAWLER_AVPROXY_KEY, proxy);

    if (proxy.getAuthenticationHeaders() != null) {
        for (Header header : proxy.getAuthenticationHeaders()) {
            request.addHeader(header);
        }
    }

    if (StringUtils.isNotEmpty(proxy.getUsername()) && StringUtils.isNotEmpty(proxy.getPassword())) {
        BasicCredentialsProvider credsProvider1 = new BasicCredentialsProvider();
        httpClientContext.setCredentialsProvider(credsProvider1);
        credsProvider1.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
    }
    return new HttpHost(proxy.getIp(), proxy.getPort());
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:28,代碼來源:VSCrawlerRoutePlanner.java

示例12: setUp

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    /**
     * 如果es集群安裝了x-pack插件則以此種方式連接集群
     * 1. java客戶端的方式是以tcp協議在9300端口上進行通信
     * 2. http客戶端的方式是以http協議在9200端口上進行通信
     */
    Settings settings = Settings.builder(). put("xpack.security.user", "elastic:changeme").build();
    client = new PreBuiltXPackTransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    elasticsearchTemplate = new ElasticsearchTemplate(client);
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("elastic", "changeme"));
    restClient = RestClient.builder(new HttpHost("localhost",9200,"http"))
            .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                @Override
                public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                    return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                }
            }).build();
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:23,代碼來源:XPackBaseDemo.java

示例13: afterPropertiesSet

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
public void afterPropertiesSet() throws UnsupportedEncodingException {
  Collection<Header> defaultHeaders = new ArrayList<Header>();
  Header header = new BasicHeader("Authorization",
      "Basic " + BaseEncoding.base64().encode("apollo:".getBytes("UTF-8")));
  defaultHeaders.add(header);

  BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY,
      new UsernamePasswordCredentials("apollo", ""));
  CloseableHttpClient httpClient =
      HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider)
          .setDefaultHeaders(defaultHeaders).build();


  restTemplate = new RestTemplate(httpMessageConverters.getConverters());
  HttpComponentsClientHttpRequestFactory requestFactory =
      new HttpComponentsClientHttpRequestFactory(httpClient);
  requestFactory.setConnectTimeout(portalConfig.connectTimeout());
  requestFactory.setReadTimeout(portalConfig.readTimeout());

  restTemplate.setRequestFactory(requestFactory);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:23,代碼來源:RestTemplateFactory.java

示例14: createHttpClientContext

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
/**
 * Creates client context.
 * @param url url
 * @param cred credentials
 * @return client context
 */
public static HttpClientContext createHttpClientContext(URL url, SimpleCredentials cred) {
  HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();
  credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
          new UsernamePasswordCredentials(cred.getUserName(),cred.getPassword()));    
  
  // Create AuthCache instance
  AuthCache authCache = new BasicAuthCache();
  // Generate BASIC scheme object and add it to the local auth cache
  BasicScheme basicAuth = new BasicScheme();
  authCache.put(targetHost, basicAuth);

  // Add AuthCache to the execution context
  HttpClientContext context = HttpClientContext.create();
  context.setCredentialsProvider(credsProvider);
  context.setAuthCache(authCache);
  
  return context;
}
 
開發者ID:Esri,項目名稱:geoportal-server-harvester,代碼行數:26,代碼來源:HttpClientContextBuilder.java

示例15: build

import org.apache.http.impl.client.BasicCredentialsProvider; //導入依賴的package包/類
public static HttpClient build(byte[] token) {
    HttpClientBuilder builder = HttpClientBuilder.create();
    Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
            .register(AuthSchemes.SPNEGO, new CollaredSPNegoSchemeFactory(token)).build();
    builder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(null, -1, null), new Credentials() {
        @Override
        public Principal getUserPrincipal() {
            return null;
        }

        @Override
        public String getPassword() {
            return null;
        }
    });
    builder.setDefaultCredentialsProvider(credentialsProvider);
    return builder.build();
}
 
開發者ID:tellisnz,項目名稱:collared-kerberos,代碼行數:21,代碼來源:CollaredHttpClientFactory.java


注:本文中的org.apache.http.impl.client.BasicCredentialsProvider類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。