/** * This format supports Shared Key authentication for the 2009-09-19 version of the Blob and Queue * services. Construct the CanonicalizedResource string in this format as follows: * * <p>1. Beginning with an empty string (""), append a forward slash (/), followed by the name of * the account that owns the resource being accessed. * * <p>2. Append the resource's encoded URI path, without any query parameters. * * <p>3. Retrieve all query parameters on the resource URI, including the comp parameter if it * exists. * * <p>4. Convert all parameter names to lowercase. * * <p>5. Sort the query parameters lexicographically by parameter name, in ascending order. * * <p>6. URL-decode each query parameter name and value. * * <p>7. Append each query parameter name and value to the string in the following format, making * sure to include the colon (:) between the name and the value: * * <p>parameter-name:parameter-value * * <p>8. If a query parameter has more than one value, sort all values lexicographically, then * include them in a comma-separated list: * * <p>parameter-name:parameter-value-1,parameter-value-2,parameter-value-n * * <p>9. Append a new line character (\n) after each name-value pair. */ private String getCanonicalizedResource(ClientRequest cr) { // 1. Beginning with an empty string (""), append a forward slash (/), followed by the name of // the account that owns // the resource being accessed. String result = "/" + this.accountName; // 2. Append the resource's encoded URI path, without any query parameters. result += cr.getURI().getPath(); // 3. Retrieve all query parameters on the resource URI, including the comp parameter if it // exists. // 6. URL-decode each query parameter name and value. List<QueryParam> queryParams = SharedKeyUtils.getQueryParams(cr.getURI().getQuery()); // 4. Convert all parameter names to lowercase. for (QueryParam param : queryParams) { param.setName(param.getName().toLowerCase(Locale.US)); } // 5. Sort the query parameters lexicographically by parameter name, in ascending order. Collections.sort(queryParams); // 7. Append each query parameter name and value to the string // 8. If a query parameter has more than one value, sort all values lexicographically, then // include them in a comma-separated list for (int i = 0; i < queryParams.size(); i++) { QueryParam param = queryParams.get(i); List<String> values = param.getValues(); // Collections.sort(values); // 9. Append a new line character (\n) after each name-value pair. result += "\n"; result += param.getName(); result += ":"; for (int j = 0; j < values.size(); j++) { if (j > 0) { result += ","; } result += values.get(j); } } return result; }
private String getHeader(ClientRequest cr, String headerKey) { return SharedKeyUtils.getHeader(cr, headerKey); }
/** * Constructing the Canonicalized Headers String * * <p>To construct the CanonicalizedHeaders portion of the signature string, follow these steps: * * <p>1. Retrieve all headers for the resource that begin with x-ms-, including the x-ms-date * header. * * <p>2. Convert each HTTP header name to lowercase. * * <p>3. Sort the headers lexicographically by header name, in ascending order. Note that each * header may appear only once in the string. * * <p>4. Unfold the string by replacing any breaking white space with a single space. * * <p>5. Trim any white space around the colon in the header. * * <p>6. Finally, append a new line character to each canonicalized header in the resulting list. * Construct the CanonicalizedHeaders string by concatenating all headers in this list into a * single string. */ private String getCanonicalizedHeaders(ClientRequest cr) { return SharedKeyUtils.getCanonicalizedHeaders(cr); }