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"); } }
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))); } }
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); } }