private static bool IsAuthorized(string fqn, ResourceTypes type, Guid guid)
        {
            var name      = default(string);
            var asAppPool = ConnectionClass.ConnectAsAppPool;

            if (!asAppPool)
            {
                ConnectionClass.ConnectAsAppPool = true;
            }
            var client = ConnectionClass.GetFormsClient();

            if (!asAppPool)
            {
                ConnectionClass.ConnectAsAppPool = false;
            }

            var identities = IdentityResolver.GetIdentities(fqn);
            var rules      = RuleProvider.GetRules();

            switch (type)
            {
            case ResourceTypes.View:
            {
                // Uses internal caches
                var details = client.GetForm(guid);
                if (details != null)
                {
                    name = details.Name;
                }
            }
            break;

            case ResourceTypes.Form:
            {
                // Uses internal caches
                var details = client.GetForm(guid);
                if (details != null)
                {
                    name = details.Name;
                }
            }
            break;

            default:
                throw new NotSupportedException(type.ToString());
            }

            if (!string.IsNullOrEmpty(name))
            {
                return(rules.IsAuthorized(name, type, identities));
            }
            else
            {
                return(false);
            }
        }
        public async Task Resolve_Resolves()
        {
            // arrange
            IIdentityResolver instanceUnderTest = new IdentityResolver();

            // act
            var result = await instanceUnderTest.GetUserNameAsync();

            // assert
            Assert.AreEqual("bob", result);
        }
Пример #3
0
        public void TestIdentityResolverWithMapAndKeyAttribute()
        {
            // Setup
            var resolver = new IdentityResolver();

            // Act
            var result   = resolver.Resolve(typeof(EntityModelWithIdentityAndKeyAttribute)).GetMappedName();
            var expected = "PrimaryId";

            // Assert
            Assert.AreEqual(expected, result);
        }
Пример #4
0
        public void TestIdentityResolverWithKeyAttributeAndMappings()
        {
            // Setup
            var resolver = new IdentityResolver();

            FluentMapper
            .Entity <EntityModelWithKeyAttribute>()
            .Primary(e => e.SecondaryId);

            // Act
            var result   = resolver.Resolve(typeof(EntityModelWithKeyAttribute)).GetMappedName();
            var expected = "PrimaryId";

            // Assert
            Assert.AreEqual(expected, result);
        }
Пример #5
0
        public async Task Validate(HamsterUpdate model)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }

            var identity = await IdentityResolver.GetIdentityAsync();

            var hamster = DbContext.Hamsters.SingleOrDefault(h => h.Id == model.Id);

            if (hamster.CreatedById != identity.Id)
            {
                throw new HamsterAccessException();
            }
        }