Skip to content

Commit

Permalink
#1150 | Federated Identity Server users incompatible with SPE Security
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-null authored and michaellwest committed Mar 18, 2021
1 parent 3ed431e commit a07d321
Showing 1 changed file with 7 additions and 5 deletions.
Expand Up @@ -14,11 +14,10 @@ namespace Spe.Core.Settings.Authorization
{
public static class ServiceAuthorizationManager
{

private static readonly ConcurrentDictionary<string, List<AuthorizationEntry>> _authorizationEntries =
new ConcurrentDictionary<string, List<AuthorizationEntry>>();

private static readonly ConcurrentDictionary<string, AuthCacheEntry> _authorizationCache =
private static readonly ConcurrentDictionary<string, AuthCacheEntry> _authorizationCache =
new ConcurrentDictionary<string, AuthCacheEntry>();

public static bool IsUserAuthorized(string serviceName, string userName = null)
Expand All @@ -45,7 +44,10 @@ public static bool IsUserAuthorized(string serviceName, string userName = null)
bool? allowedByRole = null;
bool? allowedByName = null;

var user = User.FromName(userName, false);
// AzureAD: roles are available only for "Context.User". Cannot access them via user taken from "User.FromName"
var user = userName.Equals(Context.User?.Name, StringComparison.InvariantCultureIgnoreCase)
? Context.User
: User.FromName(userName, false);

foreach (var authEntry in authEntries)
{
Expand All @@ -54,7 +56,7 @@ public static bool IsUserAuthorized(string serviceName, string userName = null)
case AccountType.Role:
Role role = authEntry.Identity;
if (!allowedByRole.HasValue || allowedByRole.Value)
// if not denied by previous rules - keep checking
// if not denied by previous rules - keep checking
{
if ((role != null && user.IsInRole(role)) ||
// check for special role based on user having administrator privileges
Expand All @@ -67,7 +69,7 @@ public static bool IsUserAuthorized(string serviceName, string userName = null)
break;
case AccountType.User:
if (!allowedByName.HasValue || allowedByName.Value)
// if not denied by previous rules - keep checking
// if not denied by previous rules - keep checking
{
if (authEntry.WildcardMatch(userName))
{
Expand Down

0 comments on commit a07d321

Please sign in to comment.