Java 类org.apache.commons.httpclient.auth.BasicScheme 实例源码

项目:convertigo-engine    文件:ProxyManager.java   
public void setCredentials() {
    //Setting credentials for XUL
    if (this.promptUser == null) {
        this.promptUser = this.proxyUser;
    }
    if (this.promptPassword == null) {
        this.promptPassword = this.proxyPassword;
    }
    if (this.promptUser != null && this.promptPassword.length() > 0 && proxyMethod.equals(ProxyMethod.basic.name())) {
        this.basicValue = BasicScheme.authenticate(new UsernamePasswordCredentials(this.promptUser, this.promptPassword), "UTF-8");
    } else {
        this.basicValue = null;
    }   
}
项目:fuse-karaf    文件:CrmSecureTest.java   
@Before
public void beforeTest() {
    // Now we need to use the basic authentication to send the request
    httpClient = new HttpClient();
    httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));
    // Use basic authentication
    scheme = new BasicScheme();

}
项目:vso-intellij    文件:WebServiceHelper.java   
private static void setCredentials(final @NotNull HttpClient httpClient,
                                   final @NotNull Credentials credentials,
                                   final @NotNull URI serverUri) {
  if (credentials.getType() == Credentials.Type.Alternate) {
    HostParams parameters = httpClient.getHostConfiguration().getParams();
    Collection<Header> headers = (Collection<Header>)parameters.getParameter(HostParams.DEFAULT_HEADERS);

    if (headers == null) {
      headers = new ArrayList<Header>();
      parameters.setParameter(HostParams.DEFAULT_HEADERS, headers);
    }

    Header authHeader = ContainerUtil.find(headers, new Condition<Header>() {
      @Override
      public boolean value(Header header) {
        return header.getName().equals(HTTPConstants.HEADER_AUTHORIZATION);
      }
    });

    if (authHeader == null) {
      authHeader = new Header(HTTPConstants.HEADER_AUTHORIZATION, "");
      headers.add(authHeader);
    }

    authHeader
      .setValue(BasicScheme.authenticate(new UsernamePasswordCredentials(credentials.getUserName(), credentials.getPassword()), "UTF-8"));
  }
  else {
    final NTCredentials ntCreds =
      new NTCredentials(credentials.getUserName(), credentials.getPassword(), serverUri.getHost(), credentials.getDomain());
    httpClient.getState().setCredentials(AuthScope.ANY, ntCreds);
    httpClient.getParams().setBooleanParameter(USE_NATIVE_CREDENTIALS, credentials.getType() == Credentials.Type.NtlmNative);
  }
}
项目:vso-intellij    文件:WebServiceHelper.java   
public static void setupStub(final @NotNull Stub stub, final @NotNull Credentials credentials, final @NotNull URI serverUri) {
  Options options = stub._getServiceClient().getOptions();

  // http params
  options.setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
  options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
  options.setProperty(HTTPConstants.SO_TIMEOUT, SOCKET_TIMEOUT);
  if (Registry.is("tfs.set.connection.timeout", false)) {
    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, SOCKET_TIMEOUT);
  }

  // credentials
  if (credentials.getType() == Credentials.Type.Alternate) {
    String basicAuth =
      BasicScheme.authenticate(new UsernamePasswordCredentials(credentials.getUserName(), credentials.getPassword()), "UTF-8");
    Map<String, String> headers = new HashMap<String, String>();
    headers.put(HTTPConstants.HEADER_AUTHORIZATION, basicAuth);
    options.setProperty(HTTPConstants.HTTP_HEADERS, headers);
  }
  else {
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(credentials.getUserName());
    auth.setPassword(credentials.getPassword() != null ? credentials.getPassword() : "");
    auth.setDomain(credentials.getDomain());
    auth.setHost(serverUri.getHost());
    options.setProperty(HTTPConstants.AUTHENTICATE, auth);

    HttpMethodParams params = new HttpMethodParams();
    params.setBooleanParameter(USE_NATIVE_CREDENTIALS, credentials.getType() == Credentials.Type.NtlmNative);
    options.setProperty(HTTPConstants.HTTP_METHOD_PARAMS, params);
  }

  // proxy
  final HttpTransportProperties.ProxyProperties proxyProperties;
  final HTTPProxyInfo proxy = HTTPProxyInfo.getCurrent();
  if (proxy.host != null) {
    proxyProperties = new HttpTransportProperties.ProxyProperties();
    Pair<String, String> domainAndUser = getDomainAndUser(proxy.user);
    proxyProperties.setProxyName(proxy.host);
    proxyProperties.setProxyPort(proxy.port);
    proxyProperties.setDomain(domainAndUser.first);
    proxyProperties.setUserName(domainAndUser.second);
    proxyProperties.setPassWord(proxy.password);
  }
  else {
    proxyProperties = null;
  }

  options.setProperty(HTTPConstants.PROXY, proxyProperties);
}
项目:lib-commons-httpclient    文件:ProxyAuthRequestHandler.java   
/**
 * Checks if the credentials provided by the client match the required
 * credentials
 * 
 * @return true if the client is authorized, false if not.
 * @param clientAuth
 */
private boolean checkAuthorization(Header clientAuth) {
    String expectedAuthString = BasicScheme.authenticate(
        (UsernamePasswordCredentials)credentials,
        "ISO-8859-1");
    return expectedAuthString.equals(clientAuth.getValue());
}
项目:lib-commons-httpclient    文件:AuthRequestHandler.java   
/**
 * Checks if the credentials provided by the client match the required
 * credentials
 * 
 * @return true if the client is authorized, false if not.
 * @param clientAuth
 */
private boolean checkAuthorization(final Header clientAuth) {
    String expectedAuthString = BasicScheme.authenticate(
        (UsernamePasswordCredentials)credentials,
        "ISO-8859-1");
    return expectedAuthString.equals(clientAuth.getValue());
}
项目:httpclient3-ntml    文件:ProxyAuthRequestHandler.java   
/**
 * Checks if the credentials provided by the client match the required
 * credentials
 * 
 * @return true if the client is authorized, false if not.
 * @param clientAuth
 */
private boolean checkAuthorization(Header clientAuth) {
    String expectedAuthString = BasicScheme.authenticate(
        (UsernamePasswordCredentials)credentials,
        "ISO-8859-1");
    return expectedAuthString.equals(clientAuth.getValue());
}
项目:httpclient3-ntml    文件:AuthRequestHandler.java   
/**
 * Checks if the credentials provided by the client match the required
 * credentials
 * 
 * @return true if the client is authorized, false if not.
 * @param clientAuth
 */
private boolean checkAuthorization(final Header clientAuth) {
    String expectedAuthString = BasicScheme.authenticate(
        (UsernamePasswordCredentials)credentials,
        "ISO-8859-1");
    return expectedAuthString.equals(clientAuth.getValue());
}