2025-06-17 15:46:04 +02:00
|
|
|
|
using BS.Shared;
|
|
|
|
|
|
using System;
|
2025-02-19 16:29:36 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2025-06-03 15:46:41 +02:00
|
|
|
|
namespace BeWo.Service.Attributes
|
2025-02-19 16:29:36 +01:00
|
|
|
|
{
|
2025-06-17 15:46:04 +02:00
|
|
|
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true)]
|
|
|
|
|
|
public class RequireWcfAuthorizationAttribute : Attribute
|
2025-02-19 16:29:36 +01:00
|
|
|
|
{
|
2025-06-17 15:46:04 +02:00
|
|
|
|
public RequireWcfAuthorizationAttribute(params UserRightType[] pPermissions)
|
2025-02-19 16:29:36 +01:00
|
|
|
|
{
|
2025-06-17 15:46:04 +02:00
|
|
|
|
Permissions = pPermissions;
|
2025-02-19 16:29:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-17 15:46:04 +02:00
|
|
|
|
public UserRightType[] Permissions { get; }
|
|
|
|
|
|
|
2025-02-19 16:29:36 +01:00
|
|
|
|
public bool HasPermission(IEnumerable<UserRightType> rights)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Permissions is null || Permissions.Length == 0)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var right in rights)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (HasPermission(right))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool HasPermission(UserRightType right)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Permissions is null || Permissions.Length == 0)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < Permissions.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var permission = Permissions[i];
|
|
|
|
|
|
if (right == permission) return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|