Skip to content

Commit

Permalink
Merge pull request #255 from alanquillin/AddSupportForAuthenticatedBy…
Browse files Browse the repository at this point in the history
…TokenProperty

Added Support for the RAX-AUTH:authenticatedBy token property
  • Loading branch information
alanquillin committed Nov 12, 2013
2 parents 7bdc5d5 + 1025246 commit f2eae72
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 5 deletions.
81 changes: 81 additions & 0 deletions src/corelib/Core/Domain/AuthenticationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Concurrent;
using Newtonsoft.Json;

namespace net.openstack.Core.Domain
{
/// <summary>
/// Represents the way a user has authenticated.
/// </summary>
/// <remarks>
/// This class functions as a strongly-typed enumeration of known authentication types,
/// with added support for unknown types returned by a server extension.
/// </remarks>
/// <threadsafety static="true" instance="false"/>
/// <preliminary/>
[JsonConverter(typeof(AuthenticationType.Converter))]
public class AuthenticationType : ExtensibleEnum<AuthenticationType>
{
private static readonly ConcurrentDictionary<string, AuthenticationType> _types =
new ConcurrentDictionary<string, AuthenticationType>(StringComparer.OrdinalIgnoreCase);

private static readonly AuthenticationType _password = FromName("PASSWORD");
private static readonly AuthenticationType _rsa = FromName("RSAKEY");

private AuthenticationType(string name) : base(name)
{
}

/// <summary>
/// Gets the <see cref="AuthenticationType"/> instance with the specified name.
/// </summary>
/// <param name="name">The name.</param>
/// <exception cref="ArgumentNullException">If <paramref name="name"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
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));
}

/// <summary>
/// Gets an <see cref="AuthenticationType"/> representing that a user authenticated using a password.
/// </summary>
public static AuthenticationType Password
{
get
{
return _password;
}
}

/// <summary>
/// Gets an <see cref="AuthenticationType"/> representing that a user authenticated using an RSA key.
/// </summary>
public static AuthenticationType RSA
{
get
{
return _rsa;
}
}

/// <summary>
/// Provides support for serializing and deserializing <see cref="AuthenticationType"/> objects to JSON string values.
/// </summary>
/// <threadsafety static="true" instance="false"/>
/// <preliminary/>
private sealed class Converter : ConverterBase
{
/// <inheritdoc/>
protected override AuthenticationType FromName(string name)
{
return AuthenticationType.FromName(name);
}
}
}
}
9 changes: 9 additions & 0 deletions src/corelib/Core/Domain/IdentityToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using net.openstack.Core.Providers;
using Newtonsoft.Json;
using System.Collections.Generic;

/// <summary>
/// Represents the authentication token used for making authenticated calls to
Expand Down Expand Up @@ -51,5 +52,13 @@ public bool IsExpired
return expiration <= DateTimeOffset.Now;
}
}

/// <summary>
/// Gets a Collection of <see cref="AuthenticationType"/> objects representing the ways the
/// user has authenticated.
/// </summary>
/// <preliminary/>
[JsonProperty("RAX-AUTH:authenticatedBy", DefaultValueHandling = DefaultValueHandling.Ignore)]
public IEnumerable<AuthenticationType> AuthenticationTypes { get; private set; }
}
}
1 change: 1 addition & 0 deletions src/corelib/corelib.v3.5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<Compile Include="Providers\Rackspace\ILoadBalancerService.cs" />
<Compile Include="Providers\Rackspace\NamespaceDoc.cs" />
<Compile Include="Providers\Rackspace\Objects\ArchiveFormat.cs" />
<Compile Include="Core\Domain\AuthenticationType.cs" />
<Compile Include="Providers\Rackspace\Objects\BulkDeletionFailedObject.cs" />
<Compile Include="Providers\Rackspace\Objects\BulkDeletionResults.cs" />
<Compile Include="Providers\Rackspace\Objects\Dns\DnsChange.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/corelib/corelib.v4.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Core\Caching\ICache`1.cs" />
<Compile Include="Core\Caching\NamespaceDoc.cs" />
<Compile Include="Core\Domain\AuthenticationRequirement.cs" />
<Compile Include="Core\Domain\AuthenticationType.cs" />
<Compile Include="Core\Domain\Converters\NamespaceDoc.cs" />
<Compile Include="Core\Domain\Converters\PhysicalAddressSimpleConverter.cs" />
<Compile Include="Core\Domain\Converters\SimpleStringJsonConverter`1.cs" />
Expand Down
7 changes: 6 additions & 1 deletion src/testing/integration/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -107,6 +107,11 @@ public class ExtendedRackspaceCloudIdentity : RackspaceCloudIdentity
{
public string TenantId { get; set; }

public ExtendedRackspaceCloudIdentity()
{

}

public ExtendedRackspaceCloudIdentity(ExtendedCloudIdentity cloudIdentity)
{
this.APIKey = cloudIdentity.APIKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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";
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public void TestDefaultIdentity()
Assert.AreEqual(identity, provider.DefaultIdentity);

IIdentityProvider defaultProvider = Bootstrapper.CreateIdentityProvider();
Assert.IsNull(defaultProvider.DefaultIdentity);
Assert.IsNotNull(defaultProvider.DefaultIdentity);
}
}
}

0 comments on commit f2eae72

Please sign in to comment.