com.amazonaws.auth.SystemPropertiesCredentialsProvider Java Examples

The following examples show how to use com.amazonaws.auth.SystemPropertiesCredentialsProvider. 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: AmazonS3Manager.java    From carina with Apache License 2.0 6 votes vote down vote up
public static AmazonS3Manager getInstance() {
    if (instance == null) {
        synchronized (AmazonS3Manager.class) {
            if (instance == null) {
                instance = new AmazonS3Manager();
                CryptoTool cryptoTool = new CryptoTool(Configuration.get(Parameter.CRYPTO_KEY_PATH));
                Pattern CRYPTO_PATTERN = Pattern.compile(SpecialKeywords.CRYPT);
                
                String accessKey = cryptoTool.decryptByPattern(Configuration.get(Parameter.ACCESS_KEY_ID), CRYPTO_PATTERN);
                String secretKey = cryptoTool.decryptByPattern(Configuration.get(Parameter.SECRET_KEY), CRYPTO_PATTERN);

                System.setProperty("aws.accessKeyId", accessKey);
                System.setProperty("aws.secretKey", secretKey);

                s3client = new AmazonS3Client(new SystemPropertiesCredentialsProvider());
            }
        }
    }
    return instance;
}
 
Example #2
Source File: App.java    From djl-demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
        throws IOException, ModelNotFoundException, MalformedModelException {
    AmazonKinesisVideoClientBuilder amazonKinesisVideoBuilder =
            AmazonKinesisVideoClientBuilder.standard();
    amazonKinesisVideoBuilder.setRegion(REGION.getName());
    amazonKinesisVideoBuilder.setCredentials(new SystemPropertiesCredentialsProvider());
    AmazonKinesisVideo amazonKinesisVideo = amazonKinesisVideoBuilder.build();

    File outDir = Paths.get("build/out").toFile();
    if (!outDir.exists()) {
        outDir.mkdir();
    }

    for (File outFile : outDir.listFiles()) {
        outFile.delete();
    }

    FrameVisitor frameVisitor = FrameVisitor.create(new DjlImageVisitor());

    ExecutorService executorService = Executors.newFixedThreadPool(1);

    GetMediaWorker getMediaWorker =
            GetMediaWorker.create(
                    REGION,
                    new SystemPropertiesCredentialsProvider(),
                    STREAM_NAME,
                    new StartSelector().withStartSelectorType(StartSelectorType.NOW),
                    amazonKinesisVideo,
                    frameVisitor);
    executorService.submit(getMediaWorker);
}
 
Example #3
Source File: AWSLambdaConfiguration.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 * @param clientConfiguration clientConfiguration
 * @param environment environment
 */
public AWSLambdaConfiguration(AWSClientConfiguration clientConfiguration, Environment environment) {
    this.clientConfiguration = clientConfiguration;

    this.builder.setCredentials(new AWSCredentialsProviderChain(
        new EnvironmentAWSCredentialsProvider(environment),
        new EnvironmentVariableCredentialsProvider(),
        new SystemPropertiesCredentialsProvider(),
        new ProfileCredentialsProvider(),
        new EC2ContainerCredentialsProviderWrapper()
    ));
}
 
Example #4
Source File: Main.java    From java-almanac with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
private static IMultiReportOutput createS3Output() {
	AmazonS3 s3Client = AmazonS3ClientBuilder.standard() //
			.withRegion("us-east-1") //
			.withCredentials(new SystemPropertiesCredentialsProvider()) //
			.build();
	return new S3MultiReportOutput(s3Client, "download.eclipselab.org", "jdkdiff/");
}
 
Example #5
Source File: AuthenticationInfoAWSCredentialsProviderChain.java    From lambadaframework with MIT License 5 votes vote down vote up
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
    super(
            new InstanceProfileCredentialsProvider(),
            new ProfileCredentialsProvider(),
            new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}
 
