Пример #1
0
        public object Intercept(IMethodInvocation invocation, params object[] args)
        {
            MethodInfo methodInfo = invocation.MethodInvocationTarget;

            if (!methodInfo.IsDefined(typeof(PermissionAttribute), true))
            {
                return(invocation.Proceed(args));
            }
            else
            {
                object[] attrs = methodInfo.GetCustomAttributes(typeof(PermissionAttribute), true);

                PermissionAttribute permissionAtt = (PermissionAttribute)attrs[0];

                ISecurityManager manager = (ISecurityManager)_kernel[typeof(ISecurityManager)];

                IPolicy policy =
                    manager.Generate(
                        permissionAtt, Thread.CurrentPrincipal);

                if (policy == null)
                {
                    return(invocation.Proceed(args));
                }

                object value = null;

                if (policy.Evaluate())
                {
                    value = invocation.Proceed(args);
                }
                else
                {
                    throw new SecurityException("Not Allowed");
                }

                return(value);
            }
        }
Пример #2
0
 public static PolicyResult Or <T>(this PolicyResult left, IPolicy <T> policy) =>
 left.IsSuccess()
         ? left
         : policy.Evaluate();
Пример #3
0
 public static PolicyResult And <T>(this PolicyResult left, IPolicy <T> policy) =>
 left.IsSuccess()
         ? policy.Evaluate()
         : left;