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 Details

    • 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 Details

    • 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 - If connectionString doesn't have AccountName or AccountKey.
    • fromAzureNamedKeyCredential

      public static StorageSharedKeyCredential fromAzureNamedKeyCredential(AzureNamedKeyCredential azureNamedKeyCredential)
      Creates a SharedKey credential from the passed AzureNamedKeyCredential.
      Parameters:
      azureNamedKeyCredential - AzureNamedKeyCredential used to build the SharedKey credential.
      Returns:
      a SharedKey credential converted from AzureNamedKeyCredential
      Throws:
      NullPointerException - If azureNamedKeyCredential is null.
    • 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 request
      httpMethod - HTTP method being used
      headers - 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 request
      httpMethod - HTTP method being used
      headers - Headers on the request
      logStringToSign - 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 request
      httpMethod - HTTP method being used
      headers - Headers on the request
      logStringToSign - Whether 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 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.
    • getSharedKeyCredentialFromPipeline

      public static StorageSharedKeyCredential getSharedKeyCredentialFromPipeline(HttpPipeline httpPipeline)
      Searches for a StorageSharedKeyCredential in the passed HttpPipeline.
      Parameters:
      httpPipeline - Pipeline being searched
      Returns:
      a StorageSharedKeyCredential if the pipeline contains one, otherwise null.