public RoleStruct[] GetItemSecurity(string sPath) { List<RoleStruct> roles5x = new List<RoleStruct>(); using (new Sitecore.SecurityModel.SecurityDisabler()) { Sitecore.Data.Items.Item item = GetItemFromMasterdatabase(sPath); for (int i = 0; i < item.SecurityField.Assignments.Count; i++) { Sitecore.SecurityModel.SecurityAssignment securityAssignment = item.SecurityField.Assignments[i]; Sitecore.Data.Items.Item groupItem = GetItemFromSecuritydatabase(securityAssignment.EntityID.ToString()); if (groupItem == null) continue; AccessRights AccessRight = GetConverterAccessRights(securityAssignment.Rights); RoleStruct role = new RoleStruct(); role.Name = securityAssignment.DomainName + "\\" + groupItem.Name; role.ID = securityAssignment.EntityID.ToString(); role.Path = groupItem.Paths.ContentPath; role.AccessRight = AccessRight; if (groupItem.Fields["email"] != null) role.Email = groupItem.Fields["email"].Value; if (groupItem.Fields["fullname"] != null) role.FullName = groupItem.Fields["fullname"].Value; if (groupItem.Fields["password"] != null) role.PassWord = groupItem.Fields["password"].Value; if ((groupItem.Fields["administrator"] != null) && (groupItem.Fields["administrator"].Value == "1")) role.IsAdmin = true; else role.IsAdmin = false; if (groupItem.Fields["roles"] != null) { role.Roles = ""; foreach (string sID in groupItem.Fields["roles"].Value.Split('|')) { Sitecore.Data.Items.Item roleItem = GetItemFromSecuritydatabase(sID); if (roleItem != null) { if (role.Roles != "") role.Roles += "|"; role.Roles += securityAssignment.DomainName + "\\" + roleItem.Name; } } // role.Roles = groupItem.Fields["roles"].Value; } roles5x.Add(role); } } return roles5x.ToArray(); }
public RoleStruct[] GetUsers(string sDomain) { using (new Sitecore.SecurityModel.SecurityDisabler()) { Sitecore.SecurityModel.Domain domain = Sitecore.SecurityModel.Domain.FromName(sDomain); Sitecore.Data.Database db = domain.Database; if (db == null) { return(null); } // create a query that will handle the Role retrieval // here we simply rely on the Role's Template ID string query = "//*[@@templateid='" + Sitecore.TemplateIDs.User + "']"; Sitecore.Data.Items.Item[] items = db.SelectItems(query); Sitecore.SecurityModel.UserItem[] users = new Sitecore.SecurityModel.UserItem[items.Length]; List <RoleStruct> roles5x = new List <RoleStruct>(); // fill this array with Role Items for (int i = 0; i < users.Length; i++) { users[i] = new Sitecore.SecurityModel.UserItem(items[i], domain); RoleStruct role = new RoleStruct(); role.Name = users[i].Domain.Name + "\\" + users[i].Name; role.ID = users[i].ID.ToString(); role.Path = users[i].InnerItem.Paths.ContentPath; role.AccessRight = AccessRights.NotSet; role.Email = users[i].Email; role.FullName = users[i].Fullname; if (users[i].InnerItem.Fields["password"] != null) { role.PassWord = users[i].InnerItem.Fields["password"].Value; } role.IsAdmin = users[i].IsAdministrator; role.Roles = ""; for (int t = 0; t < users[i].Roles.RoleNames.Length; t++) { if (role.Roles != "") { role.Roles += "|"; } role.Roles += users[i].Roles.RoleNames[t]; } roles5x.Add(role); } return(roles5x.ToArray()); } }
public RoleStruct[] GetItemSecurity(string sPath) { List <RoleStruct> roles5x = new List <RoleStruct>(); using (new Sitecore.SecurityModel.SecurityDisabler()) { Sitecore.Data.Items.Item item = GetItemFromMasterdatabase(sPath); for (int i = 0; i < item.SecurityField.Assignments.Count; i++) { Sitecore.SecurityModel.SecurityAssignment securityAssignment = item.SecurityField.Assignments[i]; Sitecore.Data.Items.Item groupItem = GetItemFromSecuritydatabase(securityAssignment.EntityID.ToString()); if (groupItem == null) { continue; } AccessRights AccessRight = GetConverterAccessRights(securityAssignment.Rights); RoleStruct role = new RoleStruct(); role.Name = securityAssignment.DomainName + "\\" + groupItem.Name; role.ID = securityAssignment.EntityID.ToString(); role.Path = groupItem.Paths.ContentPath; role.AccessRight = AccessRight; if (groupItem.Fields["email"] != null) { role.Email = groupItem.Fields["email"].Value; } if (groupItem.Fields["fullname"] != null) { role.FullName = groupItem.Fields["fullname"].Value; } if (groupItem.Fields["password"] != null) { role.PassWord = groupItem.Fields["password"].Value; } if ((groupItem.Fields["administrator"] != null) && (groupItem.Fields["administrator"].Value == "1")) { role.IsAdmin = true; } else { role.IsAdmin = false; } if (groupItem.Fields["roles"] != null) { role.Roles = ""; foreach (string sID in groupItem.Fields["roles"].Value.Split('|')) { Sitecore.Data.Items.Item roleItem = GetItemFromSecuritydatabase(sID); if (roleItem != null) { if (role.Roles != "") { role.Roles += "|"; } role.Roles += securityAssignment.DomainName + "\\" + roleItem.Name; } } // role.Roles = groupItem.Fields["roles"].Value; } roles5x.Add(role); } } return(roles5x.ToArray()); }
public RoleStruct[] GetUsers(string sDomain) { using (new Sitecore.SecurityModel.SecurityDisabler()) { Sitecore.SecurityModel.Domain domain = Sitecore.SecurityModel.Domain.FromName(sDomain); Sitecore.Data.Database db = domain.Database; if (db == null) { return null; } // create a query that will handle the Role retrieval // here we simply rely on the Role's Template ID string query = "//*[@@templateid='" + Sitecore.TemplateIDs.User + "']"; Sitecore.Data.Items.Item[] items = db.SelectItems(query); Sitecore.SecurityModel.UserItem[] users = new Sitecore.SecurityModel.UserItem[items.Length]; List<RoleStruct> roles5x = new List<RoleStruct>(); // fill this array with Role Items for (int i = 0; i < users.Length; i++) { users[i] = new Sitecore.SecurityModel.UserItem(items[i], domain); RoleStruct role = new RoleStruct(); role.Name = users[i].Domain.Name + "\\" + users[i].Name; role.ID = users[i].ID.ToString(); role.Path = users[i].InnerItem.Paths.ContentPath; role.AccessRight = AccessRights.NotSet; role.Email = users[i].Email; role.FullName = users[i].Fullname; if (users[i].InnerItem.Fields["password"] != null) role.PassWord = users[i].InnerItem.Fields["password"].Value; role.IsAdmin = users[i].IsAdministrator; role.Roles = ""; for (int t=0; t<users[i].Roles.RoleNames.Length; t++) { if (role.Roles != "") role.Roles += "|"; role.Roles += users[i].Roles.RoleNames[t]; } roles5x.Add(role); } return roles5x.ToArray(); } }