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

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

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

AuthState.update介绍

[英]Updates the auth state with a queue of AuthOptions.
[中]使用AuthOptions队列更新auth状态。

代码示例

代码示例来源: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: code4craft/webmagic

private HttpClientContext convertHttpClientContext(Request request, Site site, Proxy proxy) {
  HttpClientContext httpContext = new HttpClientContext();
  if (proxy != null && proxy.getUsername() != null) {
    AuthState authState = new AuthState();
    authState.update(new BasicScheme(ChallengeState.PROXY), new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
    httpContext.setAttribute(HttpClientContext.PROXY_AUTH_STATE, authState);
  }
  if (request.getCookies() != null && !request.getCookies().isEmpty()) {
    CookieStore cookieStore = new BasicCookieStore();
    for (Map.Entry<String, String> cookieEntry : request.getCookies().entrySet()) {
      BasicClientCookie cookie1 = new BasicClientCookie(cookieEntry.getKey(), cookieEntry.getValue());
      cookie1.setDomain(UrlUtils.removePort(UrlUtils.getDomain(request.getUrl())));
      cookieStore.addCookie(cookie1);
    }
    httpContext.setCookieStore(cookieStore);
  }
  return httpContext;
}

代码示例来源: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: ca.uhn.hapi.fhir/hapi-fhir-client

@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: 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: membrane/service-proxy

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

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

HttpContext httpContext = new BasicHttpContext();
AuthState authState = new AuthState();

authState.update(new BasicScheme(), new UsernamePasswordCredentials("userName", "password"));
httpContext.setAttribute(HttpClientContext.PROXY_AUTH_STATE, authState);
CloseableHttpResponse httpResponse = httpClient.execute(httpRequest, httpContext);

代码示例来源:origin: edu.uci.ics/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: org.apache.solr/solr-solrj

@Override
 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 available yet, try to initialize it preemptively
  if (authState.getAuthScheme() == null) {
   CredentialsProvider credsProvider = (CredentialsProvider) context
     .getAttribute(ClientContext.CREDS_PROVIDER);
   Credentials creds = credsProvider.getCredentials(AuthScope.ANY);
   authState.update(authScheme, creds);
  }
 }
}

代码示例来源:origin: apache/stanbol

public void process(HttpRequest request, 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
      Credentials creds = credsProvider.getCredentials(authScope);
      // If found, generate BasicScheme preemptively
      if (creds != null) {
        authState.update(new BasicScheme(), creds);
      }
    }
  }
}

代码示例来源:origin: org.fcrepo.client/fcrepo-java-client

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    final AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
    // If no auth scheme available yet, try to initialize it
    // preemptively
    if (authState.getAuthScheme() == null) {
      final CredentialsProvider credsProvider = (CredentialsProvider)
          context.getAttribute(HttpClientContext.CREDS_PROVIDER);
      final HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
      final AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
      final Credentials creds = credsProvider.getCredentials(authScope);
      if (creds == null) {
        LOGGER.debug("Cannot initiate preemtive authentication, Credentials not found!");
      }
      authState.update(new BasicScheme(), creds);
    }
  }
}

代码示例来源:origin: apache/stanbol

public void process(HttpRequest request, 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
      Credentials creds = credsProvider.getCredentials(authScope);
      // If found, generate BasicScheme preemptively
      if (creds != null) {
        authState.update(new BasicScheme(), creds);
      }
    }
  }
}

代码示例来源:origin: net.anthavio/hatatitla

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) {
    AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    if (authScheme != null) {
      Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
      if (creds == null) {
        throw new HttpException("No credentials for preemptive authentication");
      }
      authState.update(authScheme, creds);
    }
  }
}

代码示例来源:origin: apache/activemq-artemis

@Override
 public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
   AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
   // If no auth scheme available yet, try to initialize it preemptively
   if (authState.getAuthScheme() == null) {
    AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
    if (authScheme != null) {
      Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
      if (creds == null) {
       throw new HttpException("No credentials for preemptive authentication");
      }
      authState.update(authScheme, creds);
    }
   }
 }
}

代码示例来源:origin: uwolfer/gerrit-rest-java-client

@Override
public void process(final HttpRequest request, final HttpContext context) {
  // never ever send credentials preemptively to a host which is not the configured Gerrit host
  if (!isForGerritHost(request)) {
    return;
  }
  AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
  // if no auth scheme available yet, try to initialize it preemptively
  if (authState.getAuthScheme() == null) {
    AuthScheme authScheme = (AuthScheme) context.getAttribute(PREEMPTIVE_AUTH);
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(authData.getLogin(), authData.getPassword());
    authState.update(authScheme, creds);
  }
}

代码示例来源:origin: org.sonatype.nexus/nexus-httpclient-api

@Override
 public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
  HttpClientContext clientContext = HttpClientContext.adapt(context);
  AuthState authState = clientContext.getTargetAuthState();
  if (authState.getAuthScheme() == null) {
   CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
   HttpHost targetHost = clientContext.getTargetHost();
   Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
   if (creds != null) {
    authState.update(new BasicScheme(), creds);
   }
  }
 }
}

代码示例来源:origin: org.sonatype.nexus/nexus-httpclient

@Override
 public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
  HttpClientContext clientContext = HttpClientContext.adapt(context);
  AuthState authState = clientContext.getTargetAuthState();
  if (authState.getAuthScheme() == null) {
   CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
   HttpHost targetHost = clientContext.getTargetHost();
   Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
   if (creds != null) {
    authState.update(new BasicScheme(), creds);
   }
  }
 }
}

代码示例来源:origin: org.jfrog.artifactory.client/artifactory-java-client-httpClient

@Override
  public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    AuthState authState = clientContext.getTargetAuthState();

    // If there's no auth scheme available yet, try to initialize it preemptively
    if (authState.getAuthScheme() == null) {
      CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
      HttpHost targetHost = clientContext.getTargetHost();
      Credentials creds = credsProvider.getCredentials(
          new AuthScope(targetHost.getHostName(), targetHost.getPort()));
      if (creds != null) {
        authState.update(new BasicScheme(), creds);
      }
    }
  }
}

代码示例来源:origin: jfrog/artifactory-client-java

@Override
  public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    AuthState authState = clientContext.getTargetAuthState();

    // If there's no auth scheme available yet, try to initialize it preemptively
    if (authState.getAuthScheme() == null) {
      CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
      HttpHost targetHost = clientContext.getTargetHost();
      Credentials creds = credsProvider.getCredentials(
          new AuthScope(targetHost.getHostName(), targetHost.getPort()));
      if (creds != null) {
        authState.update(new BasicScheme(), creds);
      }
    }
  }
}

相关文章