com.amazonaws.auth.AWS4Signer Java Examples

The following examples show how to use com.amazonaws.auth.AWS4Signer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsSdbProcessor.java    From camel-quarkus with Apache License 2.0 7 votes vote down vote up
@BuildStep(applicationArchiveMarkers = { AWS_SDB_APPLICATION_ARCHIVE_MARKERS })
void process(CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<NativeImageResourceBuildItem> resource) {

    resource.produce(new NativeImageResourceBuildItem("com/amazonaws/partitions/endpoints.json"));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
            Partitions.class.getCanonicalName(),
            Partition.class.getCanonicalName(),
            Endpoint.class.getCanonicalName(),
            Region.class.getCanonicalName(),
            Service.class.getCanonicalName(),
            CredentialScope.class.getCanonicalName(),
            QueryStringSigner.class.getCanonicalName(),
            AWS4Signer.class.getCanonicalName()));
}
 
Example #2
Source File: AwsUtil.java    From datacollector with Apache License 2.0 6 votes vote down vote up
public static AwsRequestSigningApacheInterceptor getAwsSigV4Interceptor(String awsServiceName,
                                                                        AwsRegion awsRegion,
                                                                        String otherEndpoint,
                                                                        CredentialValue awsAccessKeyId,
                                                                        CredentialValue awsSecretAccessKey)
    throws StageException {
  AWS4Signer signer = new AWS4Signer();
  signer.setServiceName(awsServiceName);

  if (awsRegion == AwsRegion.OTHER) {
    if (otherEndpoint == null || otherEndpoint.isEmpty()) {
      return null;
    }
    signer.setRegionName(otherEndpoint);
  } else {
    signer.setRegionName(awsRegion.getId());
  }

  return new AwsRequestSigningApacheInterceptor(
      awsServiceName,
      signer,
      AwsUtil.getCredentialsProvider(awsAccessKeyId, awsSecretAccessKey));
}
 
Example #3
Source File: AwsRequestSigner.java    From presto with Apache License 2.0 5 votes vote down vote up
public AwsRequestSigner(String region, AWSCredentialsProvider credentialsProvider)
{
    this.credentialsProvider = credentialsProvider;
    this.signer = new AWS4Signer();

    signer.setServiceName(SERVICE_NAME);
    signer.setRegionName(region);
}
 
Example #4
Source File: GenericApiGatewayClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #5
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 5 votes vote down vote up
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"));
}
 
Example #6
Source File: SkdSignerUtil.java    From aws-signing-request-interceptor with MIT License 5 votes vote down vote up
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");
}
 
Example #7
Source File: SignedRequest.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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();
}
 
Example #8
Source File: UrlSigningAuthConfig.java    From bender with Apache License 2.0 5 votes vote down vote up
public HttpRequestInterceptor getHttpInterceptor() {
  DefaultAWSCredentialsProviderChain cp = new DefaultAWSCredentialsProviderChain();

  AWS4Signer signer = new AWS4Signer();
  signer.setServiceName(this.service);
  signer.setRegionName(this.region.getName());

  return new AWSRequestSigningApacheInterceptor(this.service, signer, cp);
}
 
Example #9
Source File: AwsIamAuthentication.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
private static String getSignedHeaders(AwsIamAuthenticationOptions options, AWSCredentials credentials) {

		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, credentials);

		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);
		}
	}
 
Example #10
Source File: ElasticsearchRequestClientFilter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Inject
public ElasticsearchRequestClientFilter(final InjectableAWSCredentialsProvider awsCredentialsProvider,
                                        @Context final Configuration configuration,
                                        @Context final MessageBodyWorkers workers) {
  this.awsCredentialsProvider = awsCredentialsProvider;
  this.signer = new AWS4Signer();
  this.signer.setRegionName((String) configuration.getProperty(REGION_NAME));
  this.signer.setServiceName(SERVICE_NAME);
  this.workers = workers;
}
 
Example #11
Source File: GenericApiGatewayClient.java    From apigateway-generic-java-sdk with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #12
Source File: Sample.java    From aws-request-signing-apache-interceptor with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #13
Source File: AwsSwfProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep(applicationArchiveMarkers = { AWS_SWF_APPLICATION_ARCHIVE_MARKERS })
void process(CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<NativeImageResourceBuildItem> resource) {

    resource.produce(new NativeImageResourceBuildItem("com/amazonaws/partitions/endpoints.json"));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
            Partitions.class.getCanonicalName(),
            Partition.class.getCanonicalName(),
            Endpoint.class.getCanonicalName(),
            Region.class.getCanonicalName(),
            Service.class.getCanonicalName(),
            CredentialScope.class.getCanonicalName(),
            AWS4Signer.class.getCanonicalName()));
}
 
