com.microsoft.azure.storage.core.StorageCredentialsHelper Java Examples

The following examples show how to use com.microsoft.azure.storage.core.StorageCredentialsHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudStorageAccount.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new File service client.
 * 
 * @return A {@link CloudFileClient} that represents the cloud File client.
 * 
 */
public CloudFileClient createCloudFileClient() {
    if (this.getFileStorageUri() == null) {
        throw new IllegalArgumentException(SR.FILE_ENDPOINT_NOT_CONFIGURED);
    }

    if (this.credentials == null) {
        throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
    }

    if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
        
        throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
    }
    
    return new CloudFileClient(this.getFileStorageUri(), this.getCredentials());
}
 
Example #2
Source File: CloudStorageAccount.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new Queue service client.
 * 
 * @return A client object that uses the Queue service endpoint.
 */
public CloudQueueClient createCloudQueueClient() {
    if (this.getQueueStorageUri() == null) {
        throw new IllegalArgumentException(SR.QUEUE_ENDPOINT_NOT_CONFIGURED);
    }

    if (this.credentials == null) {
        throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
    }

    if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
        
        throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
    }
    
    return new CloudQueueClient(this.getQueueStorageUri(), this.getCredentials());
}
 
Example #3
Source File: CloudStorageAccount.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new Table service client.
 * 
 * @return A client object that uses the Table service endpoint.
 */
public CloudTableClient createCloudTableClient() {
    if (this.getTableStorageUri() == null) {
        throw new IllegalArgumentException(SR.TABLE_ENDPOINT_NOT_CONFIGURED);
    }

    if (this.credentials == null) {
        throw new IllegalArgumentException(SR.MISSING_CREDENTIALS);
    }

    if (!StorageCredentialsHelper.canCredentialsGenerateClient(this.credentials)) {
        
        throw new IllegalArgumentException(SR.CREDENTIALS_CANNOT_SIGN_REQUEST);
    }
    
    return new CloudTableClient(this.getTableStorageUri(), this.getCredentials());
}
 
Example #4
Source File: CloudFileShare.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a shared access signature for the share. Note this does not contain the leading "?".
 * 
 * @param policy
 *            An {@link SharedAccessFilePolicy} object that represents the access policy for the
 *            shared access signature.
 * @param groupPolicyIdentifier
 *            A <code>String</code> which represents the share-level access policy.
 * @param ipRange
 *            A {@link IPRange} object containing the range of allowed IP addresses.
 * @param protocols
 *            A {@link SharedAccessProtocols} representing the allowed Internet protocols.
 * 
 * @return A <code>String</code> which represents a shared access signature for the share.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws InvalidKeyException
 *             If the key is invalid.
 */
public String generateSharedAccessSignature(
        final SharedAccessFilePolicy policy, final String groupPolicyIdentifier, final IPRange ipRange,
        final SharedAccessProtocols protocols)
        throws InvalidKeyException, StorageException {

    if (!StorageCredentialsHelper.canCredentialsSignRequest(this.fileServiceClient.getCredentials())) {
        final String errorMessage = SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY;
        throw new IllegalArgumentException(errorMessage);
    }

    final String resourceName = this.getSharedAccessCanonicalName();

    final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
            policy, null /* SharedAccessHeaders */, groupPolicyIdentifier, resourceName,
            ipRange, protocols, this.fileServiceClient);

    final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(
            policy, null /* SharedAccessHeaders */, groupPolicyIdentifier, "s", ipRange, protocols, signature);

    return builder.toString();
}
 
Example #5
Source File: CloudStorageAccount.java    From azure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a shared access signature for the account.
 * 
 * @param policy
 *            A {@link SharedAccessAccountPolicy} specifying the access policy for the shared access signature.
 *            
 * @return The query string returned includes the leading question mark.
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws InvalidKeyException
 *             If the key is invalid.
 */
public String generateSharedAccessSignature(SharedAccessAccountPolicy policy)
        throws InvalidKeyException, StorageException {
    if (!StorageCredentialsHelper.canCredentialsSignRequest(this.getCredentials())) {
        throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
    }
    
    final String sig = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForAccount(
            this.credentials.getAccountName(), policy, this.getCredentials());
    final UriQueryBuilder sasBuilder =
            SharedAccessSignatureHelper.generateSharedAccessSignatureForAccount(policy, sig);
    return sasBuilder.toString();
}
 
