skyscreamer / nevado

A JMS driver for Amazon SQS.
http://nevado.skyscreamer.org/
Apache License 2.0
51 stars 48 forks source link

Adding support for BasicSessionCredentials #74

Open xbranko opened 10 years ago

xbranko commented 10 years ago

Would it be possible to add support for BasicSessionCredentials too? In my company we use BasicSessionCredentials and not BasicAWSCredentials.

Looking at the code, it seems that this would require a minimal and rather local change to the constructor for the AmazonAwsSQSConnector, to allow it to get the sessionToken in addition to the current parameters:

 public AmazonAwsSQSConnector(String awsAccessKey, String awsSecretKey, String awsSessionToken, boolean isSecure, long receiveCheckIntervalMs) {
    this(awsAccessKey, awsSecretKey, awsSessionToken, isSecure, receiveCheckIntervalMs, false);
}

 public AmazonAwsSQSConnector(String awsAccessKey, String awsSecretKey, String awsSessionToken, boolean isSecure, long receiveCheckIntervalMs, boolean isAsync) {
    super(receiveCheckIntervalMs, isAsync);
    AWSCredentials awsCredentials = (awsSessionToken == null)? new BasicAWSCredentials(awsAccessKey, awsSecretKey) : new BasicSessionCredentials(awsAccessKey, awsSecretKey, awsSessionToken); 
// ... everything else stays the same

Other required change is in the AmazonAwsSQSConnectorFactory where the AmazonAwsSQSConnector is used:

 public AmazonAwsSQSConnector getInstance(String awsAccessKey, String awsSecretKey, String awsSessionToken, String awsSQSEndpoint, String awsSNSEndpoint) {
    AmazonAwsSQSConnector amazonAwsSQSConnector = new AmazonAwsSQSConnector(awsAccessKey, awsSecretKey, awsSessionToken, _isSecure,
            _receiveCheckIntervalMs, _useAsyncSend); 
// ... everything else stays the same

This way people who use BasicAWSCredentials will still be able to with minimal effort.

Many thanks in advance!