本文整理汇总了Java中com.microsoft.azure.storage.StorageCredentials类的典型用法代码示例。如果您正苦于以下问题:Java StorageCredentials类的具体用法?Java StorageCredentials怎么用?Java StorageCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StorageCredentials类属于com.microsoft.azure.storage包,在下文中一共展示了StorageCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
@Override
public void init() throws Exception {
super.init();
// Validate configuration
// Can throw IAEs
this.validateConfiguration();
try {
StorageCredentials credentials = new StorageCredentialsAccountAndKey(storage_account_name, storage_access_key);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, use_https);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
containerReference = blobClient.getContainerReference(container);
boolean created = containerReference.createIfNotExists();
if (created) {
log.info("Created container named '%s'.", container);
} else {
log.debug("Using existing container named '%s'.", container);
}
} catch (Exception ex) {
log.error("Error creating a storage client! Check your configuration.");
throw ex;
}
}
示例2: areCredentialsEqual
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Returns a value that indicates whether the specified credentials are equal.
*
* @param thisCred
* An object derived from {@link StorageCredentials} that represents the first set of credentials being
* compared for equality.
* @param thatCred
* An object derived from <code>StorageCredentials</code> that represents the second set of credentials
* being compared for equality.
*
* @return <code>true</code> if the credentials are equal; otherwise, <code>false</code>.
*/
public static boolean areCredentialsEqual(final StorageCredentials thisCred, final StorageCredentials thatCred) {
if (thisCred == thatCred) {
return true;
}
if (thatCred == null || thisCred.getClass() != thatCred.getClass()) {
return false;
}
if (thisCred instanceof StorageCredentialsAccountAndKey) {
return ((StorageCredentialsAccountAndKey) thisCred).toString(true).equals(
((StorageCredentialsAccountAndKey) thatCred).toString(true));
}
else if (thisCred instanceof StorageCredentialsSharedAccessSignature) {
return ((StorageCredentialsSharedAccessSignature) thisCred).getToken().equals(
((StorageCredentialsSharedAccessSignature) thatCred).getToken());
}
else if (thisCred instanceof StorageCredentialsAnonymous) {
return true;
}
return thisCred.equals(thatCred);
}
示例3: getBlobReference
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
public static CloudBlob getBlobReference(BlobType type, StorageCredentials credentials, URI uri)
throws StorageException, URISyntaxException {
CloudBlob blob = null;
switch (type) {
case APPEND_BLOB:
blob = new CloudAppendBlob(credentials.transformUri(uri));
break;
case BLOCK_BLOB:
blob = new CloudBlockBlob(credentials.transformUri(uri));
break;
case PAGE_BLOB:
blob = new CloudPageBlob(credentials.transformUri(uri));
break;
case UNSPECIFIED:
fail();
}
return blob;
}
示例4: testIsUsePathStyleUri
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
private static void testIsUsePathStyleUri(StorageCredentials creds, String tableEndpoint, boolean usePathStyleUris)
throws URISyntaxException, InvalidKeyException, StorageException {
CloudTableClient tableClient = new CloudTableClient(new URI(tableEndpoint), creds);
assertEquals(usePathStyleUris, tableClient.isUsePathStyleUris());
CloudTable table = tableClient.getTableReference("mytable");
assertEquals(tableEndpoint + "/mytable", table.getUri().toString());
String sasToken = table.generateSharedAccessSignature(null, "fakeIdentifier", null, null, null, null);
tableClient = new CloudTableClient(new URI(tableEndpoint),
new StorageCredentialsSharedAccessSignature(sasToken));
assertEquals(usePathStyleUris, tableClient.isUsePathStyleUris());
table = new CloudTable(table.getUri(), tableClient.getCredentials());
assertEquals(tableEndpoint + "/mytable", table.getUri().toString());
}
示例5: computeHmac256
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Computes a signature for the specified string using the HMAC-SHA256 algorithm.
*
* @param value
* The UTF-8-encoded string to sign.
*
* @return A <code>String</code> that contains the HMAC-SHA256-encoded signature.
*
* @throws InvalidKeyException
* If the key is not a valid Base64-encoded string.
*/
public static synchronized String computeHmac256(final StorageCredentials creds, final String value) throws InvalidKeyException {
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
byte[] utf8Bytes = null;
try {
utf8Bytes = value.getBytes(Constants.UTF8_CHARSET);
}
catch (final UnsupportedEncodingException e) {
throw new IllegalArgumentException(e);
}
return Base64.encode(((StorageCredentialsAccountAndKey) creds).getHmac256().doFinal(utf8Bytes));
}
else {
return null;
}
}
示例6: signBlobQueueAndFileRequest
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Signs a request using the specified operation context under the Shared Key authentication scheme.
*
* @param request
* An <code>HttpURLConnection</code> object that represents the request to sign.
* @param contentLength
* The length of the content written to the output stream. If unknown, specify -1.
* @param opContext
* An {@link 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.
*
* @throws InvalidKeyException
* If the given key is invalid.
* @throws StorageException
* If a storage service error occurred.
*/
public static void signBlobQueueAndFileRequest(final StorageCredentials creds,
final java.net.HttpURLConnection request, final long contentLength, OperationContext opContext)
throws InvalidKeyException, StorageException {
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
opContext = opContext == null ? new OperationContext() : opContext;
request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime());
final Canonicalizer canonicalizer = CanonicalizerFactory.getBlobQueueFileCanonicalizer(request);
final String stringToSign = canonicalizer.canonicalize(request, creds.getAccountName(), contentLength);
final String computedBase64Signature = StorageCredentialsHelper.computeHmac256(creds, stringToSign);
Logger.debug(opContext, LogConstants.SIGNING, stringToSign);
request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION,
String.format("%s %s:%s", "SharedKey", creds.getAccountName(), computedBase64Signature));
}
}
示例7: signTableRequest
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Signs a request using the specified operation context under the Shared Key authentication scheme.
*
* @param request
* An <code>HttpURLConnection</code> object that represents the request to sign.
* @param contentLength
* The length of the content written to the output stream. If unknown, specify -1.
* @param opContext
* An {@link 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.
*
* @throws InvalidKeyException
* If the given key is invalid.
* @throws StorageException
* If a storage service error occurred.
*/
public static void signTableRequest(final StorageCredentials creds, final java.net.HttpURLConnection request,
final long contentLength, OperationContext opContext) throws InvalidKeyException, StorageException {
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
opContext = opContext == null ? new OperationContext() : opContext;
request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime());
final Canonicalizer canonicalizer = CanonicalizerFactory.getTableCanonicalizer(request);
final String stringToSign = canonicalizer.canonicalize(request, creds.getAccountName(), contentLength);
final String computedBase64Signature = StorageCredentialsHelper.computeHmac256(creds, stringToSign);
Logger.debug(opContext, LogConstants.SIGNING, stringToSign);
request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION,
String.format("%s %s:%s", "SharedKey", creds.getAccountName(), computedBase64Signature));
}
}
示例8: signBlobQueueAndFileRequest
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Signs a request using the specified operation context under the Shared Key authentication scheme.
*
* @param request
* An <code>HttpURLConnection</code> object that represents the request to sign.
* @param contentLength
* The length of the content written to the output stream. If unknown, specify -1.
* @param opContext
* An {@link 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.
*
* @throws InvalidKeyException
* If the given key is invalid.
* @throws StorageException
* If a storage service error occurred.
*/
public static void signBlobQueueAndFileRequest(final StorageCredentials creds,
final java.net.HttpURLConnection request, final long contentLength, OperationContext opContext)
throws InvalidKeyException, StorageException {
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
opContext = opContext == null ? new OperationContext() : opContext;
request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime());
final Canonicalizer canonicalizer = CanonicalizerFactory.getBlobQueueFileCanonicalizer(request);
final String stringToSign = canonicalizer.canonicalize(request, creds.getAccountName(), contentLength);
final String computedBase64Signature = StorageCredentialsHelper.computeHmac256(creds, stringToSign);
Logger.trace(opContext, LogConstants.SIGNING, stringToSign);
request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION,
String.format("%s %s:%s", "SharedKey", creds.getAccountName(), computedBase64Signature));
}
}
示例9: signTableRequest
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Signs a request using the specified operation context under the Shared Key authentication scheme.
*
* @param request
* An <code>HttpURLConnection</code> object that represents the request to sign.
* @param contentLength
* The length of the content written to the output stream. If unknown, specify -1.
* @param opContext
* An {@link 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.
*
* @throws InvalidKeyException
* If the given key is invalid.
* @throws StorageException
* If a storage service error occurred.
*/
public static void signTableRequest(final StorageCredentials creds, final java.net.HttpURLConnection request,
final long contentLength, OperationContext opContext) throws InvalidKeyException, StorageException {
if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
opContext = opContext == null ? new OperationContext() : opContext;
request.setRequestProperty(Constants.HeaderConstants.DATE, Utility.getGMTTime());
final Canonicalizer canonicalizer = CanonicalizerFactory.getTableCanonicalizer(request);
final String stringToSign = canonicalizer.canonicalize(request, creds.getAccountName(), contentLength);
final String computedBase64Signature = StorageCredentialsHelper.computeHmac256(creds, stringToSign);
Logger.trace(opContext, LogConstants.SIGNING, stringToSign);
request.setRequestProperty(Constants.HeaderConstants.AUTHORIZATION,
String.format("%s %s:%s", "SharedKey", creds.getAccountName(), computedBase64Signature));
}
}
示例10: SendRequestIntercept
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Constructor for SendRequestThrottle.
*
* @param storageCreds
* - storage account credentials for signing packets.
*
*/
private SendRequestIntercept(StorageCredentials storageCreds,
boolean allowConcurrentOOBIo, OperationContext opContext) {
// Capture the send delay callback interface.
this.storageCreds = storageCreds;
this.allowConcurrentOOBIo = allowConcurrentOOBIo;
this.opContext = opContext;
}
示例11: connectUsingConnectionStringCredentials
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Connect to Azure storage using account key credentials.
*/
private void connectUsingConnectionStringCredentials(
final String accountName, final String containerName,
final String accountKey) throws InvalidKeyException, StorageException,
IOException, URISyntaxException {
// If the account name is "acc.blob.core.windows.net", then the
// rawAccountName is just "acc"
String rawAccountName = accountName.split("\\.")[0];
StorageCredentials credentials = new StorageCredentialsAccountAndKey(
rawAccountName, accountKey);
connectUsingCredentials(accountName, credentials, containerName);
}
示例12: connectUsingSASCredentials
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Connect to Azure storage using shared access signature credentials.
*/
private void connectUsingSASCredentials(final String accountName,
final String containerName, final String sas) throws InvalidKeyException,
StorageException, IOException, URISyntaxException {
StorageCredentials credentials = new StorageCredentialsSharedAccessSignature(
sas);
connectingUsingSAS = true;
connectUsingCredentials(accountName, credentials, containerName);
}
示例13: connectUsingCredentials
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
private void connectUsingCredentials(String accountName,
StorageCredentials credentials, String containerName)
throws URISyntaxException, StorageException, AzureException {
URI blobEndPoint;
if (isStorageEmulatorAccount(accountName)) {
isStorageEmulator = true;
CloudStorageAccount account =
CloudStorageAccount.getDevelopmentStorageAccount();
storageInteractionLayer.createBlobClient(account);
} else {
blobEndPoint = new URI(getHTTPScheme() + "://" +
accountName);
storageInteractionLayer.createBlobClient(blobEndPoint, credentials);
}
suppressRetryPolicyInClientIfNeeded();
// Capture the container reference for debugging purposes.
container = storageInteractionLayer.getContainerReference(containerName);
rootDirectory = container.getDirectoryReference("");
// Can only create container if using account key credentials
canCreateOrModifyContainer = credentials instanceof StorageCredentialsAccountAndKey;
// Configure Azure storage session.
configureAzureStorageSession();
}
示例14: getAzureStorageClient
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Gets the Azure storage SDK client.
*/
public static CloudStorageAccount getAzureStorageClient(String connectionString) throws Exception {
if (AzureUtils.isAzureClientMock()) {
URI blobServiceUri = UriUtils.buildUri(AzureUtils.getAzureBaseUri() + "blob-storage-service");
URI queueServiceUri = UriUtils.buildUri(AzureUtils.getAzureBaseUri() + "queue-storage-service");
URI tableServiceUri = UriUtils.buildUri(AzureUtils.getAzureBaseUri() + "table-storage-service");
URI fileServiceUri = UriUtils.buildUri(AzureUtils.getAzureBaseUri() + "file-storage-service");
return new CloudStorageAccount(StorageCredentials.tryParseCredentials(connectionString), blobServiceUri,
queueServiceUri, tableServiceUri, fileServiceUri);
} else {
return CloudStorageAccount.parse(connectionString);
}
}
示例15: CloudBlobClient
import com.microsoft.azure.storage.StorageCredentials; //导入依赖的package包/类
/**
* Creates an instance of the <code>CloudBlobClient</code> class using the specified Blob service endpoint and
* account credentials.
*
* @param storageUri
* A {@link StorageUri} object that represents the Blob service endpoint used to create the
* client.
* @param credentials
* A {@link StorageCredentials} object that represents the account credentials.
*/
public CloudBlobClient(final StorageUri storageUri, StorageCredentials credentials) {
super(storageUri, credentials);
this.defaultRequestOptions = new BlobRequestOptions();
this.defaultRequestOptions.setLocationMode(LocationMode.PRIMARY_ONLY);
this.defaultRequestOptions.setRetryPolicyFactory(new RetryExponentialRetry());
this.defaultRequestOptions.setConcurrentRequestCount(BlobConstants.DEFAULT_CONCURRENT_REQUEST_COUNT);
this.defaultRequestOptions.setDisableContentMD5Validation(false);
this.defaultRequestOptions
.setSingleBlobPutThresholdInBytes(BlobConstants.DEFAULT_SINGLE_BLOB_PUT_THRESHOLD_IN_BYTES);
this.defaultRequestOptions.setUseTransactionalContentMD5(false);
}