using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Amazon.Runtime;
using Amazon.SecurityToken.Model;
namespace Amazon.SecurityToken
{
///
/// Credentials that are retrieved by invoking AWS Security Token Service
/// AssumeRole or AssumeRoleWithSAML action.
///
[Obsolete("This class has been replaced by Amazon.Runtime.AssumeRoleAWSCredentials and Amazon.Runtime.StoredProfileFederatedCredentials, and will be removed in a future version.", false)]
public partial class STSAssumeRoleAWSCredentials : RefreshingAWSCredentials, IDisposable
{
private IAmazonSecurityTokenService _stsClient;
private AssumeRoleRequest _assumeRequest;
private AssumeRoleWithSAMLRequest _assumeSamlRequest;
private bool _isDisposed = false;
private static TimeSpan _defaultPreemptExpiryTime = TimeSpan.FromMinutes(5);
///
/// Instantiates STSAssumeRoleAWSCredentials which automatically assumes a specified role.
/// The credentials are refreshed before expiration.
///
///
/// Instance of IAmazonSecurityTokenService that will be used to make the AssumeRole service call.
///
/// Configuration for the role to assume.
public STSAssumeRoleAWSCredentials(IAmazonSecurityTokenService sts, AssumeRoleRequest assumeRoleRequest)
{
if (sts == null) throw new ArgumentNullException("sts");
if (assumeRoleRequest == null) throw new ArgumentNullException("assumeRoleRequest");
_stsClient = sts;
_assumeRequest = assumeRoleRequest;
PreemptExpiryTime = _defaultPreemptExpiryTime;
}
///
/// Instantiates STSAssumeRoleAWSCredentials which automatically assumes a specified SAML role.
/// The credentials are refreshed before expiration.
///
/// Configuration for the SAML role to assume.
public STSAssumeRoleAWSCredentials(AssumeRoleWithSAMLRequest assumeRoleWithSamlRequest)
{
if (assumeRoleWithSamlRequest == null) throw new ArgumentNullException("assumeRoleWithSamlRequest");
_stsClient = new AmazonSecurityTokenServiceClient(new AnonymousAWSCredentials());
_assumeSamlRequest = assumeRoleWithSamlRequest;
PreemptExpiryTime = _defaultPreemptExpiryTime;
}
///
/// Generate new credentials.
///
///
protected override CredentialsRefreshState GenerateNewCredentials()
{
Credentials credentials = GetServiceCredentials();
return new CredentialsRefreshState
{
Expiration = credentials.Expiration,
Credentials = credentials.GetCredentials()
};
}
#region Dispose Pattern Implementation
///
/// Implements the Dispose pattern
///
/// Whether this object is being disposed via a call to Dispose
/// or garbage collected.
protected virtual void Dispose(bool disposing)
{
if (!this._isDisposed)
{
if (disposing && _stsClient != null)
{
_stsClient.Dispose();
_stsClient = null;
}
this._isDisposed = true;
}
}
///
/// Disposes of all managed and unmanaged resources.
///
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}