code: public static Client createRESTClient(String userName, String password)
    {
  
      DefaultApacheHttpClient4Config rc = new DefaultApacheHttpClient4Config();
      rc.getClasses().add(SaltProjectProvider.class);
  
      ThreadSafeClientConnManager clientConnMgr = new ThreadSafeClientConnManager();
      clientConnMgr.setDefaultMaxPerRoute(10);
      rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
        clientConnMgr);
  
      if (userName != null && password != null)
      {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,
          new UsernamePasswordCredentials(userName, password));
  
        rc.getProperties().put(
          ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER,
          credentialsProvider);
        rc.getProperties().put(
          ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION,
          true);
  
      }
  
      Client c = ApacheHttpClient4.create(rc);
      return c;
    }
docs: Creates an authentificiated REST client
  
  @param userName
  @param password
  @return A newly created client.