Skip to content

Commit 1025246

Browse files
author
Alan Quillin
committed
Added Support for the RAX-AUTH:authenticatedBy token property
1 parent 7bdc5d5 commit 1025246

File tree

7 files changed

+101
-5
lines changed

7 files changed

+101
-5
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using Newtonsoft.Json;
4+
5+
namespace net.openstack.Core.Domain
6+
{
7+
/// <summary>
8+
/// Represents the way a user has authenticated.
9+
/// </summary>
10+
/// <remarks>
11+
/// This class functions as a strongly-typed enumeration of known authentication types,
12+
/// with added support for unknown types returned by a server extension.
13+
/// </remarks>
14+
/// <threadsafety static="true" instance="false"/>
15+
/// <preliminary/>
16+
[JsonConverter(typeof(AuthenticationType.Converter))]
17+
public class AuthenticationType : ExtensibleEnum<AuthenticationType>
18+
{
19+
private static readonly ConcurrentDictionary<string, AuthenticationType> _types =
20+
new ConcurrentDictionary<string, AuthenticationType>(StringComparer.OrdinalIgnoreCase);
21+
22+
private static readonly AuthenticationType _password = FromName("PASSWORD");
23+
private static readonly AuthenticationType _rsa = FromName("RSAKEY");
24+
25+
private AuthenticationType(string name) : base(name)
26+
{
27+
}
28+
29+
/// <summary>
30+
/// Gets the <see cref="AuthenticationType"/> instance with the specified name.
31+
/// </summary>
32+
/// <param name="name">The name.</param>
33+
/// <exception cref="ArgumentNullException">If <paramref name="name"/> is <c>null</c>.</exception>
34+
/// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
35+
public static AuthenticationType FromName(string name)
36+
{
37+
if (name == null)
38+
throw new ArgumentNullException("name");
39+
if (string.IsNullOrEmpty(name))
40+
throw new ArgumentException("name cannot be empty");
41+
42+
return _types.GetOrAdd(name, i => new AuthenticationType(i));
43+
}
44+
45+
/// <summary>
46+
/// Gets an <see cref="AuthenticationType"/> representing that a user authenticated using a password.
47+
/// </summary>
48+
public static AuthenticationType Password
49+
{
50+
get
51+
{
52+
return _password;
53+
}
54+
}
55+
56+
/// <summary>
57+
/// Gets an <see cref="AuthenticationType"/> representing that a user authenticated using an RSA key.
58+
/// </summary>
59+
public static AuthenticationType RSA
60+
{
61+
get
62+
{
63+
return _rsa;
64+
}
65+
}
66+
67+
/// <summary>
68+
/// Provides support for serializing and deserializing <see cref="AuthenticationType"/> objects to JSON string values.
69+
/// </summary>
70+
/// <threadsafety static="true" instance="false"/>
71+
/// <preliminary/>
72+
private sealed class Converter : ConverterBase
73+
{
74+
/// <inheritdoc/>
75+
protected override AuthenticationType FromName(string name)
76+
{
77+
return AuthenticationType.FromName(name);
78+
}
79+
}
80+
}
81+
}

src/corelib/Core/Domain/IdentityToken.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using net.openstack.Core.Providers;
55
using Newtonsoft.Json;
6+
using System.Collections.Generic;
67

78
/// <summary>
89
/// Represents the authentication token used for making authenticated calls to
@@ -51,5 +52,13 @@ public bool IsExpired
5152
return expiration <= DateTimeOffset.Now;
5253
}
5354
}
55+
56+
/// <summary>
57+
/// Gets a Collection of <see cref="AuthenticationType"/> objects representing the ways the
58+
/// user has authenticated.
59+
/// </summary>
60+
/// <preliminary/>
61+
[JsonProperty("RAX-AUTH:authenticatedBy", DefaultValueHandling = DefaultValueHandling.Ignore)]
62+
public IEnumerable<AuthenticationType> AuthenticationTypes { get; private set; }
5463
}
5564
}

