Skip to content

Commit 91d8ef5

Browse files
authored
Policy tool enhancements (#123)
* Adds "--app-id" option to "add-app" subcommand * Adds "--app-uri" as an option for add-app subcommand. Defaults to "http://localhost" which is deliberately different from the previous hard-coded default. * Fixes bug that made --user-name optional when adding a user. Changed to object initializers for Option<T> construction to avoid similar such bugs in the future. * Changes role name comparison to be case-insensitive. * Fixes spelling of "principal" (was "principle"). This is a breaking change since it impacts multiple public interfaces that were created in RD 0.9.0.
1 parent a550fe1 commit 91d8ef5

File tree

7 files changed

+132
-111
lines changed

7 files changed

+132
-111
lines changed

src/ReactiveDomain.IdentityStorage.Tests/MockPrinciple.cs renamed to src/ReactiveDomain.IdentityStorage.Tests/MockPrincipal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ReactiveDomain.IdentityStorage.Tests
44
{
5-
internal class MockPrinciple : IPrinciple
5+
internal class MockPrincipal : IPrincipal
66
{
77
public string Provider { get; set; }
88

src/ReactiveDomain.IdentityStorage.Tests/SubjectRmTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public void can_get_subject_ids()
6464
Assert.Equal(sub3, testSub);
6565
}
6666
[Fact]
67-
public void can_get_subject_id_for_principle()
67+
public void can_get_subject_id_for_principal()
6868
{
6969
var userId = Guid.NewGuid();
7070
var subjectId = AddNewSubject(userId, provider: AuthProvider, domain: AuthDomain);
71-
var user = new MockPrinciple { Provider = AuthProvider, Domain = AuthDomain, SId = userId.ToString() };
72-
Assert.True(_rm.TryGetSubjectIdForPrinciple(user, out var id));
71+
var user = new MockPrincipal { Provider = AuthProvider, Domain = AuthDomain, SId = userId.ToString() };
72+
Assert.True(_rm.TryGetSubjectIdForPrincipal(user, out var id));
7373
Assert.Equal(subjectId, id);
7474
}
7575
[Fact]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.DirectoryServices.AccountManagement;
2+
using ReactiveDomain.Util;
3+
4+
namespace ReactiveDomain.IdentityStorage.ReadModels
5+
{
6+
7+
public interface IPrincipal
8+
{
9+
string Provider { get; }
10+
string Domain { get; }
11+
string SId { get; }
12+
}
13+
public class PrincipalWrapper : IPrincipal
14+
{
15+
private readonly UserPrincipal _principal;
16+
17+
public PrincipalWrapper(UserPrincipal principal)
18+
{
19+
Ensure.NotNull(principal, nameof(principal));
20+
_principal = principal;
21+
}
22+
23+
public string Provider => _principal.ContextType.ToString();
24+
25+
public string Domain => _principal.Context.Name;
26+
27+
public string SId => _principal.Sid.ToString();
28+
}
29+
}

src/ReactiveDomain.IdentityStorage/ReadModels/PrincipleWrapper.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/ReactiveDomain.IdentityStorage/ReadModels/SubjectsRm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ public bool TryGetSubjectIdForUser(Guid userId, string provider, string domain,
4848
}
4949
return false;
5050
}
51-
public bool TryGetSubjectIdForPrinciple(IPrinciple principle, out Guid subjectId)
51+
public bool TryGetSubjectIdForPrincipal(IPrincipal principal, out Guid subjectId)
5252
{
5353
try
5454
{
5555

56-
if (SubjectsBySubClaim.TryGetValue(GetDomainCategory(principle.Provider, principle.Domain), out var subList))
56+
if (SubjectsBySubClaim.TryGetValue(GetDomainCategory(principal.Provider, principal.Domain), out var subList))
5757
{
58-
return subList.TryGetValue(principle.SId, out subjectId);
58+
return subList.TryGetValue(principal.SId, out subjectId);
5959
}
6060
}
6161
catch

src/ReactiveDomain.IdentityStorage/Services/UserValidation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public ValidationResult Validate(string domainName, string userName, string pass
8989

9090
if (authSucceeded)
9191
{
92-
//build the Claims Principle to return in the token
92+
//build the Claims Principal to return in the token
9393
result.IsValidated = true;
9494
_userStore.UserAuthenticated(user, domainName, contextType.ToString(), remoteHttpAddress, clientId);
9595
var additionalClaims = _userStore.GetAdditionalClaims(userId);

0 commit comments

Comments
 (0)