Java 类com.amazonaws.auth.AWS4Signer 实例源码

项目:aws-request-signing-apache-interceptor    文件:Sample.java   
CloseableHttpClient signingClientForServiceName(String serviceName) {
    AWS4Signer signer = new AWS4Signer();
    signer.setServiceName(serviceName);
    signer.setRegionName(AWS_REGION);

    HttpRequestInterceptor interceptor = new AWSRequestSigningApacheInterceptor(serviceName, signer, credentialsProvider);
    return HttpClients.custom()
            .addInterceptorLast(interceptor)
            .build();
}
项目:apigateway-generic-java-sdk    文件:GenericApiGatewayClient.java   
GenericApiGatewayClient(ClientConfiguration clientConfiguration, String endpoint, Region region,
                        AWSCredentialsProvider credentials, String apiKey, AmazonHttpClient httpClient) {
    super(clientConfiguration);
    setRegion(region);
    setEndpoint(endpoint);
    this.credentials = credentials;
    this.apiKey = apiKey;
    this.signer = new AWS4Signer();
    this.signer.setServiceName(API_GATEWAY_SERVICE_NAME);
    this.signer.setRegionName(region.getName());

    final JsonOperationMetadata metadata = new JsonOperationMetadata().withHasStreamingSuccessResponse(false).withPayloadJson(false);
    final Unmarshaller<GenericApiGatewayResponse, JsonUnmarshallerContext> responseUnmarshaller = in -> new GenericApiGatewayResponse(in.getHttpResponse());
    this.responseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createResponseHandler(metadata, responseUnmarshaller);
    JsonErrorUnmarshaller defaultErrorUnmarshaller = new JsonErrorUnmarshaller(GenericApiGatewayException.class, null) {
        @Override
        public AmazonServiceException unmarshall(JsonNode jsonContent) throws Exception {
            return new GenericApiGatewayException(jsonContent.toString());
        }
    };
    this.errorResponseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createErrorResponseHandler(
            Collections.singletonList(defaultErrorUnmarshaller), null);

    if (httpClient != null) {
        super.client = httpClient;
    }
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClientTest.java   
@Test
public void testDefaultSigner() {
    AmazonTestClient client = new AmazonTestClient();

    Assert.assertEquals("test", client.getServiceName());
    Assert.assertTrue(client.getSigner() instanceof AWS4Signer);
}
项目:spring-vault    文件:AwsIamAuthentication.java   
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);
        }
    }
项目:charles-rest    文件:SignedRequest.java   
@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();
}
项目:aws-signing-request-interceptor    文件:SkdSignerUtil.java   
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");
}
项目:ivona-speechcloud-sdk-java    文件:IvonaSpeechCloudClient.java   
private void init() {
    exceptionUnmarshallers = new ArrayList<JsonErrorUnmarshaller>();
    exceptionUnmarshallers.add(new JsonErrorUnmarshaller());

    signer = new AWS4Signer();
    signer.setServiceName(SERVICE_NAME);

    setServiceNameIntern(SERVICE_NAME);

    HandlerChainFactory chainFactory = new HandlerChainFactory();
    requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com.ivona.services/tts/request.handlers"));
    requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com.ivona.services/tts/request.handler2s"));
}
项目:async-sqs    文件:SqsAwsSdkAction.java   
@VisibleForTesting
void setRequestSigner(AWS4Signer signer) {
    this.requestSigner = signer;
}