/**
   * Formats a challenge response as a HTTP Authorization header value needed by ACS Management
   * OData Service
   */
  @Override
  public String formatResponse(
      ChallengeResponse challenge, Request request, Series<Parameter> httpHeaders) {
    ChallengeWriter challengeWriter = new ChallengeWriter();
    challengeWriter.append(challenge.getScheme().getTechnicalName()).appendSpace();

    if (challenge.getRawValue() != null) {
      challengeWriter.append(challenge.getRawValue());
    } else {
      formatRawResponse(challengeWriter, challenge, request, httpHeaders);
    }

    // Get ACS credentails
    String acsNameSpace = challenge.getIdentifier();
    String acsMgmtPassword = new String(challenge.getSecret());

    // Get token from ACS
    String swtToken = getTokenFromACS(acsNameSpace, acsMgmtPassword);

    // Append ACS token to the ChallengeWriter. Restlet library will
    // automatically
    // add this as Authorization HTTP header and use scheme technical name
    // ("bearer").
    return challengeWriter.toString() + swtToken;
  }
  /** Test Amazon S3 authentication. */
  public void testAwsS3() {
    HttpAwsS3Helper helper = new HttpAwsS3Helper();

    // Example Object GET
    ChallengeWriter cw = new ChallengeWriter();
    ChallengeResponse challenge =
        new ChallengeResponse(
            ChallengeScheme.HTTP_AWS_S3,
            "0PN5J17HBGZHT7JJ3X82",
            "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o");
    Request request = new Request(Method.GET, "http://johnsmith.s3.amazonaws.com/photos/puppy.jpg");
    Form httpHeaders = new Form();
    httpHeaders.add(HeaderConstants.HEADER_DATE, "Tue, 27 Mar 2007 19:36:42 +0000");

    helper.formatRawResponse(cw, challenge, request, httpHeaders);
    assertEquals("0PN5J17HBGZHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA=", cw.toString());

    // Example Object PUT
    cw = new ChallengeWriter();
    request.setMethod(Method.PUT);
    httpHeaders.set(HeaderConstants.HEADER_DATE, "Tue, 27 Mar 2007 21:15:45 +0000", true);
    httpHeaders.add(HeaderConstants.HEADER_CONTENT_LENGTH, "94328");
    httpHeaders.add(HeaderConstants.HEADER_CONTENT_TYPE, "image/jpeg");
    helper.formatRawResponse(cw, challenge, request, httpHeaders);
    assertEquals("0PN5J17HBGZHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ=", cw.toString());
  }