Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73a59f9181 |
@@ -1,13 +1,14 @@
|
|||||||
|
using System.Linq;
|
||||||
using xIds.Helpers;
|
using xIds.Helpers;
|
||||||
using xIds.Constants;
|
using xIds.Constants;
|
||||||
using xIds.DbContext;
|
using xIds.DbContext;
|
||||||
using xIds.Providers;
|
using xIds.Providers;
|
||||||
using IdentityServer4;
|
|
||||||
using xIdentityHelper;
|
using xIdentityHelper;
|
||||||
using xIdentityModels;
|
using xIdentityModels;
|
||||||
using xIds.Extensions;
|
using xIds.Extensions;
|
||||||
using xIds.Interfaces;
|
using xIds.Interfaces;
|
||||||
using xIds.Validators;
|
using xIds.Validators;
|
||||||
|
using IdentityServer4;
|
||||||
using xCommons.Constants;
|
using xCommons.Constants;
|
||||||
using xMessageService.DI;
|
using xMessageService.DI;
|
||||||
using xStorageService.DI;
|
using xStorageService.DI;
|
||||||
@@ -18,6 +19,7 @@ using xCommons.Authorization;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using xMessageService.Interfaces;
|
using xMessageService.Interfaces;
|
||||||
using xStorageService.Interfaces;
|
using xStorageService.Interfaces;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
@@ -433,6 +435,7 @@ namespace xIds.DI
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
var policyHandler = services.GetRegisteredService<IXPolicyHandler>();
|
||||||
services.AddAuthorization(options =>
|
services.AddAuthorization(options =>
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -446,6 +449,26 @@ namespace xIds.DI
|
|||||||
{
|
{
|
||||||
var policyDescriptor = policiesEnumerator.Current;
|
var policyDescriptor = policiesEnumerator.Current;
|
||||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Policy to Policy Handler ...
|
||||||
|
if (!policyHandler.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Policy is RequiredRole Policy ...
|
||||||
|
var roleRequirements = policyDescriptor.Value.Requirements
|
||||||
|
.OfType<RequiredRolesRequirement>()
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (!roleRequirements.IsNull() &&
|
||||||
|
roleRequirements.Roles.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
policyHandler.AddPolicy(
|
||||||
|
policy: policyDescriptor.Key.ToNormalString(),
|
||||||
|
requiredRoles: roleRequirements.Roles.Select(r => r.ToNormalString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -460,8 +483,32 @@ namespace xIds.DI
|
|||||||
{
|
{
|
||||||
while (policiesEnumerator.MoveNext())
|
while (policiesEnumerator.MoveNext())
|
||||||
{
|
{
|
||||||
|
//
|
||||||
var policyDescriptor = policiesEnumerator.Current;
|
var policyDescriptor = policiesEnumerator.Current;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Policy to Authorization ...
|
||||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add Policy to Policy Handler ...
|
||||||
|
if (!policyHandler.IsNull())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Check Policy is RequiredRole Policy ...
|
||||||
|
var roleRequirements = policyDescriptor.Value.Requirements
|
||||||
|
.OfType<RequiredRolesRequirement>()
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (!roleRequirements.IsNull() &&
|
||||||
|
roleRequirements.Roles.HasChild())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
policyHandler.AddPolicy(
|
||||||
|
policy: policyDescriptor.Key.ToNormalString(),
|
||||||
|
requiredRoles: roleRequirements.Roles.Select(r => r.ToNormalString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user