diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 5cc1b85e8e..3874ad7b3a 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -529,14 +529,14 @@ namespace umbraco string.Format( "{0}_{1}", CacheKeys.MemberLibraryCacheKey, MemberId), TimeSpan.FromSeconds(UmbracoSettings.UmbracoLibraryCacheDuration), - () => getMemberDo(MemberId)); + () => GetMemberDo(MemberId)); if (retVal != null) return retVal.CreateNavigator().Select("/"); } else { - return getMemberDo(MemberId).CreateNavigator().Select("/"); + return GetMemberDo(MemberId).CreateNavigator().Select("/"); } } @@ -548,7 +548,7 @@ namespace umbraco return xd.CreateNavigator().Select("/"); } - private static XmlDocument getMemberDo(int MemberId) + private static XmlDocument GetMemberDo(int MemberId) { Member m = new Member(MemberId); XmlDocument mXml = new XmlDocument(); diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs b/src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs index 888280df77..d16440e52b 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs @@ -127,14 +127,14 @@ namespace umbraco.presentation.umbracobase.library { myProperty.Value = value; retVal = "True"; - myMember.XmlGenerate(new XmlDocument()); + myMember.Save(); } } else { myProperty.Value = value; retVal = "True"; - myMember.XmlGenerate(new XmlDocument()); + myMember.Save(); } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs b/src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs index 8a02b65c14..0374ba5339 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs @@ -91,7 +91,7 @@ namespace umbraco.presentation.umbracobase allowed = false; } else //do member authentication stuff... - allowed = memberAuthentication(baseExt, currentMem); + allowed = MemberAuthentication(baseExt, currentMem); } } else @@ -138,7 +138,7 @@ namespace umbraco.presentation.umbracobase else { //do member authentication stuff... - allowed = memberAuthentication(attribute, currentMem); + allowed = MemberAuthentication(attribute, currentMem); } } @@ -186,7 +186,7 @@ namespace umbraco.presentation.umbracobase } } - private static bool memberAuthentication(RestExtensionMethod baseExt, Member currentMem) + private static bool MemberAuthentication(RestExtensionMethod baseExt, Member currentMem) { //Check group, type and ID bool memberAccess = false; @@ -235,7 +235,7 @@ namespace umbraco.presentation.umbracobase return memberAccess; } - private static bool memberAuthentication(XmlNode baseExt, Member currentMem) + private static bool MemberAuthentication(XmlNode baseExt, Member currentMem) { //Check group, type and ID bool memberAccess = false; diff --git a/src/umbraco.cms/businesslogic/web/Access.cs b/src/umbraco.cms/businesslogic/web/Access.cs index 8f0cffd4b2..555818952d 100644 --- a/src/umbraco.cms/businesslogic/web/Access.cs +++ b/src/umbraco.cms/businesslogic/web/Access.cs @@ -15,25 +15,18 @@ namespace umbraco.cms.businesslogic.web /// public class Access { - public Access() - { - // - // TODO: Add constructor logic here - // - } - - static private Hashtable _checkedPages = new Hashtable(); + static private readonly Hashtable CheckedPages = new Hashtable(); //must be volatile for double check lock to work static private volatile XmlDocument _accessXmlContent; static private string _accessXmlSource; - private static void clearCheckPages() + private static void ClearCheckPages() { - _checkedPages.Clear(); + CheckedPages.Clear(); } - static object _locko = new object(); + static readonly object Locko = new object(); public static XmlDocument AccessXml { @@ -41,7 +34,7 @@ namespace umbraco.cms.businesslogic.web { if (_accessXmlContent == null) { - lock (_locko) + lock (Locko) { if (_accessXmlContent == null) { @@ -80,7 +73,7 @@ namespace umbraco.cms.businesslogic.web new Access().FireBeforeAddMemberShipRoleToDocument(new Document(documentId), role, e); if (!e.Cancel) { - XmlElement x = (XmlElement)getPage(documentId); + XmlElement x = (XmlElement)GetPage(documentId); if (x == null) throw new Exception("Document is not protected!"); @@ -89,7 +82,7 @@ namespace umbraco.cms.businesslogic.web XmlElement groupXml = (XmlElement)AccessXml.CreateNode(XmlNodeType.Element, "group", ""); groupXml.SetAttribute("id", role); x.AppendChild(groupXml); - save(); + Save(); } } @@ -100,7 +93,7 @@ namespace umbraco.cms.businesslogic.web [Obsolete("This method is no longer supported. Use the ASP.NET MemberShip methods instead", true)] public static void AddMemberGroupToDocument(int DocumentId, int MemberGroupId) { - XmlElement x = (XmlElement) getPage(DocumentId); + XmlElement x = (XmlElement) GetPage(DocumentId); if (x == null) throw new Exception("Document is not protected!"); @@ -111,7 +104,7 @@ namespace umbraco.cms.businesslogic.web XmlElement groupXml = (XmlElement) AccessXml.CreateNode(XmlNodeType.Element, "group", ""); groupXml.SetAttribute("id", MemberGroupId.ToString()); x.AppendChild(groupXml); - save(); + Save(); } } } @@ -119,7 +112,7 @@ namespace umbraco.cms.businesslogic.web [Obsolete("This method is no longer supported. Use the ASP.NET MemberShip methods instead", true)] public static void AddMemberToDocument(int DocumentId, int MemberId) { - XmlElement x = (XmlElement) getPage(DocumentId); + XmlElement x = (XmlElement) GetPage(DocumentId); if (x == null) throw new Exception("Document is not protected!"); @@ -129,7 +122,7 @@ namespace umbraco.cms.businesslogic.web x.Attributes.GetNamedItem("memberId").Value = MemberId.ToString(); else x.SetAttribute("memberId", MemberId.ToString()); - save(); + Save(); } } @@ -139,7 +132,7 @@ namespace umbraco.cms.businesslogic.web new Access().FireBeforeAddMembershipUserToDocument(new Document(documentId), membershipUserName, e); if (!e.Cancel) { - XmlElement x = (XmlElement)getPage(documentId); + XmlElement x = (XmlElement)GetPage(documentId); if (x == null) throw new Exception("Document is not protected!"); @@ -148,7 +141,7 @@ namespace umbraco.cms.businesslogic.web x.Attributes.GetNamedItem("memberId").Value = membershipUserName; else x.SetAttribute("memberId", membershipUserName); - save(); + Save(); } new Access().FireAfterAddMembershipUserToDocument(new Document(documentId), membershipUserName, e); @@ -159,7 +152,7 @@ namespace umbraco.cms.businesslogic.web [Obsolete("This method is no longer supported. Use the ASP.NET MemberShip methods instead", true)] public static void RemoveMemberGroupFromDocument(int DocumentId, int MemberGroupId) { - XmlElement x = (XmlElement) getPage(DocumentId); + XmlElement x = (XmlElement) GetPage(DocumentId); if (x == null) throw new Exception("Document is not protected!"); @@ -169,7 +162,7 @@ namespace umbraco.cms.businesslogic.web if (xGroup != null) { x.RemoveChild(xGroup); - save(); + Save(); } } } @@ -180,7 +173,7 @@ namespace umbraco.cms.businesslogic.web new Access().FireBeforeRemoveMemberShipRoleFromDocument(new Document(documentId), role, e); if (!e.Cancel) { - XmlElement x = (XmlElement)getPage(documentId); + XmlElement x = (XmlElement)GetPage(documentId); if (x == null) throw new Exception("Document is not protected!"); @@ -188,7 +181,7 @@ namespace umbraco.cms.businesslogic.web XmlNode xGroup = x.SelectSingleNode("group [@id = '" + role + "']"); if (xGroup != null) { x.RemoveChild(xGroup); - save(); + Save(); } } @@ -208,7 +201,7 @@ namespace umbraco.cms.businesslogic.web hasChange = true; } if (hasChange) - save(); + Save(); } return hasChange; @@ -222,7 +215,7 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { - XmlElement x = (XmlElement)getPage(DocumentId); + XmlElement x = (XmlElement)GetPage(DocumentId); if (x == null) { x = (XmlElement)_accessXmlContent.CreateNode(XmlNodeType.Element, "page", ""); AccessXml.DocumentElement.AppendChild(x); @@ -235,9 +228,9 @@ namespace umbraco.cms.businesslogic.web x.SetAttribute("loginPage", LoginDocumentId.ToString()); x.SetAttribute("noRightsPage", ErrorDocumentId.ToString()); x.SetAttribute("simple", Simple.ToString()); - save(); + Save(); - clearCheckPages(); + ClearCheckPages(); new Access().FireAfterAddProtection(new Document(DocumentId), e); } @@ -245,7 +238,7 @@ namespace umbraco.cms.businesslogic.web public static void RemoveProtection(int DocumentId) { - XmlElement x = (XmlElement) getPage(DocumentId); + XmlElement x = (XmlElement) GetPage(DocumentId); if (x != null) { //event @@ -255,8 +248,8 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { x.ParentNode.RemoveChild(x); - save(); - clearCheckPages(); + Save(); + ClearCheckPages(); new Access().FireAfterRemoveProtection(new Document(DocumentId), e); } @@ -264,7 +257,7 @@ namespace umbraco.cms.businesslogic.web } } - private static void save() + private static void Save() { SaveEventArgs e = new SaveEventArgs(); @@ -290,7 +283,7 @@ namespace umbraco.cms.businesslogic.web isProtected = false; else { - XmlNode currentNode = getPage(getProtectedPage(d.Path)); + XmlNode currentNode = GetPage(GetProtectedPage(d.Path)); if (currentNode.SelectSingleNode("./group [@id=" + GroupId.ToString() + "]") != null) { isProtected = true; @@ -308,7 +301,7 @@ namespace umbraco.cms.businesslogic.web if (!IsProtected(documentId, d.Path)) isProtected = false; else { - XmlNode currentNode = getPage(getProtectedPage(d.Path)); + XmlNode currentNode = GetPage(GetProtectedPage(d.Path)); if (currentNode.SelectSingleNode("./group [@id='" + role + "']") != null) { isProtected = true; } @@ -323,7 +316,7 @@ namespace umbraco.cms.businesslogic.web if (!IsProtected(documentId, path)) return null; else { - XmlNode currentNode = getPage(getProtectedPage(path)); + XmlNode currentNode = GetPage(GetProtectedPage(path)); foreach (XmlNode n in currentNode.SelectNodes("./group")) { roles.Add(n.Attributes.GetNamedItem("id").Value); } @@ -341,7 +334,7 @@ namespace umbraco.cms.businesslogic.web return null; else { - XmlNode currentNode = getPage(getProtectedPage(d.Path)); + XmlNode currentNode = GetPage(GetProtectedPage(d.Path)); cms.businesslogic.member.MemberGroup[] mg = new umbraco.cms.businesslogic.member.MemberGroup[currentNode.SelectNodes("./group").Count]; int count = 0; foreach (XmlNode n in currentNode.SelectNodes("./group")) @@ -363,7 +356,7 @@ namespace umbraco.cms.businesslogic.web else if (GetProtectionType(DocumentId) != ProtectionType.Simple) throw new Exception("Document isn't protected using Simple mechanism. Use GetAccessingMemberGroups instead"); else { - XmlNode currentNode = getPage(getProtectedPage(d.Path)); + XmlNode currentNode = GetPage(GetProtectedPage(d.Path)); if (currentNode.Attributes.GetNamedItem("memberId") != null) return new cms.businesslogic.member.Member(int.Parse( currentNode.Attributes.GetNamedItem("memberId").Value)); @@ -382,7 +375,7 @@ namespace umbraco.cms.businesslogic.web else if (GetProtectionType(documentId) != ProtectionType.Simple) throw new Exception("Document isn't protected using Simple mechanism. Use GetAccessingMemberGroups instead"); else { - XmlNode currentNode = getPage(getProtectedPage(d.Path)); + XmlNode currentNode = GetPage(GetProtectedPage(d.Path)); if (currentNode.Attributes.GetNamedItem("memberId") != null) return Membership.GetUser(currentNode.Attributes.GetNamedItem("memberId").Value); else @@ -404,7 +397,7 @@ namespace umbraco.cms.businesslogic.web hasAccess = true; else { - XmlNode currentNode = getPage(getProtectedPage(d.Path)); + XmlNode currentNode = GetPage(GetProtectedPage(d.Path)); if (Member != null) { IDictionaryEnumerator ide = Member.Groups.GetEnumerator(); @@ -431,7 +424,7 @@ namespace umbraco.cms.businesslogic.web return true; else { MembershipUser member = Membership.GetUser(memberId); - XmlNode currentNode = getPage(getProtectedPage(node.Path)); + XmlNode currentNode = GetPage(GetProtectedPage(node.Path)); if (member != null) { foreach(string role in Roles.GetRolesForUser()) { @@ -445,41 +438,13 @@ namespace umbraco.cms.businesslogic.web return hasAccess; } - [Obsolete("This method is no longer supported. Use the ASP.NET MemberShip methods instead", true)] - private static bool HasAccess(int DocumentId, string Path, cms.businesslogic.member.Member Member) - { - bool hasAccess = false; - - if (!IsProtected(DocumentId, Path)) - hasAccess = true; - else - { - XmlNode currentNode = getPage(getProtectedPage(Path)); - if (Member != null) - { - IDictionaryEnumerator ide = Member.Groups.GetEnumerator(); - while(ide.MoveNext()) - { - cms.businesslogic.member.MemberGroup mg = (cms.businesslogic.member.MemberGroup) ide.Value; - if (currentNode.SelectSingleNode("./group [@id=" + mg.Id.ToString() + "]") != null) - { - hasAccess = true; - break; - } - } - } - } - - return hasAccess; - } - - public static bool HasAccess(int documentId, string path, MembershipUser member) { + public static bool HasAccess(int documentId, string path, MembershipUser member) { bool hasAccess = false; if (!IsProtected(documentId, path)) hasAccess = true; else { - XmlNode currentNode = getPage(getProtectedPage(path)); + XmlNode currentNode = GetPage(GetProtectedPage(path)); if (member != null) { string[] roles = Roles.GetRolesForUser(member.UserName); foreach(string role in roles) { @@ -496,7 +461,7 @@ namespace umbraco.cms.businesslogic.web public static ProtectionType GetProtectionType(int DocumentId) { - XmlNode x = getPage(DocumentId); + XmlNode x = GetPage(DocumentId); try { if (bool.Parse(x.Attributes.GetNamedItem("simple").Value)) @@ -515,11 +480,11 @@ namespace umbraco.cms.businesslogic.web { bool isProtected = false; - if (!_checkedPages.ContainsKey(DocumentId)) + if (!CheckedPages.ContainsKey(DocumentId)) { foreach(string id in Path.Split(',')) { - if (getPage(int.Parse(id)) != null) + if (GetPage(int.Parse(id)) != null) { isProtected = true; break; @@ -529,39 +494,39 @@ namespace umbraco.cms.businesslogic.web // Add thread safe updating to the hashtable if (System.Web.HttpContext.Current != null) System.Web.HttpContext.Current.Application.Lock(); - if (!_checkedPages.ContainsKey(DocumentId)) - _checkedPages.Add(DocumentId, isProtected); + if (!CheckedPages.ContainsKey(DocumentId)) + CheckedPages.Add(DocumentId, isProtected); if (System.Web.HttpContext.Current != null) System.Web.HttpContext.Current.Application.UnLock(); } else - isProtected = (bool) _checkedPages[DocumentId]; + isProtected = (bool) CheckedPages[DocumentId]; return isProtected; } public static int GetErrorPage(string Path) { - return int.Parse(getPage(getProtectedPage(Path)).Attributes.GetNamedItem("noRightsPage").Value); + return int.Parse(GetPage(GetProtectedPage(Path)).Attributes.GetNamedItem("noRightsPage").Value); } public static int GetLoginPage(string Path) { - return int.Parse(getPage(getProtectedPage(Path)).Attributes.GetNamedItem("loginPage").Value); + return int.Parse(GetPage(GetProtectedPage(Path)).Attributes.GetNamedItem("loginPage").Value); } - private static int getProtectedPage(string Path) + private static int GetProtectedPage(string Path) { int protectedPage = 0; foreach(string id in Path.Split(',')) - if (getPage(int.Parse(id)) != null) + if (GetPage(int.Parse(id)) != null) protectedPage = int.Parse(id); return protectedPage; } - private static XmlNode getPage(int documentId) + private static XmlNode GetPage(int documentId) { XmlNode x = AccessXml.SelectSingleNode("/access/page [@id=" + documentId.ToString() + "]"); return x; diff --git a/src/umbraco.providers/members/MembershipEventHandler.cs b/src/umbraco.providers/members/MembershipEventHandler.cs index 71330dd8e0..7d8687f788 100644 --- a/src/umbraco.providers/members/MembershipEventHandler.cs +++ b/src/umbraco.providers/members/MembershipEventHandler.cs @@ -28,6 +28,7 @@ namespace umbraco.providers.members if (property != null) { property.Value = 1; + sender.Save(); } } }