/// <summary> /// Provides incremental build the role inheritance relations. /// </summary> /// <param name="policyOperation"></param> /// <param name="section"></param> /// <param name="policyType"></param> /// <param name="rules"></param> public void BuildIncrementalRoleLinks(PolicyOperation policyOperation, string section, string policyType, IEnumerable <IEnumerable <string> > rules) { if (Model.ContainsKey(PermConstants.Section.RoleSection) is false) { return; } Assertion assertion = GetExistAssertion(section, policyType); assertion.BuildIncrementalRoleLinks(policyOperation, rules); }
/// <summary> /// Initializes the roles in RBAC. /// </summary> /// <param name="roleManager"></param> public void BuildRoleLinks(IRoleManager roleManager) { if (Model.ContainsKey(PermConstants.Section.RoleSection) is false) { return; } foreach (Assertion assertion in Model[PermConstants.Section.RoleSection].Values) { assertion.BuildRoleLinks(roleManager); } }
/// <summary> /// Adds an assertion to the model. /// </summary> /// <param name="section"></param> /// <param name="key">Key of the assertion, it is same to "policyType" when section is "p" or "g".</param> /// <param name="value">Value of the assertion.</param> /// <returns></returns> public bool AddDef(string section, string key, string value) { if (string.IsNullOrWhiteSpace(value)) { return(false); } var assertion = new Assertion { Key = key, Value = value }; if (section.Equals(PermConstants.Section.RequestSection) || section.Equals(PermConstants.Section.PolicySection)) { string[] tokens = assertion.Value .Split(PermConstants.PolicySeparatorChar) .Select(t => t.Trim()).ToArray(); if (tokens.Length != 0) { var tokenDic = new Dictionary <string, int>(); for (int i = 0; i < tokens.Length; i++) { tokenDic.Add($"{key}_{tokens[i]}", i); } assertion.Tokens = tokenDic; } } else { assertion.Value = Utility.RemoveComments(Utility.EscapeAssertion(assertion.Value)); } if (Model.ContainsKey(section) is false) { var assertionMap = new Dictionary <string, Assertion> { [key] = assertion }; Model.Add(section, assertionMap); } else { Model[section].Add(key, assertion); } return(true); }
public void ClearPolicy() { if (Model.ContainsKey(PermConstants.Section.PolicySection)) { foreach (Assertion assertion in Model[PermConstants.Section.PolicySection].Values) { assertion.ClearPolicy(); } } if (Model.ContainsKey(PermConstants.Section.RoleSection)) { foreach (Assertion assertion in Model[PermConstants.Section.RoleSection].Values) { assertion.ClearPolicy(); } } }
/// <summary> /// /// </summary> /// <param name="sec">"p" or "g"</param> /// <param name="key">the policy type, "p", "p2", .. or "g", "g2", ..</param> /// <param name="value">the policy rule, separated by ", ".</param> /// <returns>succeeds or not.</returns> public bool AddDef(string sec, string key, string value) { Assertion ast = new Assertion { Key = key, Value = value }; if (string.IsNullOrEmpty(ast.Value)) { return(false); } if (sec.Equals("r") || sec.Equals("p")) { var tokens = ast.Value.Split(new string[] { ", " }, StringSplitOptions.None); for (int i = 0; i < tokens.Length; i++) { tokens[i] = $"{key}_{tokens[i]}"; } ast.Tokens = tokens; } else { ast.Value = Utility.RemoveComments(Utility.EscapeAssertion(ast.Value)); } if (!Model.ContainsKey(sec)) { var assertionMap = new Dictionary <String, Assertion> { [key] = ast }; Model.Add(sec, assertionMap); } else { Model[sec].Add(key, ast); } return(true); }