Example #6
Source File: AwsModule.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public AWSCredentialsProvider deserializeWithType(
    JsonParser jsonParser, DeserializationContext context, TypeDeserializer typeDeserializer)
    throws IOException {
  Map<String, String> asMap =
      jsonParser.readValueAs(new TypeReference<Map<String, String>>() {});

  String typeNameKey = typeDeserializer.getPropertyName();
  String typeName = asMap.get(typeNameKey);
  if (typeName == null) {
    throw new IOException(
        String.format("AWS credentials provider type name key '%s' not found", typeNameKey));
  }

  if (typeName.equals(AWSStaticCredentialsProvider.class.getSimpleName())) {
    return new AWSStaticCredentialsProvider(
        new BasicAWSCredentials(asMap.get(AWS_ACCESS_KEY_ID), asMap.get(AWS_SECRET_KEY)));
  } else if (typeName.equals(PropertiesFileCredentialsProvider.class.getSimpleName())) {
    return new PropertiesFileCredentialsProvider(asMap.get(CREDENTIALS_FILE_PATH));
  } else if (typeName.equals(
      ClasspathPropertiesFileCredentialsProvider.class.getSimpleName())) {
    return new ClasspathPropertiesFileCredentialsProvider(asMap.get(CREDENTIALS_FILE_PATH));
  } else if (typeName.equals(DefaultAWSCredentialsProviderChain.class.getSimpleName())) {
    return new DefaultAWSCredentialsProviderChain();
  } else if (typeName.equals(EnvironmentVariableCredentialsProvider.class.getSimpleName())) {
    return new EnvironmentVariableCredentialsProvider();
  } else if (typeName.equals(SystemPropertiesCredentialsProvider.class.getSimpleName())) {
    return new SystemPropertiesCredentialsProvider();
  } else if (typeName.equals(ProfileCredentialsProvider.class.getSimpleName())) {
    return new ProfileCredentialsProvider();
  } else if (typeName.equals(EC2ContainerCredentialsProviderWrapper.class.getSimpleName())) {
    return new EC2ContainerCredentialsProviderWrapper();
  } else {
    throw new IOException(
        String.format("AWS credential provider type '%s' is not supported", typeName));
  }
}
 
Example #7
Source File: DeployTask.java    From gradle-beanstalk-plugin with MIT License 5 votes vote down vote up
@TaskAction
protected void deploy() {
    String versionLabel = getVersionLabel();

    AWSCredentialsProviderChain credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(beanstalk.getProfile()), new EC2ContainerCredentialsProviderWrapper());

    BeanstalkDeployer deployer = new BeanstalkDeployer(beanstalk.getS3Endpoint(), beanstalk.getBeanstalkEndpoint(), credentialsProvider);

    File warFile = getProject().files(war).getSingleFile();
    deployer.deploy(warFile, deployment.getApplication(), deployment.getEnvironment(), deployment.getTemplate(), versionLabel);
}
 
Example #8
Source File: AWSClusterSecurityManager.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
DefaultAWSCredentialsProviderChain(Config config) {
  super(new EnvironmentVariableCredentialsProvider(),
          new SystemPropertiesCredentialsProvider(),
          new ConfigurationCredentialsProvider(config),
          new ProfileCredentialsProvider(),
          new InstanceProfileCredentialsProvider());
}
 
Example #9
Source File: AWSUtil.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * If the provider is ASSUME_ROLE, then the credentials for assuming this role are determined
 * recursively.
 *
 * @param configProps the configuration properties
 * @param configPrefix the prefix of the config properties for this credentials provider,
 *                     e.g. aws.credentials.provider for the base credentials provider,
 *                     aws.credentials.provider.role.provider for the credentials provider
 *                     for assuming a role, and so on.
 */
