mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
.Net 6 Upgrade
This commit is contained in:
@ -28,24 +28,23 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Security.Permissions
|
||||
namespace Esiur.Security.Permissions;
|
||||
|
||||
public enum ActionType
|
||||
{
|
||||
public enum ActionType
|
||||
{
|
||||
Attach,
|
||||
Delete,
|
||||
Execute,
|
||||
GetProperty,
|
||||
SetProperty,
|
||||
CreateResource,
|
||||
UpdateAttributes,
|
||||
InquireAttributes,
|
||||
AddParent,
|
||||
RemoveParent,
|
||||
AddChild,
|
||||
RemoveChild,
|
||||
Rename,
|
||||
ReceiveEvent,
|
||||
ViewTemplate
|
||||
}
|
||||
Attach,
|
||||
Delete,
|
||||
Execute,
|
||||
GetProperty,
|
||||
SetProperty,
|
||||
CreateResource,
|
||||
UpdateAttributes,
|
||||
InquireAttributes,
|
||||
AddParent,
|
||||
RemoveParent,
|
||||
AddChild,
|
||||
RemoveChild,
|
||||
Rename,
|
||||
ReceiveEvent,
|
||||
ViewTemplate
|
||||
}
|
||||
|
@ -34,23 +34,22 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Security.Permissions
|
||||
namespace Esiur.Security.Permissions;
|
||||
|
||||
public interface IPermissionsManager
|
||||
{
|
||||
public interface IPermissionsManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Check for permission.
|
||||
/// </summary>
|
||||
/// <param name="resource">IResource.</param>
|
||||
/// <param name="session">Caller sessions.</param>
|
||||
/// <param name="action">Action type</param>
|
||||
/// <param name="member">Function, property or event to check for permission.</param>
|
||||
/// <param name="inquirer">Permission inquirer object.</param>
|
||||
/// <returns>Allowed or denined.</returns>
|
||||
Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer = null);
|
||||
/// <summary>
|
||||
/// Check for permission.
|
||||
/// </summary>
|
||||
/// <param name="resource">IResource.</param>
|
||||
/// <param name="session">Caller sessions.</param>
|
||||
/// <param name="action">Action type</param>
|
||||
/// <param name="member">Function, property or event to check for permission.</param>
|
||||
/// <param name="inquirer">Permission inquirer object.</param>
|
||||
/// <returns>Allowed or denined.</returns>
|
||||
Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer = null);
|
||||
|
||||
bool Initialize(Structure settings, IResource resource);
|
||||
bool Initialize(Structure settings, IResource resource);
|
||||
|
||||
Structure Settings { get; }
|
||||
}
|
||||
Structure Settings { get; }
|
||||
}
|
||||
|
@ -2,12 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Security.Permissions
|
||||
namespace Esiur.Security.Permissions;
|
||||
|
||||
public enum Ruling
|
||||
{
|
||||
public enum Ruling
|
||||
{
|
||||
Denied,
|
||||
Allowed,
|
||||
DontCare
|
||||
}
|
||||
Denied,
|
||||
Allowed,
|
||||
DontCare
|
||||
}
|
||||
|
@ -31,23 +31,22 @@ using Esiur.Resource;
|
||||
using Esiur.Resource.Template;
|
||||
using Esiur.Security.Authority;
|
||||
|
||||
namespace Esiur.Security.Permissions
|
||||
namespace Esiur.Security.Permissions;
|
||||
|
||||
public class StorePermissionsManager : IPermissionsManager
|
||||
{
|
||||
public class StorePermissionsManager : IPermissionsManager
|
||||
Structure settings;
|
||||
|
||||
public Structure Settings => settings;
|
||||
|
||||
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer = null)
|
||||
{
|
||||
Structure settings;
|
||||
return resource.Instance.Store.Instance.Applicable(session, action, member, inquirer);
|
||||
}
|
||||
|
||||
public Structure Settings => settings;
|
||||
|
||||
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer = null)
|
||||
{
|
||||
return resource.Instance.Store.Instance.Applicable(session, action, member, inquirer);
|
||||
}
|
||||
|
||||
public bool Initialize(Structure settings, IResource resource)
|
||||
{
|
||||
this.settings = settings;
|
||||
return true;
|
||||
}
|
||||
public bool Initialize(Structure settings, IResource resource)
|
||||
{
|
||||
this.settings = settings;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -31,96 +31,95 @@ using Esiur.Resource;
|
||||
using Esiur.Resource.Template;
|
||||
using Esiur.Security.Authority;
|
||||
|
||||
namespace Esiur.Security.Permissions
|
||||
namespace Esiur.Security.Permissions;
|
||||
|
||||
public class UserPermissionsManager : IPermissionsManager
|
||||
{
|
||||
public class UserPermissionsManager : IPermissionsManager
|
||||
IResource resource;
|
||||
Structure settings;
|
||||
|
||||
public Structure Settings => settings;
|
||||
|
||||
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer)
|
||||
{
|
||||
IResource resource;
|
||||
Structure settings;
|
||||
Structure userPermissions = null;
|
||||
|
||||
public Structure Settings => settings;
|
||||
if (settings.ContainsKey(session.RemoteAuthentication.FullName))
|
||||
userPermissions = settings[session.RemoteAuthentication.FullName] as Structure;
|
||||
else if (settings.ContainsKey("public"))
|
||||
userPermissions = settings["public"] as Structure;
|
||||
else
|
||||
return Ruling.Denied;
|
||||
|
||||
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberTemplate member, object inquirer)
|
||||
if (action == ActionType.Attach)// || action == ActionType.Delete)
|
||||
{
|
||||
Structure userPermissions = null;
|
||||
|
||||
if (settings.ContainsKey(session.RemoteAuthentication.FullName))
|
||||
userPermissions = settings[session.RemoteAuthentication.FullName] as Structure;
|
||||
else if (settings.ContainsKey("public"))
|
||||
userPermissions = settings["public"] as Structure;
|
||||
else
|
||||
if ((string)userPermissions["_attach"] != "yes")
|
||||
return Ruling.Denied;
|
||||
|
||||
if (action == ActionType.Attach)// || action == ActionType.Delete)
|
||||
{
|
||||
if ((string)userPermissions["_attach"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.Delete)
|
||||
{
|
||||
if ((string)userPermissions["_delete"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action== ActionType.InquireAttributes)
|
||||
{
|
||||
if ((string)userPermissions["_get_attributes"] == "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.UpdateAttributes)
|
||||
{
|
||||
if ((string)userPermissions["_set_attributes"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.AddChild)
|
||||
{
|
||||
if ((string)userPermissions["_add_child"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.RemoveChild)
|
||||
{
|
||||
if ((string)userPermissions["_remove_child"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.AddParent)
|
||||
{
|
||||
if ((string)userPermissions["_add_parent"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.RemoveParent)
|
||||
{
|
||||
if ((string)userPermissions["_remove_parent"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.Rename)
|
||||
{
|
||||
if ((string)userPermissions["_rename"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (userPermissions.ContainsKey(member?.Name))
|
||||
{
|
||||
Structure methodPermissions = userPermissions[member.Name] as Structure;
|
||||
if ((string)methodPermissions[action.ToString()] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
|
||||
return Ruling.DontCare;
|
||||
}
|
||||
|
||||
public UserPermissionsManager()
|
||||
else if (action == ActionType.Delete)
|
||||
{
|
||||
|
||||
if ((string)userPermissions["_delete"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
|
||||
public UserPermissionsManager(Structure settings)
|
||||
else if (action == ActionType.InquireAttributes)
|
||||
{
|
||||
this.settings = settings;
|
||||
if ((string)userPermissions["_get_attributes"] == "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.UpdateAttributes)
|
||||
{
|
||||
if ((string)userPermissions["_set_attributes"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.AddChild)
|
||||
{
|
||||
if ((string)userPermissions["_add_child"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.RemoveChild)
|
||||
{
|
||||
if ((string)userPermissions["_remove_child"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.AddParent)
|
||||
{
|
||||
if ((string)userPermissions["_add_parent"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.RemoveParent)
|
||||
{
|
||||
if ((string)userPermissions["_remove_parent"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (action == ActionType.Rename)
|
||||
{
|
||||
if ((string)userPermissions["_rename"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
else if (userPermissions.ContainsKey(member?.Name))
|
||||
{
|
||||
Structure methodPermissions = userPermissions[member.Name] as Structure;
|
||||
if ((string)methodPermissions[action.ToString()] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
|
||||
public bool Initialize(Structure settings, IResource resource)
|
||||
{
|
||||
this.resource = resource;
|
||||
this.settings = settings;
|
||||
return true;
|
||||
}
|
||||
return Ruling.DontCare;
|
||||
}
|
||||
|
||||
public UserPermissionsManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public UserPermissionsManager(Structure settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public bool Initialize(Structure settings, IResource resource)
|
||||
{
|
||||
this.resource = resource;
|
||||
this.settings = settings;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user