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); }
private static List <AuthorizationEntry> GetServiceAuthorizationInfo(string serviceName) { if (_authorizationEntries.ContainsKey(serviceName)) { return(_authorizationEntries[serviceName]); } var authEntryList = new List <AuthorizationEntry>(); var servicesNode = Factory.GetConfigNode($"powershell/services/{serviceName}/authorization"); if (servicesNode == null) { return(authEntryList); } 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}'"); } } _authorizationEntries.TryAdd(serviceName, authEntryList); return(authEntryList); }