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


Java AWSCredentials.getAWSSecretKey方法代码示例

本文整理汇总了Java中com.amazonaws.auth.AWSCredentials.getAWSSecretKey方法的典型用法代码示例。如果您正苦于以下问题:Java AWSCredentials.getAWSSecretKey方法的具体用法?Java AWSCredentials.getAWSSecretKey怎么用?Java AWSCredentials.getAWSSecretKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.auth.AWSCredentials的用法示例。


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

示例1: sign

import com.amazonaws.auth.AWSCredentials; //导入方法依赖的package包/类
public void sign(SignableRequest<?> request, AWSCredentials credentials) throws SdkClientException {
    AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials);

    if ( sanitizedCredentials instanceof AWSSessionCredentials ) {
        addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials);
    }

    String expirationInSeconds = Long.toString(expiration.getTime() / 1000L);

    String canonicalString = RestUtils.makeS3CanonicalString(
            httpVerb, resourcePath, request, expirationInSeconds);

    String signature = super.signAndBase64Encode(canonicalString, sanitizedCredentials.getAWSSecretKey(), SigningAlgorithm.HmacSHA1);

    request.addParameter("AWSAccessKeyId", sanitizedCredentials.getAWSAccessKeyId());
    request.addParameter("Expires", expirationInSeconds);
    request.addParameter("Signature", signature);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:19,代码来源:S3QueryStringSigner.java

示例2: sign

import com.amazonaws.auth.AWSCredentials; //导入方法依赖的package包/类
@Override
public void sign(SignableRequest<?> request, AWSCredentials credentials) {

    if (resourcePath == null) {
        throw new UnsupportedOperationException(
                "Cannot sign a request using a dummy S3Signer instance with "
                        + "no resource path");
    }

    if (credentials == null || credentials.getAWSSecretKey() == null) {
        log.debug("Canonical string will not be signed, as no AWS Secret Key was provided");
        return;
    }

    AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials);
    if (sanitizedCredentials instanceof AWSSessionCredentials) {
        addSessionCredentials(request,
                (AWSSessionCredentials) sanitizedCredentials);
    }

    /*
     * In s3 sigv2, the way slash characters are encoded should be
     * consistent in both the request url and the encoded resource path.
     * Since we have to encode "//" to "/%2F" in the request url to make
     * httpclient works, we need to do the same encoding here for the
     * resource path.
     */
    String encodedResourcePath = SdkHttpUtils.appendUri(
            request.getEndpoint().getPath(), SdkHttpUtils.urlEncode(resourcePath, true),
            true);

    int timeOffset = request.getTimeOffset();
    Date date = getSignatureDate(timeOffset);
    request.addHeader(Headers.DATE, ServiceUtils.formatRfc822Date(date));
    String canonicalString = RestUtils.makeS3CanonicalString(httpVerb,
            encodedResourcePath, request, null, additionalQueryParamsToSign);
    log.debug("Calculated string to sign:\n\"" + canonicalString + "\"");

    String signature = super.signAndBase64Encode(canonicalString,
            sanitizedCredentials.getAWSSecretKey(),
            SigningAlgorithm.HmacSHA1);
    request.addHeader("Authorization",
            "AWS " + sanitizedCredentials.getAWSAccessKeyId() + ":"
                    + signature);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:46,代码来源:S3Signer.java


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