예제 #1
0
        public void Test_AccessGranted()
        {
            _testHelper.ExpectMemberResolverGetMethodInformation(_methodInfo, MemberAffiliation.Instance, _methodInformation);
            _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(_methodInformation, GeneralAccessTypes.Edit, TestAccessTypes.First);
            _testHelper.ExpectObjectSecurityStrategyHasAccess(new Enum[] { GeneralAccessTypes.Edit, TestAccessTypes.First }, true);
            _testHelper.ReplayAll();

            bool hasAccess = _securityClient.HasMethodAccess(_testHelper.SecurableObject, _methodInfo);

            _testHelper.VerifyAll();
            Assert.That(hasAccess, Is.True);
        }
        public void Test_AccessGranted()
        {
            _testHelper.ReplayAll();

            bool hasAccess = _securityClient.HasMethodAccess(_testHelper.SecurableObject, "Show");

            _testHelper.VerifyAll();
            Assert.That(hasAccess, Is.True);
        }
        public void HasAccess_InstanceMethod()
        {
            var securityContextStub        = MockRepository.GenerateStub <ISecurityContext>();
            var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory>();

            securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub);
            _securityProviderStub
            .Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub))
            .Return(new[] { AccessType.Get(GeneralAccessTypes.Delete) });

            ISecurableObject securableObject =
                new SecurableObject(ObjectSecurityStrategy.Create(securityContextFactoryStub, InvalidationToken.Create()));
            var methodInfo = typeof(SecurableObject).GetMethod("Delete", new Type[0]);

            var hasMethodAccess = _securityClient.HasMethodAccess(securableObject, methodInfo);

            Assert.That(hasMethodAccess, Is.True);
        }
        public void Test_AccessGranted()
        {
            _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(_methodInformation, TestAccessTypes.First);
            _testHelper.ExpectObjectSecurityStrategyHasAccess(TestAccessTypes.First, true);
            _testHelper.ReplayAll();

            bool hasAccess = _securityClient.HasMethodAccess(_testHelper.SecurableObject, _methodInformation);

            _testHelper.VerifyAll();
            Assert.That(hasAccess, Is.True);
        }
        // methods and properties

        public bool HasAccess(ISecurableObject securableObject, Delegate handler)
        {
            if (handler == null)
            {
                return(true);
            }

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

            List <DemandTargetPermissionAttribute> attributes = GetPermissionAttributes(handler.GetInvocationList());

            bool hasAccess = true;

            foreach (DemandTargetPermissionAttribute attribute in attributes)
            {
                switch (attribute.PermissionSource)
                {
                case PermissionSource.WxeFunction:
                    hasAccess &= WxeFunction.HasAccess(attribute.FunctionType);
                    break;

                case PermissionSource.SecurableObject:
                    SecurityClient securityClient = SecurityClient.CreateSecurityClientFromConfiguration();
                    if (securableObject == null)
                    {
                        hasAccess &= securityClient.HasStatelessMethodAccess(attribute.SecurableClass, attribute.MethodName);
                    }
                    else
                    {
                        hasAccess &= securityClient.HasMethodAccess(securableObject, attribute.MethodName);
                    }
                    break;

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

                if (!hasAccess)
                {
                    break;
                }
            }

            return(hasAccess);
        }
예제 #6
0
        public bool HasAccess(WxeFunction function)
        {
            ArgumentUtility.CheckNotNull("function", function);

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

            WxeDemandTargetPermissionAttribute attribute = GetPermissionAttribute(function.GetType());

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

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

            switch (helper.MethodType)
            {
            case MethodType.Instance:
                return(securityClient.HasMethodAccess(helper.GetSecurableObject(function), 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));
            }
        }