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


Java AWS4Signer.sign方法代码示例

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


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

示例1: getSignedHeaders

import com.amazonaws.auth.AWS4Signer; //导入方法依赖的package包/类
private static String getSignedHeaders(AwsIamAuthenticationOptions options) {

		Map<String, String> headers = createIamRequestHeaders(options);

		AWS4Signer signer = new AWS4Signer();

		DefaultRequest<String> request = new DefaultRequest<>("sts");

		request.setContent(new ByteArrayInputStream(REQUEST_BODY.getBytes()));
		request.setHeaders(headers);
		request.setHttpMethod(HttpMethodName.POST);
		request.setEndpoint(options.getEndpointUri());

		signer.setServiceName(request.getServiceName());
		signer.sign(request, options.getCredentialsProvider().getCredentials());

		Map<String, Object> map = new LinkedHashMap<>();

		for (Entry<String, String> entry : request.getHeaders().entrySet()) {
			map.put(entry.getKey(), Collections.singletonList(entry.getValue()));
		}

		try {
			return OBJECT_MAPPER.writeValueAsString(map);
		}
		catch (JsonProcessingException e) {
			throw new IllegalStateException("Cannot serialize headers to JSON", e);
		}
	}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:30,代码来源:AwsIamAuthentication.java

示例2: perform

import com.amazonaws.auth.AWS4Signer; //导入方法依赖的package包/类
@Override
public T perform() {
    AWS4Signer signer = new AWS4Signer();
    String region = this.reg.read();
    if(region == null || region.isEmpty()) {
        throw new IllegalStateException("Mandatory sys property aws.es.region not specified!");
    }
    signer.setRegionName(this.reg.read());
    signer.setServiceName(this.base.request().getServiceName());
    signer.sign(this.base.request(), new AwsCredentialsFromSystem(this.accesskey, this.secretKey));
    return this.base.perform();
}
 
开发者ID:opencharles,项目名称:charles-rest,代码行数:13,代码来源:SignedRequest.java

示例3: getExpectedAuthorizationHeader

import com.amazonaws.auth.AWS4Signer; //导入方法依赖的package包/类
static public String getExpectedAuthorizationHeader(Request request) throws Exception {
    // create the signable request
    DefaultRequest signableRequest = new DefaultRequest(null, request.getServiceName());
    signableRequest.setEndpoint(new URI("http://" + request.getHost()));
    signableRequest.setResourcePath(request.getUri());
    signableRequest.setHttpMethod(HttpMethodName.valueOf(request.getHttpMethod()));
    signableRequest.setContent(new StringInputStream(request.getBody()));
    if (request.getHeaders() != null)
        signableRequest.setHeaders(request.getHeaders());
    if (request.getQueryParams() != null) {
        Map<String, List<String>> convertedQueryParams = new HashMap<>();
        for (String paramName : request.getQueryParams().keySet()) {
            convertedQueryParams.put(paramName, new ArrayList<>(request.getQueryParams().get(paramName)));
        }
        signableRequest.setParameters(convertedQueryParams);
    }

    /*
       Init the signer class

       Note: Double uri encoding is off simple before the signature does not match the expected signature of the test cases
       if it is enabled.  This was a bit unexpected because AWSElasticsearchClient (AWS SDK Class) enabled double URI encoding
       in the signer by default.  I can only assume that double encoding is needed when accessing the service but not when accessing
       elasticsearch.
     */
    AWS4Signer aws4Signer = new AWS4Signer(false);
    aws4Signer.setServiceName(request.getServiceName());
    aws4Signer.setRegionName(request.getRegion());
    Method method1 = AWS4Signer.class.getDeclaredMethod("setOverrideDate", Date.class);
    method1.setAccessible(true);
    method1.invoke(aws4Signer, request.getDate());
    aws4Signer.sign(signableRequest, request.getCredentialsProvider().getCredentials());

    return (String) signableRequest.getHeaders().get("Authorization");
}
 
开发者ID:inreachventures,项目名称:aws-signing-request-interceptor,代码行数:36,代码来源:SkdSignerUtil.java


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