コード例 #1
0
 ISecurityContext ISecurityContextFactory.CreateSecurityContext()
 {
     using (SecurityFreeSection.Activate())
     {
         return(SecurityContext.Create(GetPublicDomainObjectType(), GetOwner(), GetOwningGroup(), GetOwningTenant(), GetStates(), GetAbstractRoles()));
     }
 }
        public void SetUp()
        {
            _context = SecurityContext.Create(typeof(SecurableObject), "owner", "group", "tenant", new Dictionary <string, Enum>(), new Enum[0]);

            _invalidationToken = InvalidationToken.Create();
            _strategy          = ObjectSecurityStrategy.Create(new SerializableSecurityContextFactory(_context), _invalidationToken);
        }
コード例 #3
0
        public void Equals_WithStatefulAndStateless()
        {
            SecurityContext left  = SecurityContext.CreateStateless(typeof(File));
            SecurityContext right = SecurityContext.Create(typeof(File), null, null, null, new Dictionary <string, Enum>(), new Enum[0]);

            Assert.That(left.Equals(right), Is.False);
            Assert.That(right.Equals(left), Is.False);
        }
コード例 #4
0
        private SecurityContext CreateContextForSpecialOrder(OrderState orderState, PaymentState paymentState)
        {
            var states = new Dictionary <string, Enum>();

            states.Add("State", orderState);
            states.Add("Payment", paymentState);

            return(SecurityContext.Create(typeof(SpecialOrder), "owner", "ownerGroup", "ownerTenant", states, new Enum[0]));
        }
コード例 #5
0
        public void Equals_WithDifferentClasses()
        {
            SecurityContext left  = SecurityContext.Create(typeof(File), "owner", "ownerGroup", "ownerTenant", CreateTwoStates(), CreateTwoAbstractRoles());
            SecurityContext right = SecurityContext.Create(
                typeof(PaperFile), "owner", "ownerGroup", "ownerTenant", CreateTwoStates(), CreateTwoAbstractRoles());

            Assert.That(left.Equals(right), Is.False);
            Assert.That(right.Equals(left), Is.False);
        }
コード例 #6
0
 private SecurityContext CreateContextForCustomer()
 {
     return(SecurityContext.Create(
                typeof(Customer),
                "owner",
                "ownerGroup",
                "ownerTenant",
                new Dictionary <string, Enum>(),
                new Enum[0]));
 }
コード例 #7
0
        public void Equals_WithDifferentAbstractRoles()
        {
            SecurityContext left = SecurityContext.Create(typeof(File), "owner", "ownerGroup", "ownerTenant", CreateTwoStates(), CreateTwoAbstractRoles());

            Enum[]          rightAbstractRoles = new Enum[] { TestAbstractRoles.QualityEngineer, TestAbstractRoles.Manager };
            SecurityContext right = SecurityContext.Create(typeof(File), "owner", "ownerGroup", "ownerTenant", CreateTwoStates(), rightAbstractRoles);

            Assert.That(left.Equals(right), Is.False);
            Assert.That(right.Equals(left), Is.False);
        }
コード例 #8
0
        private async ValueTask <IStateMachineController> StartStateMachineWrapper(SessionId sessionId, StateMachineOrigin origin, DataModelValue parameters)
        {
            var finalizer       = new DeferredFinalizer();
            var securityContext = SecurityContext.Create(SecurityContextType.NewTrustedStateMachine, finalizer);

            await using (finalizer.ConfigureAwait(false))
            {
                return(await StartStateMachine(sessionId, origin, parameters, securityContext, finalizer).ConfigureAwait(false));
            }
        }
コード例 #9
0
        public void Equals_WithDifferentStatePropertyLength()
        {
            SecurityContext left = SecurityContext.Create(typeof(File), "owner", "ownerGroup", "ownerTenant", CreateTwoStates(), CreateTwoAbstractRoles());

            Dictionary <string, Enum> rightStates = new Dictionary <string, Enum>();

            rightStates.Add("Confidentiality", TestSecurityState.Public);
            SecurityContext right = SecurityContext.Create(typeof(File), "owner", "ownerGroup", "ownerTenant", rightStates, CreateTwoAbstractRoles());

            Assert.That(left.Equals(right), Is.False);
            Assert.That(right.Equals(left), Is.False);
        }
        public void SetUp()
        {
            _securityProviderMock       = MockRepository.GenerateStrictMock <ISecurityProvider>();
            _securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory>();

            _principalStub = MockRepository.GenerateStub <ISecurityPrincipal>();
            _principalStub.Stub(_ => _.User).Return("user");
            _context = SecurityContext.Create(typeof(SecurableObject), "owner", "group", "tenant", new Dictionary <string, Enum>(), new Enum[0]);
            _securityContextFactoryStub.Stub(_ => _.CreateSecurityContext()).Return(_context);

            _invalidationToken = InvalidationToken.Create();
            _strategy          = ObjectSecurityStrategy.Create(_securityContextFactoryStub, _invalidationToken);
        }
