From bb64141207356f9082c621d93fb5d16bca34e2bb Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 1 Feb 2019 16:35:10 +1100 Subject: [PATCH] removes obsolete method --- .../Mvc/MemberAuthorizeAttribute.cs | 46 ++++--------------- src/Umbraco.Web/Security/MembershipHelper.cs | 5 -- src/Umbraco.Web/Security/WebSecurity.cs | 25 +--------- .../WebApi/MemberAuthorizeAttribute.cs | 46 +++---------------- 4 files changed, 16 insertions(+), 106 deletions(-) diff --git a/src/Umbraco.Web/Mvc/MemberAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/MemberAuthorizeAttribute.cs index 287edd3bce..5f81ced3f0 100644 --- a/src/Umbraco.Web/Mvc/MemberAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/MemberAuthorizeAttribute.cs @@ -1,10 +1,11 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Web; using System.Web.Mvc; using AuthorizeAttribute = System.Web.Mvc.AuthorizeAttribute; using Umbraco.Core; -using Umbraco.Web.Composing; +using Umbraco.Web.Security; +using Umbraco.Core.Composing; +using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Web.Mvc { @@ -14,35 +15,6 @@ namespace Umbraco.Web.Mvc /// public sealed class MemberAuthorizeAttribute : AuthorizeAttribute { - // see note in HttpInstallAuthorizeAttribute - private readonly UmbracoContext _umbracoContext; - - private UmbracoContext UmbracoContext => _umbracoContext ?? Current.UmbracoContext; - - /// - /// THIS SHOULD BE ONLY USED FOR UNIT TESTS - /// - /// - public MemberAuthorizeAttribute(UmbracoContext umbracoContext) - { - if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); - _umbracoContext = umbracoContext; - } - - public MemberAuthorizeAttribute() - { - - } - - /// - /// Flag for whether to allow all site visitors or just authenticated members - /// - /// - /// This is the same as applying the [AllowAnonymous] attribute - /// - [Obsolete("Use [AllowAnonymous] instead")] - public bool AllowAll { get; set; } - /// /// Comma delimited list of allowed member types /// @@ -70,17 +42,15 @@ namespace Umbraco.Web.Mvc var members = new List(); foreach (var s in AllowMembers.Split(',')) { - int id; - if (int.TryParse(s, out id)) + if (int.TryParse(s, out var id)) { members.Add(id); } } - return UmbracoContext.Security.IsMemberAuthorized(AllowAll, - AllowType.Split(','), - AllowGroup.Split(','), - members); + var helper = Current.Factory.GetInstance(); + return helper.IsMemberAuthorized(AllowType.Split(','), AllowGroup.Split(','), members); + } /// diff --git a/src/Umbraco.Web/Security/MembershipHelper.cs b/src/Umbraco.Web/Security/MembershipHelper.cs index daec4bb1f7..8de42fc12b 100644 --- a/src/Umbraco.Web/Security/MembershipHelper.cs +++ b/src/Umbraco.Web/Security/MembershipHelper.cs @@ -599,20 +599,15 @@ namespace Umbraco.Web.Security /// /// Returns true or false if the currently logged in member is authorized based on the parameters provided /// - /// /// /// /// /// public virtual bool IsMemberAuthorized( - bool allowAll = false, IEnumerable allowTypes = null, IEnumerable allowGroups = null, IEnumerable allowMembers = null) { - if (allowAll) - return true; - if (allowTypes == null) allowTypes = Enumerable.Empty(); if (allowGroups == null) diff --git a/src/Umbraco.Web/Security/WebSecurity.cs b/src/Umbraco.Web/Security/WebSecurity.cs index 54ff1bba3f..ef6193694c 100644 --- a/src/Umbraco.Web/Security/WebSecurity.cs +++ b/src/Umbraco.Web/Security/WebSecurity.cs @@ -33,30 +33,7 @@ namespace Umbraco.Web.Security _userService = userService; _globalSettings = globalSettings; } - - /// - /// Returns true or false if the currently logged in member is authorized based on the parameters provided - /// - /// - /// - /// - /// - /// - [Obsolete("Use MembershipHelper.IsMemberAuthorized instead")] - public bool IsMemberAuthorized( - bool allowAll = false, - IEnumerable allowTypes = null, - IEnumerable allowGroups = null, - IEnumerable allowMembers = null) - { - if (Current.UmbracoContext == null) - { - return false; - } - var helper = Current.Factory.GetInstance(); - return helper.IsMemberAuthorized(allowAll, allowTypes, allowGroups, allowMembers); - } - + private IUser _currentUser; /// diff --git a/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs b/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs index 12caa29703..bc1e9a4318 100644 --- a/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs +++ b/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs @@ -1,7 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Web.Http; using Umbraco.Core; +using Umbraco.Web.Security; +using Umbraco.Core.Composing; +using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Web.WebApi { @@ -11,37 +13,6 @@ namespace Umbraco.Web.WebApi /// public sealed class MemberAuthorizeAttribute : AuthorizeAttribute { - private readonly UmbracoContext _umbracoContext; - - private UmbracoContext GetUmbracoContext() - { - return _umbracoContext ?? UmbracoContext.Current; - } - - /// - /// THIS SHOULD BE ONLY USED FOR UNIT TESTS - /// - /// - public MemberAuthorizeAttribute(UmbracoContext umbracoContext) - { - if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); - _umbracoContext = umbracoContext; - } - - public MemberAuthorizeAttribute() - { - - } - - /// - /// Flag for whether to allow all site visitors or just authenticated members - /// - /// - /// This is the same as applying the [AllowAnonymous] attribute - /// - [Obsolete("Use [AllowAnonymous] instead")] - public bool AllowAll { get; set; } - /// /// Comma delimited list of allowed member types /// @@ -69,17 +40,14 @@ namespace Umbraco.Web.WebApi var members = new List(); foreach (var s in AllowMembers.Split(',')) { - int id; - if (int.TryParse(s, out id)) + if (int.TryParse(s, out var id)) { members.Add(id); } } - return GetUmbracoContext().Security.IsMemberAuthorized(AllowAll, - AllowType.Split(','), - AllowGroup.Split(','), - members); + var helper = Current.Factory.GetInstance(); + return helper.IsMemberAuthorized(AllowType.Split(','), AllowGroup.Split(','), members); } }