org.apache.http.auth.AuthState.getAuthScheme()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(73)

本文整理了Java中org.apache.http.auth.AuthState.getAuthScheme()方法的一些代码示例,展示了AuthState.getAuthScheme()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AuthState.getAuthScheme()方法的具体详情如下:
包路径:org.apache.http.auth.AuthState
类名称:AuthState
方法名:getAuthScheme

AuthState.getAuthScheme介绍

[英]Returns the AuthScheme.
[中]返回AuthScheme。

代码示例

代码示例来源:origin: yasserg/crawler4j

@Override
  public void process(HttpRequest request, HttpContext context) {
    AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
    if (authState.getAuthScheme() == null) {
      CredentialsProvider credsProvider =
          (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
      HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
      Credentials credentials = credsProvider.getCredentials(
          new AuthScope(targetHost.getHostName(), targetHost.getPort()));
      if (credentials != null) {
        authState.update(new BasicScheme(), credentials);
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

if (authState.getAuthScheme() == null) {
  AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
  CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);

代码示例来源:origin: robolectric/robolectric

private void processChallenges(
  final Map<String, Header> challenges,
  final AuthState authState,
  final AuthenticationHandler authHandler,
  final HttpResponse response,
  final HttpContext context)
   throws MalformedChallengeException, AuthenticationException {
 AuthScheme authScheme = authState.getAuthScheme();
 if (authScheme == null) {
  // Authentication not attempted before
  authScheme = authHandler.selectScheme(challenges, response, context);
  authState.setAuthScheme(authScheme);
 }
 String id = authScheme.getSchemeName();
 Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
 if (challenge == null) {
  throw new AuthenticationException(id +
   " authorization challenge expected, but not found");
 }
 authScheme.processChallenge(challenge);
 this.log.debug("Authorization challenge processed");
}

代码示例来源:origin: robovm/robovm

private void processChallenges(
    final Map<String, Header> challenges, 
    final AuthState authState,
    final AuthenticationHandler authHandler,
    final HttpResponse response, 
    final HttpContext context) 
      throws MalformedChallengeException, AuthenticationException {
  
  AuthScheme authScheme = authState.getAuthScheme();
  if (authScheme == null) {
    // Authentication not attempted before
    authScheme = authHandler.selectScheme(challenges, response, context);
    authState.setAuthScheme(authScheme);
  }
  String id = authScheme.getSchemeName();
  Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
  if (challenge == null) {
    throw new AuthenticationException(id + 
      " authorization challenge expected, but not found");
  }
  authScheme.processChallenge(challenge);
  this.log.debug("Authorization challenge processed");
}

代码示例来源:origin: robovm/robovm

private static Principal getAuthPrincipal(final AuthState authState) {
  AuthScheme scheme = authState.getAuthScheme();
  if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) {
    Credentials creds = authState.getCredentials();
    if (creds != null) {
      return creds.getUserPrincipal(); 
    }
  }
  return null;
}

代码示例来源:origin: robolectric/robolectric

AuthScheme authScheme = authState.getAuthScheme();
AuthScope authScope = new AuthScope(
  hostname,

代码示例来源:origin: robovm/robovm

AuthScheme authScheme = authState.getAuthScheme();
if (authScheme == null) {
  return;

代码示例来源:origin: robovm/robovm

AuthScheme authScheme = authState.getAuthScheme();
if (authScheme == null) {
  return;

代码示例来源:origin: robovm/robovm

AuthScheme authScheme = authState.getAuthScheme();
AuthScope authScope = new AuthScope(
    hostname,

代码示例来源:origin: robovm/robovm

AuthScheme authScheme = this.proxyAuthState.getAuthScheme();
AuthScope authScope = this.proxyAuthState.getAuthScope();
Credentials creds = this.proxyAuthState.getCredentials();

代码示例来源:origin: robolectric/robolectric

AuthScheme authScheme = proxyAuthState.getAuthScheme();
if (authScheme != null && authScheme.isConnectionBased()) {
 proxyAuthState.invalidate();

代码示例来源:origin: jamesagnew/hapi-fhir

@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
  AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
  if (authState.getAuthScheme() == null) {
    Credentials creds = new UsernamePasswordCredentials(myUsername, myPassword);
    authState.update(new BasicScheme(), creds);
  }
}

代码示例来源:origin: rhuss/jolokia

/** {@inheritDoc} */
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
    if (authState.getAuthScheme() == null) {
      CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
      HttpHost targetHost = (HttpHost) context.getAttribute(HttpClientContext.HTTP_TARGET_HOST);
      Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
      if (creds == null) {
        throw new HttpException("No credentials given for preemptive authentication");
      }
      authState.update(authScheme, creds);
    }
  }
}

代码示例来源:origin: rnewson/couchdb-lucene

public void process(final HttpRequest request, final HttpContext context)
      throws HttpException, IOException {
    final AuthState authState = (AuthState) context
        .getAttribute(ClientContext.TARGET_AUTH_STATE);
    final CredentialsProvider credsProvider = (CredentialsProvider) context
        .getAttribute(ClientContext.CREDS_PROVIDER);
    final 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
      Credentials creds = credsProvider.getCredentials(authScope);
      // If found, generate BasicScheme preemptively
      if (creds != null) {
        authState.setAuthScheme(new BasicScheme());
        authState.setCredentials(creds);
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);

(...)

static class PreemptiveAuthInterceptor implements HttpRequestInterceptor {

  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);

    // If no auth scheme avaialble yet, try to initialize it
    // preemptively
    if (authState.getAuthScheme() == null) {
      CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
      HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
      Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
      if (creds == null)
        throw new HttpException("No credentials for preemptive authentication");
      authState.setAuthScheme(new BasicScheme());
      authState.setCredentials(creds);
    }

  }

}

代码示例来源:origin: io.takari.nexus/nexus-perf

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
  AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
  if (authState.getAuthScheme() == null) {
   CredentialsProvider credsProvider = (CredentialsProvider)
     context.getAttribute(HttpClientContext.CREDS_PROVIDER);
   HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
   AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
   Credentials creds = credsProvider.getCredentials(authScope);
   authState.update(new BasicScheme(), creds);
  }
 }
}

代码示例来源:origin: se.vgregion.pubsubhubbub/pubsubhubbub-hub-composite-twitter

public void process(HttpRequest request, HttpContext context) {
    AuthState authState = (AuthState) context.getAttribute(
        ClientContext.TARGET_AUTH_STATE);
    
    // If not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
      Credentials creds = new UsernamePasswordCredentials(username, password);
      authState.setAuthScheme(new BasicScheme());
      authState.setCredentials(creds);
    }
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

private static Principal getAuthPrincipal(final AuthState authState) {
  final AuthScheme scheme = authState.getAuthScheme();
  if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) {
    final Credentials creds = authState.getCredentials();
    if (creds != null) {
      return creds.getUserPrincipal();
    }
  }
  return null;
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

private static Principal getAuthPrincipal(final AuthState authState) {
  final AuthScheme scheme = authState.getAuthScheme();
  if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) {
    final Credentials creds = authState.getCredentials();
    if (creds != null) {
      return creds.getUserPrincipal();
    }
  }
  return null;
}

代码示例来源:origin: MobiVM/robovm

private static Principal getAuthPrincipal(final AuthState authState) {
  AuthScheme scheme = authState.getAuthScheme();
  if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) {
    Credentials creds = authState.getCredentials();
    if (creds != null) {
      return creds.getUserPrincipal(); 
    }
  }
  return null;
}

相关文章