コード例 #11
0
 ISecurityContext ISecurityContextFactory.CreateSecurityContext()
 {
     if (_securityContext == null)
     {
         _securityContext = SecurityContext.Create(
             ((ISecurableObject)this).GetSecurableType(),
             null,
             null,
             null,
             new Dictionary <string, EnumWrapper>(),
             new EnumWrapper[0]);
     }
     return(_securityContext);
 }
コード例 #12
0
        public void Find_WithUnknownStatePropertyInContext_ReturnsNull()
        {
            StubClassDefinition <Customer>();

            var states = new Dictionary <string, Enum>();

            states.Add("Unknown", Delivery.Post);
            var context = SecurityContext.Create(typeof(Customer), "owner", "ownerGroup", "ownerTenant", states, new Enum[0]);

            var aclFinder = CreateAccessControlListFinder();
            var foundAcl  = aclFinder.Find(context);

            Assert.That(foundAcl, Is.Null);
        }
コード例 #13
0
        public void Serialization()
        {
            Dictionary <string, Enum> myStates = new Dictionary <string, Enum>();

            myStates.Add("State", TestSecurityState.Public);
            myStates.Add("Confidentiality", TestSecurityState.Public);

            Enum[] myRoles = new Enum[] { TestAbstractRoles.Developer, TestAbstractRoles.QualityEngineer };

            SecurityContext context             = SecurityContext.Create(typeof(SecurableObject), "myOwner", "myGroup", "myTenant", myStates, myRoles);
            SecurityContext deserializedContext = Serializer.SerializeAndDeserialize(context);

            Assert.That(deserializedContext, Is.Not.SameAs(context));
            Assert.That(deserializedContext, Is.EqualTo(context));
        }
コード例 #14
0
 ISecurityContext ISecurityContextFactory.CreateSecurityContext()
 {
     if (_securityContext == null)
     {
         _securityContext =
             SecurityContext.Create(
                 GetPublicDomainObjectType(),
                 null,
                 null,
                 ClassForRelationTestMandatory.Name.Substring(0, ClassForRelationTestMandatory.Name.Length - 1),
                 new Dictionary <string, EnumWrapper>(),
                 new EnumWrapper[0]);
     }
     return(_securityContext);
 }
コード例 #15
0
        protected void EvaluateSecurity_Click(object sender, EventArgs e)
        {
            ISecurityProvider provider = SafeServiceLocator.Current.GetInstance <ISecurityProvider>();
            SecurityContext   context  =
                SecurityContext.Create(
                    typeof(File),
                    "1A",
                    "{00000004-1000-0000-0000-000000000007}",
                    string.Empty,
                    new Dictionary <string, Enum>(),
                    new Enum[] { DomainAbstractRoles.Creator });
            ISecurityPrincipal user = new SecurityPrincipal("1A", null, null, null);

            AccessType[] accessTypes = provider.GetAccess(context, user);
        }
コード例 #16
0
        private void SetupResultSecurityProviderGetAccessForPosition(Delegation delegation, ISecurityPrincipal principal, params Enum[] returnedAccessTypeEnums)
        {
            Type   classType    = typeof(Position);
            string owner        = string.Empty;
            string owningGroup  = string.Empty;
            string owningTenant = string.Empty;
            Dictionary <string, Enum> states = new Dictionary <string, Enum>();

            states.Add("Delegation", delegation);
            List <Enum>     abstractRoles   = new List <Enum>();
            SecurityContext securityContext = SecurityContext.Create(classType, owner, owningGroup, owningTenant, states, abstractRoles);

            AccessType[] returnedAccessTypes = Array.ConvertAll(returnedAccessTypeEnums, AccessType.Get);

            SetupResult.For(_mockSecurityProvider.GetAccess(securityContext, principal)).Return(returnedAccessTypes);
        }
コード例 #17
0
        public void TestGetHashCode()
        {
            Dictionary <string, Enum> leftStates = new Dictionary <string, Enum>();

            leftStates.Add("State", TestSecurityState.Public);
            leftStates.Add("Confidentiality", TestSecurityState.Public);
            Enum[]          leftAbstractRoles = new Enum[] { TestAbstractRoles.Developer, TestAbstractRoles.QualityEngineer };
            SecurityContext left = SecurityContext.Create(typeof(File), "owner", "ownerGroup", "ownerTenant", leftStates, leftAbstractRoles);

            Dictionary <string, Enum> rightStates = new Dictionary <string, Enum>();

            rightStates.Add("Confidentiality", TestSecurityState.Public);
            rightStates.Add("State", TestSecurityState.Public);
            Enum[]          rightAbstractRoles = new Enum[] { TestAbstractRoles.QualityEngineer, TestAbstractRoles.Developer };
            SecurityContext right = SecurityContext.Create(typeof(File), "owner", "ownerGroup", "ownerTenant", rightStates, rightAbstractRoles);

            Assert.That(right.GetHashCode(), Is.EqualTo(left.GetHashCode()));
        }