src/corelib/corelib.v3.5.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
<Compile Include="Providers\Rackspace\ILoadBalancerService.cs" />
198198
<Compile Include="Providers\Rackspace\NamespaceDoc.cs" />
199199
<Compile Include="Providers\Rackspace\Objects\ArchiveFormat.cs" />
200+
<Compile Include="Core\Domain\AuthenticationType.cs" />
200201
<Compile Include="Providers\Rackspace\Objects\BulkDeletionFailedObject.cs" />
201202
<Compile Include="Providers\Rackspace\Objects\BulkDeletionResults.cs" />
202203
<Compile Include="Providers\Rackspace\Objects\Dns\DnsChange.cs" />

src/corelib/corelib.v4.0.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="Core\Caching\ICache`1.cs" />
6161
<Compile Include="Core\Caching\NamespaceDoc.cs" />
6262
<Compile Include="Core\Domain\AuthenticationRequirement.cs" />
63+
<Compile Include="Core\Domain\AuthenticationType.cs" />
6364
<Compile Include="Core\Domain\Converters\NamespaceDoc.cs" />
6465
<Compile Include="Core\Domain\Converters\PhysicalAddressSimpleConverter.cs" />
6566
<Compile Include="Core\Domain\Converters\SimpleStringJsonConverter`1.cs" />

src/testing/integration/Bootstrapper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class OpenstackNetSetings
8585

8686
public ExtendedCloudIdentity TestAdminIdentity { get; set; }
8787

88-
public ExtendedCloudIdentity TestDomainIdentity { get; set; }
88+
public ExtendedRackspaceCloudIdentity TestDomainIdentity { get; set; }
8989

9090
public string RackspaceExtendedIdentityUrl { get; set; }
9191

@@ -107,6 +107,11 @@ public class ExtendedRackspaceCloudIdentity : RackspaceCloudIdentity
107107
{
108108
public string TenantId { get; set; }
109109

110+
public ExtendedRackspaceCloudIdentity()
111+
{
112+
113+
}
114+
110115
public ExtendedRackspaceCloudIdentity(ExtendedCloudIdentity cloudIdentity)
111116
{
112117
this.APIKey = cloudIdentity.APIKey;

src/testing/integration/Providers/Rackspace/ExtendedIdentityTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using net.openstack.Core.Caching;
55
using net.openstack.Core.Domain;
66
using net.openstack.Core.Exceptions.Response;
7-
using net.openstack.Core.Providers;
87
using net.openstack.Providers.Rackspace;
98
using net.openstack.Providers.Rackspace.Objects;
109

@@ -16,7 +15,7 @@ public class ExtendedIdentityTests
1615
private TestContext testContextInstance;
1716
private static RackspaceCloudIdentity _testIdentity;
1817
private static RackspaceCloudIdentity _testAdminIdentity;
19-
private static ExtendedRackspaceCloudIdentity _testDomainIdentity;
18+
private static RackspaceCloudIdentity _testDomainIdentity;
2019
private static User _userDetails;
2120
private static User _adminUserDetails;
2221
private const string NewPassword = "My_n3w_p@$$w0rd";
@@ -42,7 +41,7 @@ public static void Init(TestContext context)
4241
{
4342
_testIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestIdentity);
4443
_testAdminIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestAdminIdentity);
45-
_testDomainIdentity = new ExtendedRackspaceCloudIdentity(Bootstrapper.Settings.TestDomainIdentity);
44+
_testDomainIdentity = new RackspaceCloudIdentity(Bootstrapper.Settings.TestDomainIdentity);
4645

4746
var provider = BuildProvider();
4847

src/testing/integration/Providers/Rackspace/UserIdentityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public void TestDefaultIdentity()
464464
Assert.AreEqual(identity, provider.DefaultIdentity);
465465

466466
IIdentityProvider defaultProvider = Bootstrapper.CreateIdentityProvider();
467-
Assert.IsNull(defaultProvider.DefaultIdentity);
467+
Assert.IsNotNull(defaultProvider.DefaultIdentity);
468468
}
469469
}
470470
}

0 commit comments

Comments
 (0)