|
@@ -0,0 +1,53 @@
|
|
|
+using System;
|
|
|
+using System.Linq;
|
|
|
+
|
|
|
+namespace InABox.Core
|
|
|
+{
|
|
|
+ [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
|
|
|
+ public class SecurityAttribute : Attribute
|
|
|
+ {
|
|
|
+ public Type SecurityDescriptor { get; set; }
|
|
|
+
|
|
|
+ private SecurityAttribute() { }
|
|
|
+
|
|
|
+ public SecurityAttribute(Type securityDescriptor)
|
|
|
+ {
|
|
|
+ if (!securityDescriptor.GetInterfaces().Contains(typeof(ISecurityDescriptor)))
|
|
|
+ throw new Exception(securityDescriptor.EntityName() + " is not a valid security descriptor!");
|
|
|
+ SecurityDescriptor = securityDescriptor;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual SecurityAttribute Clone()
|
|
|
+ {
|
|
|
+ var result = new SecurityAttribute(SecurityDescriptor);
|
|
|
+ result.SecurityDescriptor = SecurityDescriptor;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class CanViewAttribute : SecurityAttribute
|
|
|
+ {
|
|
|
+ public CanViewAttribute(Type TEntity): base(
|
|
|
+ typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanView<>).MakeGenericType(TEntity)))
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class CanEditAttribute : SecurityAttribute
|
|
|
+ {
|
|
|
+ public CanEditAttribute(Type TEntity) : base(
|
|
|
+ typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanEdit<>).MakeGenericType(TEntity)))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class CanDeleteAttribute : SecurityAttribute
|
|
|
+ {
|
|
|
+ public CanDeleteAttribute(Type TEntity) : base(
|
|
|
+ typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanDelete<>).MakeGenericType(TEntity)))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|