Package com.azure.storage.common
Class StorageSharedKeyCredential
java.lang.Object
com.azure.storage.common.StorageSharedKeyCredential
SharedKey credential policy that is put into a header to authorize requests.
-
Constructor Summary
ConstructorDescriptionStorageSharedKeyCredential
(String accountName, String accountKey) Initializes a new instance of StorageSharedKeyCredential contains an account's name and its primary or secondary accountKey. -
Method Summary
Modifier and TypeMethodDescriptioncomputeHmac256
(String stringToSign) Computes a signature for the specified string using the HMAC-SHA256 algorithm.static StorageSharedKeyCredential
fromAzureNamedKeyCredential
(AzureNamedKeyCredential azureNamedKeyCredential) Creates a SharedKey credential from the passedAzureNamedKeyCredential
.static StorageSharedKeyCredential
fromConnectionString
(String connectionString) Creates a SharedKey credential from the passed connection string.generateAuthorizationHeader
(URL requestURL, String httpMethod, HttpHeaders headers, boolean logStringToSign) Generates the SharedKey Authorization value from information in the request.Generates the SharedKey Authorization value from information in the request.generateAuthorizationHeader
(URL requestURL, String httpMethod, Map<String, String> headers, boolean logStringToSign) Generates the SharedKey Authorization value from information in the request.Gets the account name associated with the request.static StorageSharedKeyCredential
getSharedKeyCredentialFromPipeline
(HttpPipeline httpPipeline) Searches for aStorageSharedKeyCredential
in the passedHttpPipeline
.
-
Constructor Details
-
StorageSharedKeyCredential
Initializes a new instance of StorageSharedKeyCredential contains an account's name and its primary or secondary accountKey.- Parameters:
accountName
- The account name associated with the request.accountKey
- The account access key used to authenticate the request.
-
-
Method Details
-
fromConnectionString
Creates a SharedKey credential from the passed connection string.Code Samples
StorageSharedKeyCredential credential = StorageSharedKeyCredential.fromConnectionString(connectionString);
- Parameters:
connectionString
- Connection string used to build the SharedKey credential.- Returns:
- a SharedKey credential if the connection string contains AccountName and AccountKey
- Throws:
IllegalArgumentException
- IfconnectionString
doesn't have AccountName or AccountKey.
-
fromAzureNamedKeyCredential
public static StorageSharedKeyCredential fromAzureNamedKeyCredential(AzureNamedKeyCredential azureNamedKeyCredential) Creates a SharedKey credential from the passedAzureNamedKeyCredential
.- Parameters:
azureNamedKeyCredential
-AzureNamedKeyCredential
used to build the SharedKey credential.- Returns:
- a SharedKey credential converted from
AzureNamedKeyCredential
- Throws:
NullPointerException
- IfazureNamedKeyCredential
is null.
-
getAccountName
Gets the account name associated with the request.- Returns:
- The account name.
-
generateAuthorizationHeader
public String generateAuthorizationHeader(URL requestURL, String httpMethod, Map<String, String> headers) Generates the SharedKey Authorization value from information in the request.- Parameters:
requestURL
- URL of the requesthttpMethod
- HTTP method being usedheaders
- Headers on the request- Returns:
- the SharedKey authorization value
-
generateAuthorizationHeader
public String generateAuthorizationHeader(URL requestURL, String httpMethod, Map<String, String> headers, boolean logStringToSign) Generates the SharedKey Authorization value from information in the request.- Parameters:
requestURL
- URL of the requesthttpMethod
- HTTP method being usedheaders
- Headers on the requestlogStringToSign
- Whether to log the string to sign- Returns:
- the SharedKey authorization value
-
generateAuthorizationHeader
public String generateAuthorizationHeader(URL requestURL, String httpMethod, HttpHeaders headers, boolean logStringToSign) Generates the SharedKey Authorization value from information in the request.- Parameters:
requestURL
- URL of the requesthttpMethod
- HTTP method being usedheaders
- Headers on the requestlogStringToSign
- Whether to log the string to sign- Returns:
- the SharedKey authorization value
-
computeHmac256
Computes a signature for the specified string using the HMAC-SHA256 algorithm. Package-private because it is used to generate SAS signatures.- Parameters:
stringToSign
- The UTF-8-encoded string to sign.- Returns:
- A
String
that contains the HMAC-SHA256-encoded signature. - Throws:
RuntimeException
- If the HMAC-SHA256 algorithm isn't support, if the key isn't a valid Base64 encoded string, or the UTF-8 charset isn't supported.
-