共用方式為


StorageCredentials Class

  • java.lang.Object
    • com.microsoft.azure.storage.StorageCredentials

public class StorageCredentials

Represents a set of credentials used to authenticate access to a Microsoft Azure storage account. This is the base class for the StorageCredentialsAccountAndKey, StorageCredentialsToken, and StorageCredentialsSharedAccessSignature classes.

Method Summary

Modifier and Type Method and Description
String getAccountName()

Returns the associated account name for the credentials. This is null for anonymous and shared access signature credentials.

boolean isHttpsOnly()

Gets whether this object only allows access via HTTPS.

void setHttpsOnly(boolean httpsOnly)

Sets whether this object only allows access via HTTPS.

abstract String toString(boolean exportSecrets)

Returns a that represents this instance.

URI transformUri(final URI resourceUri)

Transforms a resource URI into a shared access signature URI, by appending a shared access token.

StorageUri transformUri(StorageUri resourceUri)

Transforms a resource URI into a shared access signature URI, by appending a shared access token.

abstract StorageUri transformUri(StorageUri resourceUri, OperationContext opContext)

Transforms a resource URI into a shared access signature URI, by appending a shared access token and using the specified operation context.

abstract URI transformUri(URI resourceUri, OperationContext opContext)

Transforms a resource URI into a shared access signature URI, by appending a shared access token and using the specified operation context.

StorageCredentials tryParseCredentials(final Map<String, String> settings)

Tries to determine the storage credentials from a collection of name/value pairs.

Either include an account name with an account key (specifying values for ACCOUNT_NAME_NAME and ACCOUNT_KEY_NAME ), or a shared access signature (specifying a value for SHARED_ACCESS_SIGNATURE_NAME ). If you use an account name and account key, do not include a shared access signature, and vice versa.

StorageCredentials tryParseCredentials(final String connectionString)

Tries to determine the storage credentials from a connection string.

The format for the connection string is in the pattern "<i>keyname=value</i>". Multiple key/value pairs can be separated by a semi-colon, for example, "<i>keyname1=value1;keyname2=value2</i>". Either include an account name with an account key or a shared access signature. If you use an account name and account key, do not include a shared access signature, and vice versa.

The same connection string can be used as for parse(final String connectionString) but here only the account name, account key, and sas key/value pairs will be examined.

Method Details

getAccountName

public String getAccountName()

Returns the associated account name for the credentials. This is null for anonymous and shared access signature credentials.

Returns:

A String that represents the associated account name for the credentials

isHttpsOnly

public boolean isHttpsOnly()

Gets whether this object only allows access via HTTPS.

Returns:

A boolean representing whether this StorageCredentials object only allows access via HTTPS.

setHttpsOnly

protected void setHttpsOnly(boolean httpsOnly)

Sets whether this object only allows access via HTTPS.

Parameters:

httpsOnly - A boolean representing whether this StorageCredentials object only allows access via HTTPS.

toString

public abstract String toString(boolean exportSecrets)

Returns a that represents this instance.

Parameters:

exportSecrets -

true to include sensitive data in the return string; otherwise, false.

Returns:

A String that represents this object, optionally including sensitive data.

transformUri

public URI transformUri(final URI resourceUri)

Transforms a resource URI into a shared access signature URI, by appending a shared access token.

Parameters:

resourceUri - A java.net.URI object that represents the resource URI to be transformed.

Returns:

A java.net.URI object that represents the signature, including the resource URI and the shared access token.

Throws:

StorageException - If a storage service error occurred.
URISyntaxException - If the resource URI is not properly formatted.

transformUri

public StorageUri transformUri(StorageUri resourceUri)

Transforms a resource URI into a shared access signature URI, by appending a shared access token.

Parameters:

resourceUri - A StorageUri object that represents the resource URI to be transformed.

Returns:

A StorageUri object that represents the signature, including the resource URI and the shared access token.

Throws:

StorageException - If a storage service error occurred.
URISyntaxException - If the resource URI is not properly formatted.

transformUri

public abstract StorageUri transformUri(StorageUri resourceUri, OperationContext opContext)

Transforms a resource URI into a shared access signature URI, by appending a shared access token and using the specified operation context.

Parameters:

resourceUri - A StorageUri object that represents the resource URI to be transformed.
opContext - An OperationContext object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.

Returns:

A StorageUri object that represents the signature, including the resource URI and the shared access token.

Throws:

StorageException - If a storage service error occurred.
URISyntaxException - If the resource URI is not properly formatted.

transformUri

public abstract URI transformUri(URI resourceUri, OperationContext opContext)

Transforms a resource URI into a shared access signature URI, by appending a shared access token and using the specified operation context.

Parameters:

resourceUri - A java.net.URI object that represents the resource URI to be transformed.
opContext - An OperationContext object that represents the context for the current operation. This object is used to track requests to the storage service, and to provide additional runtime information about the operation.

Returns:

A java.net.URI object that represents the signature, including the resource URI and the shared access token.

Throws:

StorageException - If a storage service error occurred.
URISyntaxException - If the resource URI is not properly formatted.

tryParseCredentials

protected static StorageCredentials tryParseCredentials(final Map settings)

Tries to determine the storage credentials from a collection of name/value pairs.

Either include an account name with an account key (specifying values for ACCOUNT_NAME_NAME and ACCOUNT_KEY_NAME ), or a shared access signature (specifying a value for SHARED_ACCESS_SIGNATURE_NAME ). If you use an account name and account key, do not include a shared access signature, and vice versa.

Parameters:

settings - A Map object of the name/value pairs that represent the settings to use to configure the credentials.

Returns:

A StorageCredentials object representing the storage credentials determined from the name/value pairs.

Throws:

InvalidKeyException - If the key value specified for ACCOUNT_KEY_NAME is not a valid Base64-encoded string.

tryParseCredentials

public static StorageCredentials tryParseCredentials(final String connectionString)

Tries to determine the storage credentials from a connection string.

The format for the connection string is in the pattern "<i>keyname=value</i>". Multiple key/value pairs can be separated by a semi-colon, for example, "<i>keyname1=value1;keyname2=value2</i>". Either include an account name with an account key or a shared access signature. If you use an account name and account key, do not include a shared access signature, and vice versa.

The same connection string can be used as for parse(final String connectionString) but here only the account name, account key, and sas key/value pairs will be examined.

Parameters:

connectionString - A String that contains the key/value pairs that represent the storage credentials.

Returns:

A StorageCredentials object representing the storage credentials determined from the connection string.

Throws:

InvalidKeyException - If the account key specified in connectionString is not valid.
StorageException

Applies to