com.microsoft.windowsazure.services.blob.implementation.SharedKeyUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of microsoft-windowsazure-api Show documentation
Show all versions of microsoft-windowsazure-api Show documentation
API for Microsoft Windows Azure Clients
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.windowsazure.services.blob.implementation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import com.sun.jersey.api.client.ClientRequest;
public class SharedKeyUtils {
public static final String AUTHORIZATION_FILTER_MARKER = SharedKeyUtils.class.getName();
/*
* Constructing the Canonicalized Headers String
*
* To construct the CanonicalizedHeaders portion of the signature string,
* follow these steps: 1. Retrieve all headers for the resource that begin
* with x-ms-, including the x-ms-date header. 2. Convert each HTTP header
* name to lowercase. 3. Sort the headers lexicographically by header name,
* in ascending order. Note that each header may appear only once in the
* string. 4. Unfold the string by replacing any breaking white space with a
* single space. 5. Trim any white space around the colon in the header. 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.
*/
public static String getCanonicalizedHeaders(ClientRequest cr) {
ArrayList msHeaders = new ArrayList();
for (String key : cr.getHeaders().keySet()) {
if (key.toLowerCase(Locale.US).startsWith("x-ms-")) {
msHeaders.add(key.toLowerCase(Locale.US));
}
}
Collections.sort(msHeaders);
String result = "";
for (String msHeader : msHeaders) {
result += msHeader + ":" + cr.getHeaders().getFirst(msHeader) + "\n";
}
return result;
}
public static String getHeader(ClientRequest cr, String headerKey) {
List