예제 #1
0
        public void GetAccess_ReturnsAccessTypes()
        {
            AccessType[] expectedAccessTypes = new AccessType[1];

            SecurityToken token = SecurityToken.Create(
                PrincipalTestHelper.Create(_tenant, null, new Role[0]),
                null,
                null,
                null,
                Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >());

            var aclHandle = CreateAccessControlListHandle();

            Expect.Call(_mockAclFinder.Find(_context)).Return(aclHandle);
            Expect.Call(_mockTokenBuilder.CreateToken(_principalStub, _context)).Return(token);
            Expect.Call(_mockAccessResolver.GetAccessTypes(aclHandle, token)).Return(expectedAccessTypes);
            _mocks.ReplayAll();

            AccessType[] actualAccessTypes = _service.GetAccess(_context, _principalStub);

            Assert.That(actualAccessTypes, Is.SameAs(expectedAccessTypes));
        }
예제 #2
0
        public AccessType[] GetAccess(ISecurityContext context, ISecurityPrincipal principal)
        {
            ArgumentUtility.CheckNotNull("context", context);
            ArgumentUtility.CheckNotNull("principal", principal);

            using (SecurityFreeSection.Activate())
            {
                IDomainObjectHandle <AccessControlList> acl;
                SecurityToken token;
                try
                {
                    acl   = _accessControlListFinder.Find(context);
                    token = _securityTokenBuilder.CreateToken(principal, context);
                }
                catch (AccessControlException e)
                {
                    s_log.Error("Error during evaluation of security query.", e);
                    return(new AccessType[0]);
                }

                if (acl == null)
                {
                    return(new AccessType[0]);
                }

                try
                {
                    return(_accessResolver.GetAccessTypes(acl, token));
                }
                catch (ObjectsNotFoundException e)
                {
                    s_log.Error("Error during evaluation of security query.", e);
                    return(new AccessType[0]);
                }
            }
        }