当前位置: 首页>>代码示例>>Java>>正文


Java StorageCredentialsAccountAndKey类代码示例

本文整理汇总了Java中com.microsoft.azure.storage.StorageCredentialsAccountAndKey的典型用法代码示例。如果您正苦于以下问题:Java StorageCredentialsAccountAndKey类的具体用法?Java StorageCredentialsAccountAndKey怎么用?Java StorageCredentialsAccountAndKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StorageCredentialsAccountAndKey类属于com.microsoft.azure.storage包,在下文中一共展示了StorageCredentialsAccountAndKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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;
    }
}
 
开发者ID:jgroups-extras,项目名称:jgroups-azure,代码行数:27,代码来源:AZURE_PING.java

示例2: areCredentialsEqual

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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);
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:36,代码来源:Utility.java

示例3: computeHmac256

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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;
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:27,代码来源:StorageCredentialsHelper.java

示例4: signBlobQueueAndFileRequest

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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));
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:37,代码来源:StorageCredentialsHelper.java

示例5: signTableRequest

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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));
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:36,代码来源:StorageCredentialsHelper.java

示例6: signBlobQueueAndFileRequest

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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));
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:37,代码来源:StorageCredentialsHelper.java

示例7: signTableRequest

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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));
    }
}
 
开发者ID:Azure,项目名称:azure-storage-java,代码行数:36,代码来源:StorageCredentialsHelper.java

示例8: connectUsingConnectionStringCredentials

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:AzureNativeFileSystemStore.java

示例9: connectUsingCredentials

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的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();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:AzureNativeFileSystemStore.java

示例10: generateSharedAccessSignature

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的package包/类
/**
 * 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.
 *
 * @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) 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, startPartitionKey, startRowKey, endPartitionKey, endRowKey,
            this.tableServiceClient, null);

    String accountKeyName = null;
    StorageCredentials credentials = this.tableServiceClient.getCredentials();

    if (credentials instanceof StorageCredentialsAccountAndKey) {
        accountKeyName = ((StorageCredentialsAccountAndKey) credentials).getAccountKeyName();
    }

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

    return builder.toString();
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:54,代码来源:CloudTable.java

示例11: canCredentialsSignRequest

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的package包/类
/** Reserved. */
public static boolean canCredentialsSignRequest(final StorageCredentials creds) {
    if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
        return true;
    }
    else {
        return false;
    }
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:10,代码来源:StorageCredentialsHelper.java