private static AWSCredentialsProvider getCredentialsProvider(final Properties configProps, final String configPrefix) {
	CredentialProvider credentialProviderType;
	if (!configProps.containsKey(configPrefix)) {
		if (configProps.containsKey(AWSConfigConstants.accessKeyId(configPrefix))
			&& configProps.containsKey(AWSConfigConstants.secretKey(configPrefix))) {
			// if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC
			credentialProviderType = CredentialProvider.BASIC;
		} else {
			// if the credential provider type is not specified, it will default to AUTO
			credentialProviderType = CredentialProvider.AUTO;
		}
	} else {
		credentialProviderType = CredentialProvider.valueOf(configProps.getProperty(configPrefix));
	}

	switch (credentialProviderType) {
		case ENV_VAR:
			return new EnvironmentVariableCredentialsProvider();

		case SYS_PROP:
			return new SystemPropertiesCredentialsProvider();

		case PROFILE:
			String profileName = configProps.getProperty(
					AWSConfigConstants.profileName(configPrefix), null);
			String profileConfigPath = configProps.getProperty(
					AWSConfigConstants.profilePath(configPrefix), null);
			return (profileConfigPath == null)
				? new ProfileCredentialsProvider(profileName)
				: new ProfileCredentialsProvider(profileConfigPath, profileName);

		case BASIC:
			return new AWSCredentialsProvider() {
				@Override
				public AWSCredentials getCredentials() {
					return new BasicAWSCredentials(
						configProps.getProperty(AWSConfigConstants.accessKeyId(configPrefix)),
						configProps.getProperty(AWSConfigConstants.secretKey(configPrefix)));
				}

				@Override
				public void refresh() {
					// do nothing
				}
			};

		case ASSUME_ROLE:
			final AWSSecurityTokenService baseCredentials = AWSSecurityTokenServiceClientBuilder.standard()
					.withCredentials(getCredentialsProvider(configProps, AWSConfigConstants.roleCredentialsProvider(configPrefix)))
					.withRegion(configProps.getProperty(AWSConfigConstants.AWS_REGION))
					.build();
			return new STSAssumeRoleSessionCredentialsProvider.Builder(
					configProps.getProperty(AWSConfigConstants.roleArn(configPrefix)),
					configProps.getProperty(AWSConfigConstants.roleSessionName(configPrefix)))
					.withExternalId(configProps.getProperty(AWSConfigConstants.externalId(configPrefix)))
					.withStsClient(baseCredentials)
					.build();

		default:
		case AUTO:
			return new DefaultAWSCredentialsProviderChain();
	}
}
 
Example #10
Source File: AWSUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * If the provider is ASSUME_ROLE, then the credentials for assuming this role are determined
 * recursively.
 *
 * @param configProps the configuration properties
 * @param configPrefix the prefix of the config properties for this credentials provider,
 *                     e.g. aws.credentials.provider for the base credentials provider,
 *                     aws.credentials.provider.role.provider for the credentials provider
 *                     for assuming a role, and so on.
 */
private static AWSCredentialsProvider getCredentialsProvider(final Properties configProps, final String configPrefix) {
	CredentialProvider credentialProviderType;
	if (!configProps.containsKey(configPrefix)) {
		if (configProps.containsKey(AWSConfigConstants.accessKeyId(configPrefix))
			&& configProps.containsKey(AWSConfigConstants.secretKey(configPrefix))) {
			// if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC
			credentialProviderType = CredentialProvider.BASIC;
		} else {
			// if the credential provider type is not specified, it will default to AUTO
			credentialProviderType = CredentialProvider.AUTO;
		}
	} else {
		credentialProviderType = CredentialProvider.valueOf(configProps.getProperty(configPrefix));
	}

	switch (credentialProviderType) {
		case ENV_VAR:
			return new EnvironmentVariableCredentialsProvider();

		case SYS_PROP:
			return new SystemPropertiesCredentialsProvider();

		case PROFILE:
			String profileName = configProps.getProperty(
					AWSConfigConstants.profileName(configPrefix), null);
			String profileConfigPath = configProps.getProperty(
					AWSConfigConstants.profilePath(configPrefix), null);
			return (profileConfigPath == null)
				? new ProfileCredentialsProvider(profileName)
				: new ProfileCredentialsProvider(profileConfigPath, profileName);

		case BASIC:
			return new AWSCredentialsProvider() {
				@Override
				public AWSCredentials getCredentials() {
					return new BasicAWSCredentials(
						configProps.getProperty(AWSConfigConstants.accessKeyId(configPrefix)),
						configProps.getProperty(AWSConfigConstants.secretKey(configPrefix)));
				}

				@Override
				public void refresh() {
					// do nothing
				}
			};

		case ASSUME_ROLE:
			final AWSSecurityTokenService baseCredentials = AWSSecurityTokenServiceClientBuilder.standard()
					.withCredentials(getCredentialsProvider(configProps, AWSConfigConstants.roleCredentialsProvider(configPrefix)))
					.withRegion(configProps.getProperty(AWSConfigConstants.AWS_REGION))
					.build();
			return new STSAssumeRoleSessionCredentialsProvider.Builder(
					configProps.getProperty(AWSConfigConstants.roleArn(configPrefix)),
					configProps.getProperty(AWSConfigConstants.roleSessionName(configPrefix)))
					.withExternalId(configProps.getProperty(AWSConfigConstants.externalId(configPrefix)))
					.withStsClient(baseCredentials)
					.build();

		default:
		case AUTO:
			return new DefaultAWSCredentialsProviderChain();
	}
}
 
