public static SnAccessControlEntry CreateEmpty(int principalId, bool propagates) { var perms = new List<SnPermission>(); foreach (var permType in ActiveSchema.PermissionTypes) // .OrderBy(x => x.Id) perms.Add(new SnPermission { Name = permType.Name }); return new SnAccessControlEntry { Identity = SnIdentity.Create(principalId), Permissions = perms, Propagates = propagates }; }
//============================================================================= for editing internal SnAccessControlList GetAcl(int nodeId, string path, int creatorId, int lastModifierId) { var acl = new SnAccessControlList { Path = path, NodeId = nodeId, Creator = SnIdentity.Create(creatorId), LastModifier = SnIdentity.Create(lastModifierId) }; var firstPermInfo = GetFirstInfo(path); if (firstPermInfo == null) { return(acl); } return(firstPermInfo.BuildAcl(acl)); }
private string SetAclTest(int operationNumber, string initial, string readOnlyMask, string set, string expected) { if (readOnlyMask == null) readOnlyMask = initial.Replace("+", "r").Replace("-", "r"); //Trace.WriteLine(String.Format("@> TEST #{0}: {1} | {2} | {3} | {4}", operationNumber, initial, readOnlyMask, set, expected)); var node = TestRoot; var visitor = User.Visitor; var ident = new SnIdentity { Kind = SnIdentityKind.User, Name = "Visitor", NodeId = visitor.Id, Path = visitor.Path }; var permsEd = GetPermsFromString(initial, readOnlyMask); var entryEd = new SnAccessControlEntry { Identity = ident, Propagates = true, Permissions = permsEd }; var aclEd = new SnAccessControlList { NodeId = 9999, Creator = ident, Inherits = true, LastModifier = ident, Path = "asdf", Entries = new[] { entryEd } }; var perms0 = GetPermsFromString(initial, readOnlyMask); var entry0 = new SnAccessControlEntry { Identity = ident, Propagates = true, Permissions = perms0 }; var acl0 = new SnAccessControlList { NodeId = 9999, Creator = ident, Inherits = true, LastModifier = ident, Path = "asdf", Entries = new[] { entry0 } }; var perms1 = GetPermsFromString(set, readOnlyMask); var entry1 = new SnAccessControlEntry { Identity = ident, Propagates = true, Permissions = perms1 }; var acl1 = new SnAccessControlList { NodeId = 9999, Creator = ident, Inherits = true, LastModifier = ident, Path = "asdf", Entries = new[] { entry1 } }; var ed = node.Security.GetAclEditor(); ed.Acl = aclEd; // clone of acl0 var edAcc = new AclEditorAccessor(ed); var secAcc = new SecurityHandlerAccessor(node.Security); var entries = secAcc.GetEntriesFromAcl(ed, acl0, acl1); var resultEntry = SearchEntry(entries, User.Visitor, true); var result = resultEntry.ValuesToString(); if (result == expected) return null; return String.Concat("State is '", result, "', expected '", expected, "' at operation ", operationNumber); }