private static List <AuthorizationEntry> GetServiceAuthorizationInfo(string serviceName)
        {
            if (authorizationEntries.ContainsKey(serviceName))
            {
                return(authorizationEntries[serviceName]);
            }

            var authEntryList = new List <AuthorizationEntry>();

            authorizationEntries.Add(serviceName, authEntryList);

            var servicesNode =
                Factory.GetConfigNode($"powershell/services/{serviceName}/authorization");

            if (servicesNode != null)
            {
                foreach (XmlNode node in servicesNode.ChildNodes)
                {
                    AuthorizationEntry entry;
                    if (node.Name.Is("#comment"))
                    {
                        continue;
                    }
                    if (AuthorizationEntry.TryParse(node, out entry))
                    {
                        authEntryList.Add(entry);
                    }
                    else
                    {
                        PowerShellLog.Error($"Invalid permission entry for service '{serviceName}'");
                    }
                }
            }
            return(authEntryList);
        }
Ejemplo n.º 2
0
        public static bool TryParse(XmlNode node, out AuthorizationEntry entry)
        {
            entry = new AuthorizationEntry();
            if (node?.Attributes == null)
            {
                return(false);
            }
            var accessPermissionStr = node.Attributes?["Permission"].Value;
            var accountTypeStr      = node?.Attributes["IdentityType"].Value;
            var identityStr         = node?.Attributes["Identity"].Value;

            AccessPermission accessPermission;

            if (!Enum.TryParse(accessPermissionStr, true, out accessPermission) ||
                accessPermission == AccessPermission.NotSet)
            {
                return(false);
            }

            AccountType accountType;

            if (!Enum.TryParse(accountTypeStr, true, out accountType) || accountType == AccountType.Unknown)
            {
                return(false);
            }

            AccountIdentity identity = null;

            try
            {
                identity = new AccountIdentity(identityStr, true);
            }
            catch
            {
                PowerShellLog.Error($"Invalid identity {identityStr} provided for service configuration.");
            }

            entry.AccessPermission = accessPermission;
            entry.IdentityType     = accountType;
            entry.Identity         = identity;
            entry.wildcardPattern  = WildcardUtils.GetWildcardPattern(identity.Name);
            return(true);
        }