Example #14
Source File: AwsSQSProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep(applicationArchiveMarkers = { AWS_SQS_APPLICATION_ARCHIVE_MARKERS })
void process(CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<NativeImageResourceBuildItem> resource) {

    resource.produce(new NativeImageResourceBuildItem("com/amazonaws/partitions/endpoints.json"));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
            Partitions.class.getCanonicalName(),
            Partition.class.getCanonicalName(),
            Endpoint.class.getCanonicalName(),
            Region.class.getCanonicalName(),
            Service.class.getCanonicalName(),
            CredentialScope.class.getCanonicalName(),
            AWS4Signer.class.getCanonicalName()));
}
 
Example #15
Source File: AwsTranslateProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep(applicationArchiveMarkers = { AWS_TRANSLATE_APPLICATION_ARCHIVE_MARKERS })
void process(CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<NativeImageResourceBuildItem> resource) {

    resource.produce(new NativeImageResourceBuildItem("com/amazonaws/partitions/endpoints.json"));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
            Partitions.class.getCanonicalName(),
            Partition.class.getCanonicalName(),
            Endpoint.class.getCanonicalName(),
            Region.class.getCanonicalName(),
            Service.class.getCanonicalName(),
            CredentialScope.class.getCanonicalName(),
            AWS4Signer.class.getCanonicalName()));
}
 
Example #16
Source File: AwsSNSProcessor.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep(applicationArchiveMarkers = { AWS_SNS_APPLICATION_ARCHIVE_MARKERS })
void process(CombinedIndexBuildItem combinedIndexBuildItem,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<NativeImageResourceBuildItem> resource) {

    resource.produce(new NativeImageResourceBuildItem("com/amazonaws/partitions/endpoints.json"));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
            Partitions.class.getCanonicalName(),
            Partition.class.getCanonicalName(),
            Endpoint.class.getCanonicalName(),
            Region.class.getCanonicalName(),
            Service.class.getCanonicalName(),
            CredentialScope.class.getCanonicalName(),
            AWS4Signer.class.getCanonicalName()));
}
 
Example #17
Source File: AwsRestHighLevelClient.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
/**
 * A constructor for the client builder.
 * @param endpoint is the cluster's endpoint and is injected into the builder.
 */
public Builder(String endpoint)
{
    this.endpoint = endpoint;
    this.clientBuilder = RestClient.builder(HttpHost.create(this.endpoint));
    this.signer = new AWS4Signer();
    this.domainSplitter = Splitter.on(".");
}
 
Example #18
Source File: ElasticsearchBackendClient.java    From jmeter-elasticsearch-backend-listener with MIT License 4 votes vote down vote up
@Override
public void setupTest(BackendListenerContext context) throws Exception {
    try {
        this.filters = new HashSet<>();
        this.fields = new HashSet<>();
        this.modes = new HashSet<>(Arrays.asList("info", "debug", "error", "quiet"));
        this.bulkSize = Integer.parseInt(context.getParameter(ES_BULK_SIZE));
        this.timeoutMs = Integer.parseInt((context.getParameter(ES_TIMEOUT_MS)));
        this.buildNumber = (JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER) != null
                && !JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER).trim().equals(""))
                        ? Integer.parseInt(JMeterUtils.getProperty(ElasticsearchBackendClient.BUILD_NUMBER)) : 0;

        setSSLConfiguration(context);

        if (context.getParameter(ES_AWS_ENDPOINT).equalsIgnoreCase("")) {
            client = RestClient
                    .builder(new HttpHost(context.getParameter(ES_HOST),
                            Integer.parseInt(context.getParameter(ES_PORT)), context.getParameter(ES_SCHEME)))
                    .setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000)
                            .setSocketTimeout((int) timeoutMs))
                    .setFailureListener(new RestClient.FailureListener() {
                        @Override
                        public void onFailure(Node node) {
                            logger.error("Error with node: " + node.toString());
                        }
                    }).build();
        } else {
            AWS4Signer signer = new AWS4Signer();
            signer.setServiceName(SERVICE_NAME);
            signer.setRegionName(context.getParameter(ES_AWS_REGION));
            HttpRequestInterceptor interceptor = new AWSRequestSigningApacheInterceptor(SERVICE_NAME, signer,
                    credentialsProvider);
            client = RestClient.builder(HttpHost.create(context.getParameter(ES_AWS_ENDPOINT)))
                    .setHttpClientConfigCallback(hacb -> hacb.addInterceptorLast(interceptor)).build();
        }

        convertParameterToSet(context, ES_SAMPLE_FILTER, this.filters);
        convertParameterToSet(context, ES_FIELDS, this.fields);

        this.sender = new ElasticSearchMetricSender(client, context.getParameter(ES_INDEX).toLowerCase(),
                context.getParameter(ES_AUTH_USER), context.getParameter(ES_AUTH_PWD),
                context.getParameter(ES_AWS_ENDPOINT));
        this.sender.createIndex();
        this.esVersion = sender.getElasticSearchVersion();

        checkTestMode(context.getParameter(ES_TEST_MODE));
        super.setupTest(context);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to connect to the ElasticSearch engine", e);
    }
}