improved legacy support for module authorization policy
This commit is contained in:
		| @ -3,6 +3,7 @@ using Microsoft.AspNetCore.Http; | ||||
| using Oqtane.Infrastructure; | ||||
| using System.Collections.Generic; | ||||
| using System; | ||||
| using Oqtane.Shared; | ||||
|  | ||||
| namespace Oqtane.Controllers | ||||
| { | ||||
| @ -11,23 +12,25 @@ namespace Oqtane.Controllers | ||||
|         protected readonly ILogManager _logger; | ||||
|         // querystring parameters for policy authorization and validation | ||||
|         protected Dictionary<string, int> _authEntityId = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); | ||||
|         protected int _entityId = -1; // deprecated | ||||
|         protected int _entityId = -1; // legacy support | ||||
|  | ||||
|         public ModuleControllerBase(ILogManager logger, IHttpContextAccessor accessor) | ||||
|         { | ||||
|             _logger = logger; | ||||
|  | ||||
|             // populate policy authorization dictionary | ||||
|             int value; | ||||
|             foreach (var param in accessor.HttpContext.Request.Query) | ||||
|             { | ||||
|                 if (param.Key.StartsWith("auth") && param.Key.EndsWith("id") && int.TryParse(param.Value, out value)) | ||||
|                 { | ||||
|                     _authEntityId.Add(param.Key.Substring(4, param.Key.Length - 6), int.Parse(param.Value)); | ||||
|                     _authEntityId.Add(param.Key.Substring(4, param.Key.Length - 6), value); | ||||
|                 } | ||||
|             } | ||||
|             // entityid is deprecated | ||||
|             if (accessor.HttpContext.Request.Query.ContainsKey("entityid")) | ||||
|             // legacy support | ||||
|             if (_authEntityId.ContainsKey(EntityNames.Module)) | ||||
|             { | ||||
|                 _entityId = int.Parse(accessor.HttpContext.Request.Query["entityid"]); | ||||
|                 _entityId = _authEntityId[EntityNames.Module]; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
| @ -1,19 +1,14 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.AspNetCore.Identity; | ||||
| using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Migrations; | ||||
| using Microsoft.Extensions.Configuration; | ||||
| using Oqtane.Databases.Interfaces; | ||||
| using Oqtane.Extensions; | ||||
| using Oqtane.Infrastructure; | ||||
| using Oqtane.Interfaces; | ||||
| using Oqtane.Migrations.Framework; | ||||
| using Oqtane.Models; | ||||
| using Oqtane.Shared; | ||||
|  | ||||
| // ReSharper disable BuiltInTypeReferenceStyleForMemberAccess | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker