当前位置: 首页>>代码示例>>Java>>正文


Java BasicScheme类代码示例

本文整理汇总了Java中org.apache.http.impl.auth.BasicScheme的典型用法代码示例。如果您正苦于以下问题:Java BasicScheme类的具体用法?Java BasicScheme怎么用?Java BasicScheme使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BasicScheme类属于org.apache.http.impl.auth包,在下文中一共展示了BasicScheme类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MyAnimeListQuery

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
public MyAnimeListQuery(Charrizard charrizard) {
    status = MyAnimeListStatus.UNKNOWN_ERROR;
    errorDescription = "Unknown error.";
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("https://myanimelist.net/api/account/verify_credentials.xml");
        httpGet.addHeader(BasicScheme.authenticate(
                new UsernamePasswordCredentials(charrizard.getSettings().getMyAnimeList().getUsername(), charrizard.getSettings().getMyAnimeList().getUsername()),
                "UTF-8", false));

        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity responseEntity = httpResponse.getEntity();
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            status = MyAnimeListStatus.AUTH_ERROR;
            errorDescription = "Authorization Error: " + httpResponse.getStatusLine().getReasonPhrase();
            return;
        }
    } catch (IOException e) {
        status = MyAnimeListStatus.REQUEST_ERROR;
        errorDescription = "Can't connect to MyAnimeList: " + e.getMessage();
        e.printStackTrace();
    }
}
 
开发者ID:kacperduras,项目名称:Charrizard,代码行数:24,代码来源:MyAnimeListQuery.java

示例2: process

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
public void process(HttpRequest request, HttpContext context) throws HttpException,
        IOException {
    AuthState authState = (AuthState) context.getAttribute("http.auth.target-scope");
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute("http.auth" +
            ".credentials-provider");
    HttpHost targetHost = (HttpHost) context.getAttribute("http.target_host");
    if (authState.getAuthScheme() == null) {
        Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName
                (), targetHost.getPort()));
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:16,代码来源:AsyncHttpClient$3.java