コード例 #18
0
        public void Find_WithInvalidStateValueInContext_ThrowsAccessControlException()
        {
            var acl = CreateStatefulAcl(OrderState_Delivered, PaymentState_None);

            StubClassDefinition <Order> (acl);

            var states = new Dictionary <string, Enum>();

            states.Add("State", Delivery.Post);
            states.Add("Payment", PaymentState.None);
            var context = SecurityContext.Create(typeof(Order), "owner", "ownerGroup", "ownerTenant", states, new Enum[0]);

            var aclFinder = CreateAccessControlListFinder();

            Assert.That(
                () => aclFinder.Find(context),
                Throws.TypeOf <AccessControlException>()
                .And.Message.EqualTo(
                    "The state 'Post|Remotion.SecurityManager.UnitTests.TestDomain.Delivery, Remotion.SecurityManager.UnitTests' is not defined "
                    + "for the property 'State' of the securable class 'Remotion.SecurityManager.UnitTests.TestDomain.Order, Remotion.SecurityManager.UnitTests' "
                    + "or its base classes."));
        }
コード例 #19
0
        public void CreateSecurityContextFromEnumWrappers()
        {
            var abstractRoles = new[] { EnumWrapper.Get(TestAbstractRoles.QualityEngineer), EnumWrapper.Get(SimpleEnum.Second), EnumWrapper.Get("Role") };
            var states        = new Dictionary <string, EnumWrapper>();

            states.Add("property1", EnumWrapper.Get(TestSecurityState.Confidential));
            states.Add("property2", EnumWrapper.Get(SimpleEnum.First));
            states.Add("property3", EnumWrapper.Get("State"));

            SecurityContext context = SecurityContext.Create(typeof(ISecurableObject), "owner", "group", "tenant", states, abstractRoles);

            Assert.That(context.Owner, Is.EqualTo("owner"));
            Assert.That(context.OwnerGroup, Is.EqualTo("group"));
            Assert.That(context.OwnerTenant, Is.EqualTo("tenant"));

            Assert.That(context.AbstractRoles, Is.Not.SameAs(abstractRoles));
            Assert.That(context.AbstractRoles, Is.EquivalentTo(abstractRoles));

            Assert.That(context.GetNumberOfStates(), Is.EqualTo(3));
            Assert.That(context.GetState("property1"), Is.EqualTo(states["property1"]));
            Assert.That(context.GetState("property2"), Is.EqualTo(states["property2"]));
            Assert.That(context.GetState("property3"), Is.EqualTo(states["property3"]));
        }
コード例 #20
0
 public ISecurityContext CreateSecurityContext()
 {
     return(SecurityContext.Create(GetPublicDomainObjectType(), GetOwnerName(), GetOwnerGroupName(), GetOwnerTenantName(), GetStates(), GetAbstractRoles()));
 }
コード例 #21
0
 private SecurityContext CreateContextWithNotExistingOwningUser()
 {
     return(SecurityContext.Create(
                typeof(Order), "notExistingUser", "UID: testOwningGroup", "UID: testTenant", new Dictionary <string, Enum>(), new Enum[0]));
 }
コード例 #22
0
 private SecurityContext CreateContextWithoutOwningGroup()
 {
     return(SecurityContext.Create(typeof(Order), "group0/user1", null, "UID: testTenant", new Dictionary <string, Enum>(), new Enum[0]));
 }
コード例 #23
0
 private SecurityContext CreateContext(params Enum[] abstractRoles)
 {
     return(SecurityContext.Create(
                typeof(Order), "group0/user1", "UID: testOwningGroup", "UID: testTenant", new Dictionary <string, Enum>(), abstractRoles));
 }
コード例 #24
0
ファイル: XIncludeTest.cs プロジェクト: TSSArt/Xtate.Core
 public async Task DtdReaderTest()
 {
     var uri             = new Uri("res://Xtate.Core.Test/Xtate.Core.Test/Scxml/XInclude/DtdSingleIncludeSource.scxml");
     var securityContext = SecurityContext.Create(SecurityContextType.NewStateMachine, new DeferredFinalizer());
     var factoryContext  = new FactoryContext(ImmutableArray.Create(ResxResourceLoaderFactory.Instance), securityContext, logger: default, loggerContext: default);
コード例 #25
0
 private SecurityContext CreateTestSecurityContext(Type type, IDictionary <string, Enum> states, ICollection <Enum> abstractRoles)
 {
     return(SecurityContext.Create(type, "owner", "group", "tenant", states, abstractRoles));
 }