public void Test_AccessGranted()
        {
            _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(_methodInformation, TestAccessTypes.First);
            _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, true);
            _testHelper.ReplayAll();

            bool hasAccess = _securityClient.HasStaticMethodAccess(typeof(SecurableObject), _methodInformation);

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

            bool hasAccess = _securityClient.HasStaticMethodAccess(typeof(SecurableObject), "IsValid");

            _testHelper.VerifyAll();
            Assert.That(hasAccess, Is.True);
        }
        public void HasAccess_StaticMethod()
        {
            var securityContext            = SecurityContext.CreateStateless(typeof(SecurableObject));
            var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory>();

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

            var securityClient = new SecurityClient(
                _securityProviderStub,
                new PermissionReflector(),
                _principalProviderStub,
                new FunctionalSecurityStrategy(),
                new ReflectionBasedMemberResolver());

            var methodInfo = typeof(SecurableObject).GetMethod("IsValid", new[] { typeof(SecurableObject) });

            var hasMethodAccess = securityClient.HasStaticMethodAccess(typeof(SecurableObject), methodInfo);

            Assert.That(hasMethodAccess, Is.True);
        }
Beispiel #4
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));
            }
        }