/** * Gets S3 access key. * * @return S3 access key. */ public String getAccessKey() { return cred.getAWSAccessKeyId(); }
public String getAccessKeyId() { return iamCredProvider.getCredentials().getAWSAccessKeyId(); }
public Profile(String profileName, AWSCredentials awsCredentials) { Map<String, String> properties = new LinkedHashMap<String, String>(); properties.put(ProfileKeyConstants.AWS_ACCESS_KEY_ID, awsCredentials.getAWSAccessKeyId()); properties.put(ProfileKeyConstants.AWS_SECRET_ACCESS_KEY, awsCredentials.getAWSSecretKey()); if (awsCredentials instanceof AWSSessionCredentials) { AWSSessionCredentials sessionCred = (AWSSessionCredentials)awsCredentials; properties.put(ProfileKeyConstants.AWS_SESSION_TOKEN, sessionCred.getSessionToken()); } this.profileName = profileName; this.properties = properties; this.awsCredentials = new StaticCredentialsProvider(awsCredentials); }
/** * Creates the authorization header to be included in the request. */ private String buildAuthorizationHeader(SignableRequest<?> request, byte[] signature, AWSCredentials credentials, AWS4SignerRequestParams signerParams) { final String signingCredentials = credentials.getAWSAccessKeyId() + "/" + signerParams.getScope(); final String credential = "Credential=" + signingCredentials; final String signerHeaders = "SignedHeaders=" + getSignedHeadersString(request); final String signatureHeader = "Signature=" + BinaryUtils.toHex(signature); final StringBuilder authHeaderBuilder = new StringBuilder(); authHeaderBuilder.append(AWS4_SIGNING_ALGORITHM) .append(" ") .append(credential) .append(", ") .append(signerHeaders) .append(", ") .append(signatureHeader); return authHeaderBuilder.toString(); }
/** * Gets a session credentials provider for the long-term credentials and * service endpoint given. These are shared globally to support reuse of * session tokens. * * @param longTermCredentials * The long-term AWS account credentials used to initiate a * session. * @param serviceEndpoint * The service endpoint for the service the session credentials * will be used to access. * @param stsClientConfiguration * Client configuration for the {@link AWSSecurityTokenService} * used to fetch session credentials. */ public static synchronized STSSessionCredentialsProvider getSessionCredentialsProvider(AWSCredentials longTermCredentials, String serviceEndpoint, ClientConfiguration stsClientConfiguration) { Key key = new Key(longTermCredentials.getAWSAccessKeyId(), serviceEndpoint); if ( !cache.containsKey(key) ) { cache.put(key, new STSSessionCredentialsProvider(longTermCredentials, stsClientConfiguration)); } return cache.get(key); } }
@Override public AWSCredentials getCredentials() { if (reuseLastProvider && lastUsedProvider != null) { return lastUsedProvider.getCredentials(); } List<String> exceptionMessages = null; for (AWSCredentialsProvider provider : credentialsProviders) { try { AWSCredentials credentials = provider.getCredentials(); if (credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) { log.debug("Loading credentials from " + provider.toString()); lastUsedProvider = provider; return credentials; } } catch (Exception e) { // Ignore any exceptions and move onto the next provider String message = provider + ": " + e.getMessage(); log.debug("Unable to load credentials from " + message); if (exceptionMessages == null) { exceptionMessages = new LinkedList<String>(); } exceptionMessages.add(message); } } throw new SdkClientException("Unable to load AWS credentials from any provider in the chain: " + exceptionMessages); }
private void init() { if(StringUtils.isEmpty(creds.getAWSAccessKeyId())){ throw new AmazonClientException("could not get aws access key from system properties"); } if(StringUtils.isEmpty(creds.getAWSSecretKey())){ throw new AmazonClientException("could not get aws secret key from system properties"); } }
String token = null; synchronized (credentials) { accessKeyId = credentials.getAWSAccessKeyId(); secretKey = credentials.getAWSSecretKey(); if ( credentials instanceof AWSSessionCredentials ) {
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
cachedEndpoint = cache.get(awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), false, endpoint);
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); }
/** * Includes all the signing headers as request parameters for pre-signing. */ private void addPreSignInformationToRequest(SignableRequest<?> request, AWSCredentials credentials, AWS4SignerRequestParams signerParams, String timeStamp, long expirationInSeconds) { String signingCredentials = credentials.getAWSAccessKeyId() + "/" + signerParams.getScope(); request.addParameter(X_AMZ_ALGORITHM, AWS4_SIGNING_ALGORITHM); request.addParameter(X_AMZ_DATE, timeStamp); request.addParameter(X_AMZ_SIGNED_HEADER, getSignedHeadersString(request)); request.addParameter(X_AMZ_EXPIRES, Long.toString(expirationInSeconds)); request.addParameter(X_AMZ_CREDENTIAL, signingCredentials); }