List of usage examples for com.amazonaws.auth BasicSessionCredentials getSessionToken
public String getSessionToken()
From source file:com.github.jramos.snowplow.RedshiftSinkEmitter.java
License:Apache License
protected String generateCopyStatement(String s3File, AWSCredentials credentials) { StringBuilder exec = new StringBuilder(); exec.append("COPY ").append(redshiftTable).append(" "); exec.append("FROM 's3://").append(s3Bucket).append("/").append(s3File).append("' "); exec.append("CREDENTIALS 'aws_access_key_id=").append(credentials.getAWSAccessKeyId()); exec.append(";aws_secret_access_key=").append(credentials.getAWSSecretKey()); if (credentials instanceof BasicSessionCredentials) { BasicSessionCredentials sessionCredentials = (BasicSessionCredentials) credentials; exec.append(";token=").append(sessionCredentials.getSessionToken()); }//w w w . j ava2s. c o m exec.append("' DELIMITER '").append(redshiftDelimiter).append("'"); if (configuration instanceof RedshiftSinkConfiguration) { RedshiftSinkConfiguration redshiftSinkConfiguration = (RedshiftSinkConfiguration) configuration; if (redshiftSinkConfiguration.hasRedshiftOptions()) { List<String> options = redshiftSinkConfiguration.getRedshiftOptions(); for (String option : options) { exec.append(" ").append(option); } } } exec.append(";"); return exec.toString(); }
From source file:com.okta.tools.awscli.java
License:Open Source License
private static String setAWSCredentials(AssumeRoleWithSAMLResult assumeResult, String credentialsProfileName) throws FileNotFoundException, UnsupportedEncodingException, IOException { BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials( assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken()); String awsAccessKey = temporaryCredentials.getAWSAccessKeyId(); String awsSecretKey = temporaryCredentials.getAWSSecretKey(); String awsSessionToken = temporaryCredentials.getSessionToken(); //File file = new File(System.getProperty("user.home") + "/.aws/credentials"); //file.getParentFile().mkdirs(); //try {// ww w .j a v a 2 s .c o m if (credentialsProfileName.startsWith("arn:aws:sts::")) { credentialsProfileName = credentialsProfileName.substring(13); } if (credentialsProfileName.contains(":assumed-role")) { credentialsProfileName = credentialsProfileName.replaceAll(":assumed-role", ""); } Object[] args = { new String(credentialsProfileName) }; //writer.println("[aws-okta]"); MessageFormat fmt = new MessageFormat("[{0}]"); String profileNameLine = fmt.format(args); ProfilesConfigFile profilesConfigFile = null; try { profilesConfigFile = new ProfilesConfigFile(); } catch (AmazonClientException ace) { PopulateCredentialsFile(profileNameLine, awsAccessKey, awsSecretKey, awsSessionToken); } try { if (profilesConfigFile != null && profilesConfigFile.getCredentials(credentialsProfileName) != null) { //if we end up here, it means we were able to find a matching profile PopulateCredentialsFile(profileNameLine, awsAccessKey, awsSecretKey, awsSessionToken); } } catch (IllegalArgumentException iae) { //if we end up here, it means we were not able to find a matching profile so we need to append one FileWriter fileWriter = new FileWriter(System.getProperty("user.home") + "/.aws/credentials", true); //TODO: need to be updated to work with Windows PrintWriter writer = new PrintWriter(fileWriter); // new PrintWriter(file, "UTF-8"); WriteNewProfile(writer, profileNameLine, awsAccessKey, awsSecretKey, awsSessionToken); fileWriter.close(); } return credentialsProfileName; }
From source file:io.hekate.cluster.seed.jclouds.aws.AwsCredentialsSupplier.java
License:Apache License
@Override public Credentials get() { String identity = getIdentity() != null ? getIdentity().trim() : null; String credential = getCredential() != null ? getCredential().trim() : null; if (identity == null || identity.isEmpty() || credential == null || credential.isEmpty()) { DefaultAWSCredentialsProviderChain chain = new DefaultAWSCredentialsProviderChain(); AWSCredentials cred = chain.getCredentials(); if (cred instanceof BasicSessionCredentials) { BasicSessionCredentials sesCred = (BasicSessionCredentials) cred; return new SessionCredentials.Builder().identity(sesCred.getAWSAccessKeyId()) .credential(sesCred.getAWSSecretKey()).sessionToken(sesCred.getSessionToken()).build(); } else {/*w ww .j a v a 2s.c o m*/ return new Credentials.Builder<>().identity(cred.getAWSAccessKeyId()) .credential(cred.getAWSSecretKey()).build(); } } return super.get(); }