Example #6
Source File: CloudBlobContainer.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a shared access signature for the container. Note this does not contain the leading "?".
 * 
 * @param policy
 *            An {@link SharedAccessBlobPolicy} object that represents the access policy for the shared access
 *            signature.
 * @param groupPolicyIdentifier
 *            A <code>String</code> which represents the container-level access policy.
 * @param ipRange
 *            A {@link IPRange} object containing the range of allowed IP addresses.
 * @param protocols
 *            A {@link SharedAccessProtocols} representing the allowed Internet protocols.
 * 
 * @return A <code>String</code> which represents a shared access signature for the container.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws InvalidKeyException
 *             If the key is invalid.
 */
public String generateSharedAccessSignature(final SharedAccessBlobPolicy policy,
        final String groupPolicyIdentifier, final IPRange ipRange, final SharedAccessProtocols protocols)
        throws InvalidKeyException, StorageException {
    if (!StorageCredentialsHelper.canCredentialsSignRequest(this.blobServiceClient.getCredentials())) {
        final String errorMessage = SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY;
        throw new IllegalArgumentException(errorMessage);
    }
    
    final String resourceName = this.getSharedAccessCanonicalName();

    final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
            policy, null /* SharedAccessBlobHeaders */, groupPolicyIdentifier, resourceName,
            ipRange, protocols, this.blobServiceClient);

    final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(policy,
            null /* SharedAccessBlobHeaders */, groupPolicyIdentifier, "c", ipRange, protocols, signature);

    return builder.toString();
}
 
Example #7
Source File: CloudBlob.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a shared access signature for the blob using the specified group policy identifier and operation context.
 * Note this does not contain the leading "?".
 *
 * @param policy
 *            A <code>{@link SharedAccessPolicy}</code> object that represents the access policy for the shared
 *            access signature.
 * @param headers
 *            A <code>{@link SharedAccessBlobHeaders}</code> object that represents the optional header values to
 *            set for a blob accessed with this shared access signature.
 * @param groupPolicyIdentifier
 *            A <code>String</code> that represents the container-level access policy.
 * @param ipRange
 *            A {@link IPRange} object containing the range of allowed IP addresses.
 * @param protocols
 *            A {@link SharedAccessProtocols} representing the allowed Internet protocols.
 *
 * @return A <code>String</code> that represents the shared access signature.
 *
 * @throws IllegalArgumentException
 *             If the credentials are invalid or the blob is a snapshot.
 * @throws InvalidKeyException
 *             If the credentials are invalid.
 * @throws StorageException
 *             If a storage service error occurred.
 */
public String generateSharedAccessSignature(
        final SharedAccessBlobPolicy policy, final SharedAccessBlobHeaders headers,
        final String groupPolicyIdentifier, final IPRange ipRange, final SharedAccessProtocols protocols)
        throws InvalidKeyException, StorageException {
    
    if (!StorageCredentialsHelper.canCredentialsSignRequest(this.blobServiceClient.getCredentials())) {
        throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
    }
    
    if (this.isSnapshot()) {
        throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_FOR_SNAPSHOTS);
    }

    final String resourceName = this.getCanonicalName(true);

    final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
            policy, headers, groupPolicyIdentifier, resourceName, ipRange, protocols, this.blobServiceClient);

    final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(
            policy, headers, groupPolicyIdentifier, "b", ipRange, protocols, signature);

    return builder.toString();
}
 
Example #8
Source File: CloudFile.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a shared access signature for the file using the specified group policy identifier and
 * shared access file headers. Note this does not contain the leading "?".
 *
 * @param policy
 *            A <code>{@link SharedAccessFilePolicy}</code> object that represents the access policy for the shared
 *            access signature.
 * @param headers
 *            A <code>{@link SharedAccessFileHeaders}</code> object that represents the optional header values to
 *            set for a file accessed with this shared access signature.
 * @param groupPolicyIdentifier
 *            A <code>String</code> that represents the share-level access policy.
 * @param ipRange
 *            A {@link IPRange} object containing the range of allowed IP addresses.
 * @param protocols
 *            A {@link SharedAccessProtocols} representing the allowed Internet protocols.
 *
 * @return A <code>String</code> that represents the shared access signature.
 *
 * @throws IllegalArgumentException
 *             If the credentials are invalid.
 * @throws InvalidKeyException
 *             If the credentials are invalid.
 * @throws StorageException
 *             If a storage service error occurred.
 */
