Exemplo n.º 1
0
        public bool HasStatelessAccess(Type functionType)
        {
            ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("functionType", functionType, typeof(WxeFunction));

            if (SecurityFreeSection.IsActive)
            {
                return(true);
            }

            WxeDemandTargetPermissionAttribute attribute = GetPermissionAttribute(functionType);

            if (attribute == null)
            {
                return(true);
            }

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(functionType, attribute);
            SecurityClient securityClient = SecurityClient.CreateSecurityClientFromConfiguration();

            switch (helper.MethodType)
            {
            case MethodType.Instance:
                return(securityClient.HasStatelessMethodAccess(helper.GetTypeOfSecurableObject(), helper.MethodName));

            case MethodType.Static:
                return(securityClient.HasStaticMethodAccess(helper.SecurableClass, helper.MethodName));

            case MethodType.Constructor:
                return(securityClient.HasConstructorAccess(helper.SecurableClass));

            default:
                throw new InvalidOperationException(string.Format(
                                                        "Value '{0}' is not supported by the MethodType property of the WxeDemandMethodPermissionAttribute.",
                                                        helper.MethodType));
            }
        }