From 1025246b12d20eeb419dc1553164d04e1a26f357 Mon Sep 17 00:00:00 2001 From: Alan Quillin Date: Mon, 11 Nov 2013 21:29:29 -0600 Subject: [PATCH] Added Support for the RAX-AUTH:authenticatedBy token property --- src/corelib/Core/Domain/AuthenticationType.cs | 81 +++++++++++++++++++ src/corelib/Core/Domain/IdentityToken.cs | 9 +++ src/corelib/corelib.v3.5.csproj | 1 + src/corelib/corelib.v4.0.csproj | 1 + src/testing/integration/Bootstrapper.cs | 7 +- .../Rackspace/ExtendedIdentityTests.cs | 5 +- .../Providers/Rackspace/UserIdentityTests.cs | 2 +- 7 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 src/corelib/Core/Domain/AuthenticationType.cs diff --git a/src/corelib/Core/Domain/AuthenticationType.cs b/src/corelib/Core/Domain/AuthenticationType.cs new file mode 100644 index 000000000..b679d794a --- /dev/null +++ b/src/corelib/Core/Domain/AuthenticationType.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Concurrent; +using Newtonsoft.Json; + +namespace net.openstack.Core.Domain +{ + /// + /// Represents the way a user has authenticated. + /// + /// + /// This class functions as a strongly-typed enumeration of known authentication types, + /// with added support for unknown types returned by a server extension. + /// + /// + /// + [JsonConverter(typeof(AuthenticationType.Converter))] + public class AuthenticationType : ExtensibleEnum + { + private static readonly ConcurrentDictionary _types = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + + private static readonly AuthenticationType _password = FromName("PASSWORD"); + private static readonly AuthenticationType _rsa = FromName("RSAKEY"); + + private AuthenticationType(string name) : base(name) + { + } + + /// + /// Gets the instance with the specified name. + /// + /// The name. + /// If is null. + /// If is empty. + public static AuthenticationType FromName(string name) + { + if (name == null) + throw new ArgumentNullException("name"); + if (string.IsNullOrEmpty(name)) + throw new ArgumentException("name cannot be empty"); + + return _types.GetOrAdd(name, i => new AuthenticationType(i)); + } + + /// + /// Gets an representing that a user authenticated using a password. + /// + public static AuthenticationType Password + { + get + { + return _password; + } + } + + /// + /// Gets an representing that a user authenticated using an RSA key. + /// + public static AuthenticationType RSA + { + get + { + return _rsa; + } + } + + /// + /// Provides support for serializing and deserializing objects to JSON string values. + /// + /// + /// + private sealed class Converter : ConverterBase + { + /// + protected override AuthenticationType FromName(string name) + { + return AuthenticationType.FromName(name); + } + } + } +} diff --git a/src/corelib/Core/Domain/IdentityToken.cs b/src/corelib/Core/Domain/IdentityToken.cs index de836ef00..ac95905c6 100644 --- a/src/corelib/Core/Domain/IdentityToken.cs +++ b/src/corelib/Core/Domain/IdentityToken.cs @@ -3,6 +3,7 @@ using System; using net.openstack.Core.Providers; using Newtonsoft.Json; + using System.Collections.Generic; /// /// Represents the authentication token used for making authenticated calls to @@ -51,5 +52,13 @@ public bool IsExpired return expiration <= DateTimeOffset.Now; } } + + /// + /// Gets a Collection of objects representing the ways the + /// user has authenticated. + /// + /// + [JsonProperty("RAX-AUTH:authenticatedBy", DefaultValueHandling = DefaultValueHandling.Ignore)] + public IEnumerable AuthenticationTypes { get; private set; } } } diff --git a/src/corelib/corelib.v3.5.csproj b/src/corelib/corelib.v3.5.csproj index a024a0a6e..7c13e29e6 100644 --- a/src/corelib/corelib.v3.5.csproj +++ b/src/corelib/corelib.v3.5.csproj @@ -197,6 +197,7 @@ + diff --git a/src/corelib/corelib.v4.0.csproj b/src/corelib/corelib.v4.0.csproj index b9ded9a57..5b83ce3f9 100644 --- a/src/corelib/corelib.v4.0.csproj +++ b/src/corelib/corelib.v4.0.csproj @@ -60,6 +60,7 @@ + diff --git a/src/testing/integration/Bootstrapper.cs b/src/testing/integration/Bootstrapper.cs index 119668c71..98e6e68ad 100644 --- a/src/testing/integration/Bootstrapper.cs +++ b/src/testing/integration/Bootstrapper.cs @@ -85,7 +85,7 @@ public class OpenstackNetSetings public ExtendedCloudIdentity TestAdminIdentity { get; set; } - public ExtendedCloudIdentity TestDomainIdentity { get; set; } + public ExtendedRackspaceCloudIdentity TestDomainIdentity { get; set; } public string RackspaceExtendedIdentityUrl { get; set; } @@ -107,6 +107,11 @@ public class ExtendedRackspaceCloudIdentity : RackspaceCloudIdentity { public string TenantId { get; set; } + public ExtendedRackspaceCloudIdentity() + { + + } + public ExtendedRackspaceCloudIdentity(ExtendedCloudIdentity cloudIdentity) { this.APIKey = cloudIdentity.APIKey; diff --git a/src/testing/integration/Providers/Rackspace/ExtendedIdentityTests.cs b/src/testing/integration/Providers/Rackspace/ExtendedIdentityTests.cs index fa2768203..950314538 100644 --- a/src/testing/integration/Providers/Rackspace/ExtendedIdentityTests.cs +++ b/src/testing/integration/Providers/Rackspace/ExtendedIdentityTests.cs @@ -4,7 +4,6 @@ using net.openstack.Core.Caching; using net.openstack.Core.Domain; using net.openstack.Core.Exceptions.Response; -using net.openstack.Core.Providers; using net.openstack.Providers.Rackspace; using net.openstack.Providers.Rackspace.Objects; @@ -16,7 +15,7 @@ public class ExtendedIdentityTests private TestContext testContextInstance; private static RackspaceCloudIdentity _testIdentity; private static RackspaceCloudIdentity _testAdminIdentity; - private static ExtendedRackspaceCloudIdentity _testDomainIdentity; + private static RackspaceCloudIdentity _testDomainIdentity; private static User _userDetails; private static User _adminUserDetails; private const string NewPassword = "My_n3w_p@$$w0rd"; @@ -42,7 +41,7 @@ public static void Init(TestContext context) { _testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity); _testAdminIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestAdminIdentity); - _testDomainIdentity = new ExtendedRackspaceCloudIdentity(Bootstrapper.Settings.TestDomainIdentity); + _testDomainIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestDomainIdentity); var provider = BuildProvider(); diff --git a/src/testing/integration/Providers/Rackspace/UserIdentityTests.cs b/src/testing/integration/Providers/Rackspace/UserIdentityTests.cs index 5bfe42128..c3008cf6a 100644 --- a/src/testing/integration/Providers/Rackspace/UserIdentityTests.cs +++ b/src/testing/integration/Providers/Rackspace/UserIdentityTests.cs @@ -464,7 +464,7 @@ public void TestDefaultIdentity() Assert.AreEqual(identity, provider.DefaultIdentity); IIdentityProvider defaultProvider = Bootstrapper.CreateIdentityProvider(); - Assert.IsNull(defaultProvider.DefaultIdentity); + Assert.IsNotNull(defaultProvider.DefaultIdentity); } } }