Example #11
Source File: DynamoStreamsManager.java    From dynamo-cassandra-proxy with Apache License 2.0 4 votes vote down vote up
public void configure(DCProxyConfiguration config) {

        //TODO make table name dynamic
        String tableName = "test";

        this.dynamodbEndpoint = config.getAwsDynamodbEndpoint();
        this.streamsEndpoint = config.getStreamsEndpoint();
        this.signinRegion = config.getDynamoRegion();
        this.accessKey = config.getDynamoAccessKey();
        this.secretKey = config.getDynamoSecretKey();

        Properties props = System.getProperties();
        props.setProperty("aws.accessKeyId", accessKey);
        props.setProperty("aws.secretKey", secretKey);

        AwsClientBuilder.EndpointConfiguration endpointConfiguration =
                new AwsClientBuilder.EndpointConfiguration(streamsEndpoint, signinRegion);
        SystemPropertiesCredentialsProvider spcp = new SystemPropertiesCredentialsProvider();

        realDDB = AmazonDynamoDBClientBuilder.standard().
                withRegion(Regions.US_EAST_2).
                //withEndpointConfiguration(endpointConfiguration).
                withCredentials(spcp).build();

        DescribeTableResult tableResult = realDDB.describeTable(tableName);
        streamArn = tableResult.getTable().getLatestStreamArn();
        //streamSpec = tableResult.getTable().getStreamSpecification();
        streamsClient = AmazonDynamoDBStreamsClientBuilder.standard().withEndpointConfiguration(endpointConfiguration).build();

        adapterClient = new AmazonDynamoDBStreamsAdapterClient(streamsClient);

        recordProcessorFactory = new StreamsRecordProcessorFactory(ddbProxy, tableName);

        workerConfig = new KinesisClientLibConfiguration("test-app",
                streamArn,
                spcp,
                "streams-worker")
                .withMaxRecords(1000)
                .withIdleTimeBetweenReadsInMillis(500)
                .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON);
        AmazonCloudWatch cloudWatchClient;
        cloudWatchClient = AmazonCloudWatchClientBuilder.standard()
        .withRegion(signinRegion)
        .build();

        System.out.println("Creating worker for stream: " + streamArn);

        /*
        DescribeStreamRequest request = new DescribeStreamRequest();
        DescribeStreamRequestAdapter describeStreamResult = new DescribeStreamRequestAdapter(request);
        String id = describeStreamResult.getExclusiveStartShardId();
        String id2 = describeStreamResult.withStreamArn(streamArn).getExclusiveStartShardId();
        */

        Worker worker = StreamsWorkerFactory.createDynamoDbStreamsWorker(
                recordProcessorFactory,
                workerConfig,
                adapterClient,
                realDDB,
                cloudWatchClient
        );

        System.out.println("Starting worker...");
        Thread t = new Thread(worker);
        t.start();
    }
 
Example #12
Source File: AuthHelper.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 4 votes vote down vote up
public static AWSCredentialsProvider getSystemPropertiesCredentialsProvider() {
    return new SystemPropertiesCredentialsProvider();
}
 
Example #13
Source File: CustomCredentialsProviderChain.java    From strongbox with Apache License 2.0 4 votes vote down vote up
public CustomCredentialsProviderChain(ClientConfiguration clientConfiguration, ProfileIdentifier profile, Supplier<MFAToken> mfaTokenSupplier) {
    super(new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new ProfileCredentialProvider(clientConfiguration, profile, mfaTokenSupplier),
            new EC2ContainerCredentialsProviderWrapper());
}
 
