|
@@ -1,6 +1,7 @@
|
|
using System;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
@@ -27,7 +28,8 @@ namespace InABox.Core
|
|
{
|
|
{
|
|
var tokens = CoreUtils.TypeList(
|
|
var tokens = CoreUtils.TypeList(
|
|
AppDomain.CurrentDomain.GetAssemblies(),
|
|
AppDomain.CurrentDomain.GetAssemblies(),
|
|
- x => !x.IsAbstract && !x.IsGenericType && x.GetInterfaces().Any(i => i == typeof(ISecurityDescriptor))
|
|
|
|
|
|
+ x => !x.IsAbstract && !x.IsGenericType &&
|
|
|
|
+ x.GetInterfaces().Any(i => i == typeof(ISecurityDescriptor))
|
|
);
|
|
);
|
|
foreach (var _class in tokens)
|
|
foreach (var _class in tokens)
|
|
{
|
|
{
|
|
@@ -49,12 +51,12 @@ namespace InABox.Core
|
|
});
|
|
});
|
|
var edit = Task.Run(() =>
|
|
var edit = Task.Run(() =>
|
|
{
|
|
{
|
|
- foreach (var _class in tokens.Where(x=>x.GetCustomAttribute<AutoEntity>() == null))
|
|
|
|
|
|
+ foreach (var _class in tokens.Where(x => x.GetCustomAttribute<AutoEntity>() == null))
|
|
CheckAutoToken(_class, typeof(CanEdit<>));
|
|
CheckAutoToken(_class, typeof(CanEdit<>));
|
|
});
|
|
});
|
|
var delete = Task.Run(() =>
|
|
var delete = Task.Run(() =>
|
|
{
|
|
{
|
|
- foreach (var _class in tokens.Where(x=>x.GetCustomAttribute<AutoEntity>() == null))
|
|
|
|
|
|
+ foreach (var _class in tokens.Where(x => x.GetCustomAttribute<AutoEntity>() == null))
|
|
CheckAutoToken(_class, typeof(CanDelete<>));
|
|
CheckAutoToken(_class, typeof(CanDelete<>));
|
|
});
|
|
});
|
|
var issues = Task.Run(() =>
|
|
var issues = Task.Run(() =>
|
|
@@ -94,6 +96,28 @@ namespace InABox.Core
|
|
_descriptors = null;
|
|
_descriptors = null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void CheckTokens()
|
|
|
|
+ {
|
|
|
|
+ var tasks = new Task[] {
|
|
|
|
+ Task.Run(() =>
|
|
|
|
+ {
|
|
|
|
+ _usertokens ??= new Client<UserSecurityToken>().Load(
|
|
|
|
+ new Filter<UserSecurityToken>(x => x.User.ID).IsEqualTo(ClientFactory.UserGuid)
|
|
|
|
+ );
|
|
|
|
+ }),
|
|
|
|
+ Task.Run(() =>
|
|
|
|
+ {
|
|
|
|
+ _grouptokens ??= new Client<SecurityToken>().Load(
|
|
|
|
+ new Filter<SecurityToken>(x => x.Group.ID).IsEqualTo(ClientFactory.UserSecurityID));
|
|
|
|
+ }),
|
|
|
|
+ Task.Run(() =>
|
|
|
|
+ {
|
|
|
|
+ _globaltokens ??= new Client<GlobalSecurityToken>().Load();
|
|
|
|
+ }),
|
|
|
|
+ };
|
|
|
|
+ Task.WaitAll(tasks);
|
|
|
|
+ }
|
|
|
|
+
|
|
private static void CheckAutoToken(Type _class, Type type)
|
|
private static void CheckAutoToken(Type _class, Type type)
|
|
{
|
|
{
|
|
var basetype = typeof(AutoSecurityDescriptor<,>);
|
|
var basetype = typeof(AutoSecurityDescriptor<,>);
|
|
@@ -113,20 +137,19 @@ namespace InABox.Core
|
|
if (userGuid == Guid.Empty)
|
|
if (userGuid == Guid.Empty)
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
+ CheckTokens();
|
|
|
|
+
|
|
// First Check for a matching User Token (override)
|
|
// First Check for a matching User Token (override)
|
|
- _usertokens ??= new Client<UserSecurityToken>().Load(new Filter<UserSecurityToken>(x => x.User.ID).IsEqualTo(userGuid));
|
|
|
|
var usertoken = _usertokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
var usertoken = _usertokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
if (usertoken != null)
|
|
if (usertoken != null)
|
|
return usertoken.Enabled;
|
|
return usertoken.Enabled;
|
|
|
|
|
|
// If not found, fall back to the Group Token
|
|
// If not found, fall back to the Group Token
|
|
- _grouptokens ??= new Client<SecurityToken>().Load(new Filter<SecurityToken>(x => x.Group.ID).IsEqualTo(securityId));
|
|
|
|
var grouptoken = _grouptokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
var grouptoken = _grouptokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
if (grouptoken != null)
|
|
if (grouptoken != null)
|
|
return grouptoken.Enabled;
|
|
return grouptoken.Enabled;
|
|
|
|
|
|
// Still not found? fall back to the Global Token
|
|
// Still not found? fall back to the Global Token
|
|
- _globaltokens ??= new Client<GlobalSecurityToken>().Load();
|
|
|
|
var globaltoken = _globaltokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
var globaltoken = _globaltokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
if (globaltoken != null)
|
|
if (globaltoken != null)
|
|
return globaltoken.Enabled;
|
|
return globaltoken.Enabled;
|