示例12: canCredentialsSignRequestLite

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的package包/类
/** Reserved. */
public static boolean canCredentialsSignRequestLite(final StorageCredentials creds) {
    if (creds.getClass().equals(StorageCredentialsAccountAndKey.class)) {
        return true;
    }
    else {
        return false;
    }
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:10,代码来源:StorageCredentialsHelper.java

示例13: deleteUnmanagedOsDisk

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的package包/类
private void deleteUnmanagedOsDisk(Azure api) {
    LOG.debug("deleting unmanaged OS disk for VM {} ...", this.vm.name());

    String osDiskUrl = this.vm.osUnmanagedDiskVhdUri();
    if (osDiskUrl == null) {
        LOG.warn("no unmanaged OS disk to delete found for VM {}.", this.vm.name());
        return;
    }

    LOG.debug("deleting unmanaged OS disk {}", osDiskUrl);
    URI osDiskUri = URI.create(osDiskUrl);
    String storageAccountName = extractStorageAccountName(osDiskUri);
    StorageAccount storageAccount = api.storageAccounts().getByResourceGroup(this.vm.resourceGroupName(),
            storageAccountName);

    // extract API access key to allow us to access the blob container
    StorageAccountKey accessKey = storageAccount.getKeys().get(0);
    StorageCredentialsAccountAndKey storageCredentials = new StorageCredentialsAccountAndKey(storageAccountName,
            accessKey.value());

    try {
        LOG.debug("deleting disk blob {} ...", osDiskUri);
        new CloudBlockBlob(osDiskUri, storageCredentials).delete();
    } catch (StorageException e) {
        throw new RuntimeException(String.format("failed to delete storage account blobs for VM %s: %s",
                this.vm.name(), e.getMessage()), e);
    }
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:29,代码来源:DeleteVmOsDiskRequest.java

示例14: AzureTableConfiguration

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的package包/类
@JsonCreator
public AzureTableConfiguration(@JsonProperty("accountName") String accountName,
                               @JsonProperty("accountKey") String accountKey,
                               @JsonProperty("timeout")Duration timeout,
                               @JsonProperty("retryInterval") Duration retryInterval,
                               @JsonProperty("retryAttempts") int retryAttempts) {
    this.retryInterval = checkNotNull(retryInterval, "retryInterval cannot be null");
    this.retryAttempts = retryAttempts;
    this.timeout = checkNotNull(timeout, "timeout cannot be null");
    this.storageCredentialsAccountAndKey =
            new StorageCredentialsAccountAndKey(
                    checkNotNull(accountName, "accountName cannot be null"),
                    checkNotNull(accountKey, "accountKey cannot be null"));
}
 
开发者ID:yammer,项目名称:breakerbox,代码行数:15,代码来源:AzureTableConfiguration.java

示例15: connect

import com.microsoft.azure.storage.StorageCredentialsAccountAndKey; //导入依赖的package包/类
@Override
public CloudBlobClient connect(final HostKeyCallback callback, final LoginCallback prompt) throws BackgroundException {
    try {
        final StorageCredentialsAccountAndKey credentials
            = new StorageCredentialsAccountAndKey(host.getCredentials().getUsername(), "null");
        // Client configured with no credentials
        final URI uri = new URI(String.format("%s://%s", Scheme.https, host.getHostname()));
        final CloudBlobClient client = new CloudBlobClient(uri, credentials);
        client.setDirectoryDelimiter(String.valueOf(Path.DELIMITER));
        final BlobRequestOptions options = new BlobRequestOptions();
        options.setRetryPolicyFactory(new RetryNoRetry());
        context.setLoggingEnabled(true);
        context.setLogger(LoggerFactory.getLogger(log.getName()));
        context.setUserHeaders(new HashMap<String, String>(Collections.singletonMap(
            HttpHeaders.USER_AGENT, new PreferencesUseragentProvider().get()))
        );
        context.getSendingRequestEventHandler().addListener(listener = new StorageEvent<SendingRequestEvent>() {
            @Override
            public void eventOccurred(final SendingRequestEvent event) {
                if(event.getConnectionObject() instanceof HttpsURLConnection) {
                    final HttpsURLConnection connection = (HttpsURLConnection) event.getConnectionObject();
                    connection.setSSLSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key));
                    connection.setHostnameVerifier(new DisabledX509HostnameVerifier());
                }
            }
        });
        final Proxy proxy = ProxyFactory.get().find(host);
        switch(proxy.getType()) {
            case SOCKS: {
                if(log.isInfoEnabled()) {
                    log.info(String.format("Configured to use SOCKS proxy %s", proxy));
                }
                final java.net.Proxy socksProxy = new java.net.Proxy(
                    java.net.Proxy.Type.SOCKS, new InetSocketAddress(proxy.getHostname(), proxy.getPort()));
                context.setProxy(socksProxy);
                break;
            }
            case HTTP:
            case HTTPS: {
                if(log.isInfoEnabled()) {
                    log.info(String.format("Configured to use HTTP proxy %s", proxy));
                }
                final java.net.Proxy httpProxy = new java.net.Proxy(
                    java.net.Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostname(), proxy.getPort()));
                context.setProxy(httpProxy);
                break;
            }
        }
        return client;
    }
    catch(URISyntaxException e) {
        throw new LoginFailureException(e.getMessage(), e);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:55,代码来源:AzureSession.java


注:本文中的com.microsoft.azure.storage.StorageCredentialsAccountAndKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。