Example #14
Source File: CustomCredentialsProviderChain.java    From aws-big-data-blog with Apache License 2.0 4 votes vote down vote up
public CustomCredentialsProviderChain() {
    super(new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(),
            new ClasspathPropertiesFileCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}
 
Example #15
Source File: AWSUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * If the provider is ASSUME_ROLE, then the credentials for assuming this role are determined
 * recursively.
 *
 * @param configProps the configuration properties
 * @param configPrefix the prefix of the config properties for this credentials provider,
 *                     e.g. aws.credentials.provider for the base credentials provider,
 *                     aws.credentials.provider.role.provider for the credentials provider
 *                     for assuming a role, and so on.
 */
private static AWSCredentialsProvider getCredentialsProvider(final Properties configProps, final String configPrefix) {
	CredentialProvider credentialProviderType;
	if (!configProps.containsKey(configPrefix)) {
		if (configProps.containsKey(AWSConfigConstants.accessKeyId(configPrefix))
			&& configProps.containsKey(AWSConfigConstants.secretKey(configPrefix))) {
			// if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC
			credentialProviderType = CredentialProvider.BASIC;
		} else {
			// if the credential provider type is not specified, it will default to AUTO
			credentialProviderType = CredentialProvider.AUTO;
		}
	} else {
		credentialProviderType = CredentialProvider.valueOf(configProps.getProperty(configPrefix));
	}

	switch (credentialProviderType) {
		case ENV_VAR:
			return new EnvironmentVariableCredentialsProvider();

		case SYS_PROP:
			return new SystemPropertiesCredentialsProvider();

		case PROFILE:
			String profileName = configProps.getProperty(
					AWSConfigConstants.profileName(configPrefix), null);
			String profileConfigPath = configProps.getProperty(
					AWSConfigConstants.profilePath(configPrefix), null);
			return (profileConfigPath == null)
				? new ProfileCredentialsProvider(profileName)
				: new ProfileCredentialsProvider(profileConfigPath, profileName);

		case BASIC:
			return new AWSCredentialsProvider() {
				@Override
				public AWSCredentials getCredentials() {
					return new BasicAWSCredentials(
						configProps.getProperty(AWSConfigConstants.accessKeyId(configPrefix)),
						configProps.getProperty(AWSConfigConstants.secretKey(configPrefix)));
				}

				@Override
				public void refresh() {
					// do nothing
				}
			};

		case ASSUME_ROLE:
			final AWSSecurityTokenService baseCredentials = AWSSecurityTokenServiceClientBuilder.standard()
					.withCredentials(getCredentialsProvider(configProps, AWSConfigConstants.roleCredentialsProvider(configPrefix)))
					.withRegion(configProps.getProperty(AWSConfigConstants.AWS_REGION))
					.build();
			return new STSAssumeRoleSessionCredentialsProvider.Builder(
					configProps.getProperty(AWSConfigConstants.roleArn(configPrefix)),
					configProps.getProperty(AWSConfigConstants.roleSessionName(configPrefix)))
					.withExternalId(configProps.getProperty(AWSConfigConstants.externalId(configPrefix)))
					.withStsClient(baseCredentials)
					.build();

		case WEB_IDENTITY_TOKEN:
			return WebIdentityTokenCredentialsProvider.builder()
					.roleArn(configProps.getProperty(AWSConfigConstants.roleArn(configPrefix), null))
					.roleSessionName(configProps.getProperty(AWSConfigConstants.roleSessionName(configPrefix), null))
					.webIdentityTokenFile(configProps.getProperty(AWSConfigConstants.webIdentityTokenFile(configPrefix), null))
					.build();

		default:
		case AUTO:
			return new DefaultAWSCredentialsProviderChain();
	}
}
 
Example #16
Source File: CustomCredentialsProviderChain.java    From kinesis-log4j-appender with Apache License 2.0 4 votes vote down vote up
public CustomCredentialsProviderChain() {
  super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(),
      new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider());
}