Package org.apache.http.auth

Examples of org.apache.http.auth.UsernamePasswordCredentials


   
    if (useAuthentication){
      int port = targetHost.getPort();
      String hostName = targetHost.getHostName();
   
      this.credentials = new UsernamePasswordCredentials(this.username, this.password);
//this may not work.  may need a new client.
      ((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
              new AuthScope(hostName, port),
              this.credentials);
     
View Full Code Here


    }
   
    private void setAdminCredentials() {
        client.getCredentialsProvider().setCredentials(
                AuthScope.ANY,
                new UsernamePasswordCredentials("admin", "admin"));
        client.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);
    }
View Full Code Here

            return authenticated;

        } else if (authenticable instanceof CredentialsProvider) {
            CredentialsProvider credentialsProvider = (CredentialsProvider) authenticable;
            credentialsProvider.setCredentials(new AuthScope(new HttpHost(endpoint.getUri().getHost(), endpoint.getUri().getPort())),
                    new UsernamePasswordCredentials(username, password));

            log.debug("authenticated CredentialsProvider HTTP client with user and password");
            return credentialsProvider;
        }
View Full Code Here

  private static ResteasyClient getClientWithServerAdminCredentials() {
    DefaultHttpClient httpClient = new DefaultHttpClient();

    httpClient.getCredentialsProvider().setCredentials(
        new AuthScope( host, port ),
        new UsernamePasswordCredentials( serverAdminUser, serverAdminPassword )
        );

    AuthCache authCache = new BasicAuthCache();
    authCache.put(
        new HttpHost( host, port, "http" ),
View Full Code Here

  public static Map<String, Object> get(String url, Integer connectionTimeout, Integer soTimeout, Map<String, Object> authMap) throws Exception
  {
    HttpClient client = getHttpClient(url, connectionTimeout, soTimeout);
    HttpGet httpclient = new HttpGet(url);
    if (authMap != null)
      httpclient.addHeader(new BasicScheme().authenticate(new UsernamePasswordCredentials((String) authMap.get("user"), (String) authMap.get("password")), httpclient));
    HttpResponse response = client.execute(httpclient);
    HttpEntity resEntity = response.getEntity();
    String contentCharSet = EntityUtils.getContentCharSet(resEntity);
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("status", response.getStatusLine().getStatusCode());
View Full Code Here

  }

  public void setupConnection(AbstractHttpClient client) {
    client.getCredentialsProvider().setCredentials(
            AuthScope.ANY,
            new UsernamePasswordCredentials(username, password)
    );
  }
View Full Code Here

  @Override
  public void afterPropertiesSet() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    BasicCredentialsProvider credentialsProvider =  new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(adminUser, adminPass));
    client.setCredentialsProvider(credentialsProvider);
    ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(client);

    RestTemplate template = new RestTemplate(rf);
View Full Code Here

            throw new IllegalArgumentException("password must not be null"); //$NON-NLS-1$
        }
        this.baseUri = normalize(baseUri);
        this.user = user;
        DefaultHttpClient client = createClient();
        client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
        this.http = client;
    }
View Full Code Here

        Boolean response =  false;
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
          HttpPost httpPost = new HttpPost(URL);
          System.out.println(URL);
            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
            BasicScheme scheme = new BasicScheme();
            Header authorizationHeader = scheme.authenticate(credentials, httpPost);
            httpPost.setHeader(authorizationHeader);
            httpPost.setEntity(input);
            //System.out.println("Executing request: " + httpGet.getRequestLine());
View Full Code Here

        String response =  "";
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            HttpGet httpGet = new HttpGet(URL);

            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
            BasicScheme scheme = new BasicScheme();
            Header authorizationHeader = scheme.authenticate(credentials, httpGet);
            httpGet.setHeader(authorizationHeader);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
           
View Full Code Here

TOP

Related Classes of org.apache.http.auth.UsernamePasswordCredentials

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.