public void TestSimpleAuthorization()
        {
            using (new ObjectCacheScope(SetupSimpleData()))
            {
                IAuthorizationProvider provider = Afcas.GetAuthorizationProvider();

                Principal G  = ObjectCache.Current.Get <Principal>("G");
                Principal G2 = ObjectCache.Current.Get <Principal>("G2");
                Principal U1 = ObjectCache.Current.Get <Principal>("U1");

                Operation O  = ObjectCache.Current.Get <Operation>("O");
                Operation O3 = ObjectCache.Current.Get <Operation>("O3");

                SampleResource        R      = SampleResource.GetOrCreateSampleResource("R");
                SampleResource        R2     = SampleResource.GetOrCreateSampleResource("R2");
                ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource");

                Assert.That(provider.IsAuthorized(G.Key, O.Key, resFac.GenerateResourceHandle(R)),
                            "authorization must exist");
                Assert.That(provider.IsAuthorized(G2.Key, O3.Key, resFac.GenerateResourceHandle(R2)),
                            "authorization must exist");
                Assert.That(provider.IsAuthorized(U1.Key, O3.Key, resFac.GenerateResourceHandle(R2)),
                            "authorization must exist");
            }
        }
Exemple #2
0
        public void TestAccessors( )
        {
            SampleResource sample = SampleResource.GetOrCreateSampleResource("1");

            sample.StringTest = "123";
            sample.Int32Test  = 123;

            ReflectionHelper.FastMemberGetter stringFieldGetter = ReflectionHelper.GetCachedFieldGetter(typeof(SampleResource),
                                                                                                        "_StringTest");
            ReflectionHelper.FastMemberSetter stringFieldSetter = ReflectionHelper.GetCachedFieldSetter(typeof(SampleResource),
                                                                                                        "_StringTest");
            ReflectionHelper.FastMemberGetter intFieldGetter = ReflectionHelper.GetCachedFieldGetter(typeof(SampleResource),
                                                                                                     "_Int32Test");
            ReflectionHelper.FastMemberSetter intFieldSetter = ReflectionHelper.GetCachedFieldSetter(typeof(SampleResource),
                                                                                                     "_Int32Test");

            Assert.That(stringFieldGetter.Invoke(sample).Equals(sample.StringTest));
            Assert.That(intFieldGetter.Invoke(sample).Equals(sample.Int32Test));

            stringFieldSetter.Invoke(sample, "456");
            intFieldSetter.Invoke(sample, 456);
            Assert.That(sample.StringTest == "456");
            Assert.That(sample.Int32Test == 456);

            ReflectionHelper.FastMemberGetter stringPropGetter = ReflectionHelper.GetCachedPropertyGetter(typeof(SampleResource),
                                                                                                          "StringTest");
            ReflectionHelper.FastMemberSetter stringPropSetter = ReflectionHelper.GetCachedPropertySetter(typeof(SampleResource),
                                                                                                          "StringTest");
            ReflectionHelper.FastMemberGetter intPropGetter = ReflectionHelper.GetCachedPropertyGetter(typeof(SampleResource),
                                                                                                       "Int32Test");
            ReflectionHelper.FastMemberSetter intPropSetter = ReflectionHelper.GetCachedPropertySetter(typeof(SampleResource),
                                                                                                       "Int32Test");


            Assert.That(stringPropGetter.Invoke(sample).Equals(sample.StringTest));
            Assert.That(intPropGetter.Invoke(sample).Equals(sample.Int32Test));
            stringPropSetter.Invoke(sample, "789");
            intPropSetter.Invoke(sample, 789);
            Assert.That(sample.StringTest == "789");
            Assert.That(sample.Int32Test == 789);

            ReflectionHelper.FastMemberGetter keyPropGetter  = ReflectionHelper.GetCachedPropertyGetter(typeof(SampleResource), "Key");
            ReflectionHelper.FastMemberSetter keyFieldSetter = ReflectionHelper.GetCachedFieldSetter(typeof(SampleResource), "_Key");

            Assert.That(sample.Key.Equals(keyPropGetter.Invoke(sample)));
            keyFieldSetter.Invoke(sample, "xxx");
            Assert.That(sample.Key.Equals("xxx"));
        }
        public void TestOffline()
        {
            using (new ObjectCacheScope(SetupSimpleData()))
            {
                IAuthorizationManager manager = Afcas.GetAuthorizationManager();
                manager.GetOperationList();

                Principal         U1 = ObjectCache.Current.Get <Principal>("U1");
                IList <Operation> ol = manager.GetAuthorizedOperations(U1.Key, NullResource.Instance);
                Assert.AreEqual(0, ol.Count);

                ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource");
                SampleResource        R      = SampleResource.GetOrCreateSampleResource("R");

                ol = manager.GetAuthorizedOperations(U1.Key, resFac.GenerateResourceHandle(R));
                Assert.AreEqual(4, ol.Count);

                IList <ResourceAccessPredicate> acl = manager.GetAuthorizationDigest(U1.Key);
                Assert.AreEqual(12, acl.Count);
            }
        }
        public void TestSimpleHierarchy()
        {
            using (new ObjectCacheScope(SetupSimpleData()))
            {
                IAuthorizationProvider provider = Afcas.GetAuthorizationProvider();

                Principal G  = ObjectCache.Current.Get <Principal>("G");
                Principal G1 = ObjectCache.Current.Get <Principal>("G1");

                Operation O  = ObjectCache.Current.Get <Operation>("O");
                Operation O3 = ObjectCache.Current.Get <Operation>("O3");

                ResourceHandleFactory resFac = Afcas.GetHandleFactory("SampleResource");
                SampleResource        R      = SampleResource.GetOrCreateSampleResource("R");
                SampleResource        R2     = SampleResource.GetOrCreateSampleResource("R2");

                Assert.That(provider.IsMemberOf(G.Key, G1.Key));
                Assert.That(provider.IsSubOperation(O.Key, O3.Key));
                Assert.That(!provider.IsSubOperation(O3.Key, O.Key));
                Assert.That(
                    !provider.IsSubResource(resFac.GenerateResourceHandle(R), resFac.GenerateResourceHandle(R2)));
            }
        }
Exemple #5
0
 public override ResourceHandle GenerateResourceHandle(object resource)
 {
     return(new SampleResourceHandle(this, SampleResource.GetOrCreateSampleResource((( SampleResource )resource).Key)));
 }
Exemple #6
0
 protected internal override ResourceHandle GenerateResourceHandleByKey(string resourceId)
 {
     return(new SampleResourceHandle(this, SampleResource.GetOrCreateSampleResource(resourceId)));
 }
Exemple #7
0
 public SampleResourceHandle(ResourceHandleFactory fac, SampleResource res) : base(fac)
 {
     _Key = res.Key;
 }