Package com.azure.storage.common
Class StorageSharedKeyCredential
- java.lang.Object
-
- com.azure.storage.common.StorageSharedKeyCredential
-
public final class StorageSharedKeyCredential extends Object
SharedKey credential policy that is put into a header to authorize requests.
-
-
Constructor Summary
Constructors Constructor Description StorageSharedKeyCredential(String accountName, String accountKey)Initializes a new instance of StorageSharedKeyCredential contains an account's name and its primary or secondary accountKey.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringcomputeHmac256(String stringToSign)Computes a signature for the specified string using the HMAC-SHA256 algorithm.static StorageSharedKeyCredentialfromConnectionString(String connectionString)Creates a SharedKey credential from the passed connection string.StringgenerateAuthorizationHeader(URL requestURL, String httpMethod, com.azure.core.http.HttpHeaders headers, boolean logStringToSign)Generates the SharedKey Authorization value from information in the request.StringgenerateAuthorizationHeader(URL requestURL, String httpMethod, Map<String,String> headers)Generates the SharedKey Authorization value from information in the request.StringgenerateAuthorizationHeader(URL requestURL, String httpMethod, Map<String,String> headers, boolean logStringToSign)Generates the SharedKey Authorization value from information in the request.StringgetAccountName()Gets the account name associated with the request.static StorageSharedKeyCredentialgetSharedKeyCredentialFromPipeline(com.azure.core.http.HttpPipeline httpPipeline)Searches for aStorageSharedKeyCredentialin the passedHttpPipeline.
-
-
-
Constructor Detail
-
StorageSharedKeyCredential
public StorageSharedKeyCredential(String accountName, String accountKey)
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 Detail
-
fromConnectionString
public static StorageSharedKeyCredential fromConnectionString(String connectionString)
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- IfconnectionStringdoesn't have AccountName or AccountKey.
-
getAccountName
public String 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 or not to log the string to sign- Returns:
- the SharedKey authorization value
-
generateAuthorizationHeader
public String generateAuthorizationHeader(URL requestURL, String httpMethod, com.azure.core.http.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 or not to log the string to sign- Returns:
- the SharedKey authorization value
-
computeHmac256
public String computeHmac256(String stringToSign)
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
Stringthat 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.
-
getSharedKeyCredentialFromPipeline
public static StorageSharedKeyCredential getSharedKeyCredentialFromPipeline(com.azure.core.http.HttpPipeline httpPipeline)
Searches for aStorageSharedKeyCredentialin the passedHttpPipeline.- Parameters:
httpPipeline- Pipeline being searched- Returns:
- a StorageSharedKeyCredential if the pipeline contains one, otherwise null.
-
-