示例3: addPreemptiveAuthenticationProxy

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
private static void addPreemptiveAuthenticationProxy(HttpClientContext clientContext,
                                                     ProxyConfiguration proxyConfiguration) {

    if (proxyConfiguration.preemptiveBasicAuthenticationEnabled()) {
        HttpHost targetHost = new HttpHost(proxyConfiguration.endpoint().getHost(), proxyConfiguration.endpoint().getPort());
        final CredentialsProvider credsProvider = newProxyCredentialsProvider(proxyConfiguration);
        // 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);

        clientContext.setCredentialsProvider(credsProvider);
        clientContext.setAuthCache(authCache);
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:17,代码来源:ApacheUtils.java

示例4: addPreemptiveAuthenticationProxy

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
private static void addPreemptiveAuthenticationProxy(HttpClientContext clientContext,
                                                     HttpClientSettings settings) {

    if (settings.isPreemptiveBasicProxyAuth()) {
        HttpHost targetHost = new HttpHost(settings.getProxyHost(), settings
                .getProxyPort());
        final CredentialsProvider credsProvider = newProxyCredentialsProvider(settings);
        // 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);

        clientContext.setCredentialsProvider(credsProvider);
        clientContext.setAuthCache(authCache);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:ApacheUtils.java

示例5: createHttpClientContext

import org.apache.http.impl.auth.BasicScheme; //导入依赖的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

示例6: BitcoindApiHandler

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
public BitcoindApiHandler(String host, int port, String protocol, String uri, String username, String password) {
	this.uri = uri;

	httpClient = HttpClients.createDefault();

	targetHost = new HttpHost(host, port, protocol);
	CredentialsProvider credsProvider = new BasicCredentialsProvider();
	credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
			new UsernamePasswordCredentials(username, password));

	AuthCache authCache = new BasicAuthCache();
	BasicScheme basicAuth = new BasicScheme();
	authCache.put(targetHost, basicAuth);

	context = HttpClientContext.create();
	context.setCredentialsProvider(credsProvider);
	context.setAuthCache(authCache);
}
 
开发者ID:SulacoSoft,项目名称:BitcoindConnector4J,代码行数:19,代码来源:BitcoindApiHandler.java

示例7: configureContext

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
private HttpClientContext configureContext(CredentialsProvider credentialsProvider, String url) {
  if (credentialsProvider != null) {
    try {
      URL targetUrl = new URL(url);

      HttpHost targetHost =
          new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol());
      AuthCache authCache = new BasicAuthCache();
      authCache.put(targetHost, new BasicScheme());

      final HttpClientContext context = HttpClientContext.create();
      context.setCredentialsProvider(credentialsProvider);
      context.setAuthCache(authCache);

      return context;
    } catch (MalformedURLException e) {
      LOG.error("Cannot parse URL '{}'", url, e);
    }
  }
  return null;
}
 
开发者ID:reflectoring,项目名称:infiniboard,代码行数:22,代码来源:UrlSourceJob.java

示例8: process

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {

    AuthState authState = (AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider)context
            .getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    // If not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        // Obtain credentials matching the target host
        org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
        // If found, generate BasicScheme preemptively
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
开发者ID:Kamshak,项目名称:foursquared,代码行数:22,代码来源:HttpApiWithBasicAuth.java

示例9: process

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {

    AuthState authState = (AuthState)context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider)context
            .getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

    // If not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
 
开发者ID:Kamshak,项目名称:foursquared,代码行数:20,代码来源:SpecialWebViewActivity.java

示例10: createClient

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
private CloseableHttpClient createClient(String user, String password) {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(TOTAL_CONN);
    cm.setDefaultMaxPerRoute(ROUTE_CONN);

    logger.info("Pooling connection manager created.");

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
    logger.info("Default credentials provider created.");

    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();

    authCache.put(new HttpHost(rootUri.getHost(), rootUri.getPort(), rootUri.getScheme()), basicAuth);
    logger.info("Auth cache created.");

    httpContext = HttpClientContext.create();
    httpContext.setCredentialsProvider(credentialsProvider);
    httpContext.setAuthCache(authCache);
    logger.info("HttpContext filled with Auth cache.");

    return HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(cm)
            .build();
}
 
开发者ID:egetman,项目名称:ibm-bpm-rest-client,代码行数:26,代码来源:SimpleBpmClient.java

示例11: withAuthentication

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
@Override
public RestConfiguration withAuthentication(String user, String password) {
  // Create AuthCache instance
  AuthCache authCache = new BasicAuthCache();
  // Generate BASIC scheme object and add it to the local auth cache
  BasicScheme basicAuth = new BasicScheme();
  CredentialsProvider provider = new BasicCredentialsProvider();

  URI uri = request.getURI();
  authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth);
  provider.setCredentials(new AuthScope(uri.getHost(), AuthScope.ANY_PORT),
      new UsernamePasswordCredentials(user, password));

  this.context.setCredentialsProvider(provider);
  this.context.setAuthCache(authCache);

  return this;
}
 
开发者ID:devnull-tools,项目名称:boteco,代码行数:19,代码来源:DefaultRestConfiguration.java

示例12: getRequestContext

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
@Override
protected HttpContext getRequestContext(URI imageUrl, String imageIdentifier,
        ConfluenceConfiguration config) {
    HttpHost targetHost = new HttpHost(imageUrl.getHost(), imageUrl.getPort());
    CredentialsProvider credentialsProviderProvider = new BasicCredentialsProvider();
    credentialsProviderProvider.setCredentials(new AuthScope(targetHost.getHostName(),
            targetHost.getPort()), new UsernamePasswordCredentials(config.getAdminLogin(),
            config.getAdminPassword()));

    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();
    // preemptive authentication (send credentials with request) by adding host to auth cache
    // TODO maybe use real basic auth challenge?
    authCache.put(targetHost, basicAuth);
    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credentialsProviderProvider);
    context.setAuthCache(authCache);
    return context;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:20,代码来源:ConfluenceUserImageProvider.java

示例13: createContext

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
@Override
    public BasicHttpContext createContext(HttpHost targetHost) {

        final AuthCache authCache = new BasicAuthCache();

        final BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        // OPTIMIZED
        credentialsProvider
                .setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));

        // NON-OPTIMIZED
//        credentialsProvider.setCredentials(
//                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
//                new UsernamePasswordCredentials(username, password));

        final BasicHttpContext context = new BasicHttpContext();
        context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
        context.setAttribute(HttpClientContext.CREDS_PROVIDER, credentialsProvider);

        return context;
    }
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:26,代码来源:BasicAuthConfigurator.java

示例14: setUp

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
@Before
public void setUp() {
    this.target = new HttpHost("localhost", 80);
    this.proxy = new HttpHost("localhost", 8080);

    this.credProvider = new BasicCredentialsProvider();
    this.creds1 = new UsernamePasswordCredentials("user1", "secret1");
    this.creds2 = new UsernamePasswordCredentials("user2", "secret2");
    this.authscope1 = new AuthScope(this.target);
    this.authscope2 = new AuthScope(this.proxy);
    this.authscheme1 = new BasicScheme();
    this.authscheme2 = new BasicScheme();

    this.credProvider.setCredentials(this.authscope1, this.creds1);
    this.credProvider.setCredentials(this.authscope2, this.creds2);

    this.targetState = new AuthState();
    this.proxyState = new AuthState();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:TestRequestAuthCache.java

示例15: testPreemptiveAuthentication

import org.apache.http.impl.auth.BasicScheme; //导入依赖的package包/类
@Test
public void testPreemptiveAuthentication() throws Exception {
    final CountingAuthHandler requestHandler = new CountingAuthHandler();
    this.serverBootstrap.registerHandler("*", requestHandler);

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();
    final AuthCache authCache = new BasicAuthCache();
    authCache.put(target, new BasicScheme());
    context.setAuthCache(authCache);
    final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("test", "test"));
    context.setCredentialsProvider(credsProvider);

    final HttpGet httpget = new HttpGet("/");
    final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
    final HttpEntity entity1 = response1.getEntity();
    Assert.assertEquals(HttpStatus.SC_OK, response1.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity1);
    EntityUtils.consume(entity1);

    Assert.assertEquals(1, requestHandler.getCount());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestClientAuthentication.java


注:本文中的org.apache.http.impl.auth.BasicScheme类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。