List of usage examples for com.amazonaws.auth AWS4Signer AWS4Signer
public AWS4Signer()
From source file:com.comcast.cmb.common.controller.AdminServletBase.java
License:Apache License
protected String httpPOST(String baseUrl, String urlString, AWSCredentials awsCredentials) { URL url;//from w w w.j a v a 2s .c om HttpURLConnection conn; BufferedReader br; String line; String doc = ""; try { String urlPost = urlString.substring(0, urlString.indexOf("?")); url = new URL(urlPost); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("test"); Request<CreateQueueRequest> request = new CreateQueueRequestMarshaller().marshall(createQueueRequest); //set parameters from url String parameterString = urlString.substring(urlString.indexOf("?") + 1); String[] parameterArray = parameterString.split("&"); Map<String, String> requestParameters = new HashMap<String, String>(); for (int i = 0; i < parameterArray.length; i++) { requestParameters.put(parameterArray[i].substring(0, parameterArray[i].indexOf("=")), parameterArray[i].substring(parameterArray[i].indexOf("=") + 1)); } request.setParameters(requestParameters); //get endpoint from url URI uri = new URI(baseUrl); request.setEndpoint(uri); String resourcePath = urlString.substring(baseUrl.length(), urlString.indexOf("?")); request.setResourcePath(resourcePath); AWS4Signer aws4Signer = new AWS4Signer(); String host = uri.getHost(); aws4Signer.setServiceName(host); aws4Signer.sign(request, awsCredentials); //set headers for real request for (Entry<String, String> entry : request.getHeaders().entrySet()) { conn.setRequestProperty(entry.getKey(), entry.getValue()); } // Send post request conn.setDoOutput(true); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); StringBuffer bodyStringBuffer = new StringBuffer(); for (Entry<String, String> entry : requestParameters.entrySet()) { bodyStringBuffer.append(entry.getKey() + "=" + entry.getValue() + "&"); } String bodyString = ""; if (bodyStringBuffer.length() > 0) { bodyString = bodyStringBuffer.substring(0, bodyStringBuffer.length() - 1); } wr.writeBytes(bodyString); wr.flush(); wr.close(); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = br.readLine()) != null) { doc += line; } br.close(); logger.info("event=http_get url=" + urlString); } catch (Exception ex) { logger.error("event=http_get url=" + urlString, ex); } return doc; }
From source file:com.eucalyptus.ws.handlers.IoInternalHmacHandler.java
License:Open Source License
private void sign(final FullHttpRequest request) { final AWS4Signer signer = new AWS4Signer(); signer.setRegionName("eucalyptus"); signer.setServiceName("internal"); signer.sign(wrapRequest(request), credentials()); }
From source file:com.ghedeon.AwsInterceptor.java
License:Apache License
public AwsInterceptor(@Nonnull AWSCredentialsProvider credentialsProvider, @Nonnull String serviceName, @Nonnull String region) { this.credentialsProvider = credentialsProvider; this.serviceName = serviceName; signer = new AWS4Signer(); signer.setServiceName(serviceName);/*from w w w . ja v a 2 s . com*/ signer.setRegionName(region); }
From source file:com.ivona.services.tts.IvonaSpeechCloudClient.java
License:Open Source License
private void init() { exceptionUnmarshallers = new ArrayList<JsonErrorUnmarshaller>(); exceptionUnmarshallers.add(new JsonErrorUnmarshaller()); signer = new AWS4Signer(); signer.setServiceName(SERVICE_NAME); setServiceNameIntern(SERVICE_NAME);//w w w . j av a2s. com HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com.ivona.services/tts/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com.ivona.services/tts/request.handler2s")); }
From source file:com.streamsets.pipeline.lib.aws.AwsUtil.java
License:Apache License
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; }/*from ww w .j a v a 2 s.com*/ signer.setRegionName(otherEndpoint); } else { signer.setRegionName(awsRegion.getId()); } return new AwsRequestSigningApacheInterceptor(awsServiceName, signer, AwsUtil.getCredentialsProvider(awsAccessKeyId, awsSecretAccessKey)); }
From source file:org.springframework.vault.authentication.AwsIamAuthentication.java
License:Apache License
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);/*from w ww . j av a2s. com*/ 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); } }
From source file:zipkin.autoconfigure.storage.elasticsearch.aws.ElasticsearchAwsRequestSigner.java
License:Apache License
@Override public void process(HttpRequest hr, HttpContext hc) { AWSCredentials creds = credentialsProvider.getCredentials(); AWS4Signer signer = new AWS4Signer(); signer.setServiceName("es"); signer.setRegionName(region);//from ww w .ja va2 s. co m signer.sign(new SignableHttpRequest(hr, hc), creds); }