All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.distelli.aws.AWSCredentialsProviderFactory Maven / Gradle / Ivy

There is a newer version: 3.8.16
Show newest version
package com.distelli.aws;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.BasicSessionCredentials;
import com.distelli.cred.CredPair;
import com.distelli.cred.CredProvider;
import javax.inject.Singleton;
import javax.inject.Inject;

@Singleton
public class AWSCredentialsProviderFactory {
    private static class Impl implements AWSCredentialsProvider {
        private CredProvider _credProvider;

        private Impl(CredProvider credProvider) {
            _credProvider = credProvider;
        }

        @Override
        public AWSCredentials getCredentials() {
            CredPair credPair = _credProvider.getCredPair();
            String secret = credPair.getSecret();
            if ( null != secret && secret.contains("\u001E") ) {
                String[] secretPair = secret.split("\u001E", 2);
                return new BasicSessionCredentials(credPair.getKeyId(), secretPair[0], secretPair[1]);
            } else {
                return new BasicAWSCredentials(credPair.getKeyId(), secret);
            }
        }

        @Override
        public void refresh() {
            _credProvider.refresh();
        }
    }

    @Inject
    protected AWSCredentialsProviderFactory(){}

    public AWSCredentialsProvider create(CredProvider credProvider) {
        if ( null == credProvider ) throw new IllegalArgumentException("CredProvider can not be null");
        return new Impl(credProvider);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy