Ejemplo n.º 1
0
 /**
  * Add DIGEST credentials to all requests
  *
  * @param realm the realm that the username and password are in
  * @param user username
  * @param password password
  */
 public void setCredentials(String realm, String user, String password)
     throws HoneycombTestException {
   try {
     String host = conn.getHost();
     int port = conn.getPort();
     AuthorizationInfo.addDigestAuthorization(host, port, realm, user, password);
   } catch (Exception e) {
     throw new HoneycombTestException(
         "Couldn't add credential " + realm + ":" + user + " -- " + e);
   }
 }
Ejemplo n.º 2
0
  public NVPair getUsernamePassword(AuthorizationInfo challenge, boolean forProxy) {
    if (forProxy && pa_name != null) {
      if (been_here) {
        System.out.println();
        System.out.println("Proxy authorization failed");
        return null;
      }

      been_here = true;
      return new NVPair(pa_name, pa_pass);
    }

    if (been_here) {
      System.out.println();
      System.out.println("Proxy authorization succeeded");
    }

    // print out all challenge info

    System.out.println();
    if (forProxy) System.out.println("The proxy requires authorization");
    else System.out.println("The server requires authorization for this resource");

    System.out.println();
    System.out.println("Scheme: " + challenge.getScheme());
    System.out.println("Realm:  " + challenge.getRealm());

    System.out.println();
    System.out.println("Add the following line near the beginning of your application:");
    System.out.println();

    if (challenge.getScheme().equalsIgnoreCase("Basic"))
      System.out.println(
          "    AuthorizationInfo.addBasicAuthorization(\""
              + challenge.getHost()
              + "\", "
              + challenge.getPort()
              + ", \""
              + challenge.getRealm()
              + "\", "
              + "<username>, <password>);");
    else if (challenge.getScheme().equalsIgnoreCase("Digest"))
      System.out.println(
          "    AuthorizationInfo.addDigestAuthorization(\""
              + challenge.getHost()
              + "\", "
              + challenge.getPort()
              + ", \""
              + challenge.getRealm()
              + "\", "
              + "<username>, <password>);");
    else
      System.out.println(
          "    AuthorizationInfo.addAuthorization(\""
              + challenge.getHost()
              + "\", "
              + challenge.getPort()
              + ", \""
              + challenge.getScheme()
              + "\", \""
              + challenge.getRealm()
              + "\", "
              + "...);");
    System.out.println();

    return null;
  }