public String generateSharedAccessSignature(
        final SharedAccessFilePolicy policy, final SharedAccessFileHeaders headers,
        final String groupPolicyIdentifier, final IPRange ipRange, final SharedAccessProtocols protocols)
        throws InvalidKeyException, StorageException {

    if (!StorageCredentialsHelper.canCredentialsSignRequest(this.fileServiceClient.getCredentials())) {
        throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
    }

    final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForBlobAndFile(
            policy, headers, groupPolicyIdentifier, this.getCanonicalName(),
            ipRange, protocols, this.fileServiceClient);

    final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForBlobAndFile(
            policy, headers, groupPolicyIdentifier, "f", ipRange, protocols, signature);

    return builder.toString();
}
 
Example #9
Source File: CloudTable.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a shared access signature for the table.
 *
 * @param policy
 *            A {@link SharedAccessTablePolicy} object which represents the access policy for the shared access
 *            signature.
 * @param accessPolicyIdentifier
 *            A <code>String</code> which represents a table-level access policy.
 * @param startPartitionKey
 *            A <code>String</code> which represents the starting partition key.
 * @param startRowKey
 *            A <code>String</code> which represents the starting row key.
 * @param endPartitionKey
 *            A <code>String</code> which represents the ending partition key.
 * @param endRowKey
 *            A <code>String</code> which represents the ending end key.
 * @param ipRange
 *            A {@link IPRange} object containing the range of allowed IP addresses.
 * @param protocols
 *            A {@link SharedAccessProtocols} representing the allowed Internet protocols.
 *
 * @return A <code>String</code> containing the shared access signature for the table.
 *
 * @throws InvalidKeyException
 *             If an invalid key was passed.
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws IllegalArgumentException
 *             If an unexpected value is passed.
 */
public String generateSharedAccessSignature(
        final SharedAccessTablePolicy policy, final String accessPolicyIdentifier, final String startPartitionKey,
        final String startRowKey, final String endPartitionKey, final String endRowKey, final IPRange ipRange,
        final SharedAccessProtocols protocols)
        throws InvalidKeyException, StorageException {

    if (!StorageCredentialsHelper.canCredentialsSignRequest(this.tableServiceClient.getCredentials())) {
        throw new IllegalArgumentException(SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY);
    }

    final String resourceName = this.getSharedAccessCanonicalName();

    final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForTable(
            policy, accessPolicyIdentifier, resourceName, ipRange, protocols,
            startPartitionKey, startRowKey, endPartitionKey, endRowKey, this.tableServiceClient);

    final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForTable(
            policy, startPartitionKey, startRowKey, endPartitionKey, endRowKey, accessPolicyIdentifier,
            ipRange, protocols, this.name,  signature);

    return builder.toString();
}
 
Example #10
Source File: CloudQueue.java    From azure-storage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a shared access signature for the queue.
 * 
 * @param policy
 *            The access policy for the shared access signature.
 * @param groupPolicyIdentifier
 *            A queue-level access policy.
 * @param ipRange
 *            A {@link IPRange} object containing the range of allowed IP addresses.
 * @param protocols
 *            A {@link SharedAccessProtocols} representing the allowed Internet protocols.
 *            
 * @return A shared access signature for the queue.
 * 
 * @throws InvalidKeyException
 *             If an invalid key was passed.
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws IllegalArgumentException
 *             If an unexpected value is passed.
 */
public String generateSharedAccessSignature(
        final SharedAccessQueuePolicy policy, final String groupPolicyIdentifier, final IPRange ipRange,
        final SharedAccessProtocols protocols)
        throws InvalidKeyException, StorageException {

    if (!StorageCredentialsHelper.canCredentialsSignRequest(this.queueServiceClient.getCredentials())) {
        final String errorMessage = SR.CANNOT_CREATE_SAS_WITHOUT_ACCOUNT_KEY;
        throw new IllegalArgumentException(errorMessage);
    }

    final String resourceName = this.getSharedAccessCanonicalName();

    final String signature = SharedAccessSignatureHelper.generateSharedAccessSignatureHashForQueue(
            policy, groupPolicyIdentifier, resourceName, ipRange, protocols, this.queueServiceClient);

    final UriQueryBuilder builder = SharedAccessSignatureHelper.generateSharedAccessSignatureForQueue(
            policy, groupPolicyIdentifier, ipRange, protocols, signature);

    return builder.toString();
}