Esempio n. 1
0
        public void Create()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var dbFixtures = new DatabaseFixtures();
                var tenant     = dbFixtures.CreateAndCommitOrganizationalStructureWithTwoTenants(ClientTransaction.Current);
                var user       = User.FindByTenant(tenant.GetHandle()).First();

                var factory = new SecurityManagerPrincipalFactory();

                var principal = factory.Create(tenant.GetHandle(), user.GetHandle(), null);

                Assert.That(principal, Is.TypeOf <SecurityManagerPrincipal>());
                Assert.That(principal.Tenant.ID, Is.EqualTo(tenant.ID));
                Assert.That(principal.User.ID, Is.EqualTo(user.ID));
                Assert.That(principal.Substitution, Is.Null);
            }
        }
Esempio n. 2
0
        private ISecurityManagerPrincipal GetSecurityManagerPrincipalByUserName(IPrincipal principal)
        {
            if (!principal.Identity.IsAuthenticated)
            {
                return(SecurityManagerPrincipal.Null);
            }

            using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope())
            {
                using (SecurityFreeSection.Activate())
                {
                    var user = SecurityManagerUser.FindByUserName(principal.Identity.Name);
                    if (user == null)
                    {
                        return(SecurityManagerPrincipal.Null);
                    }
                    else
                    {
                        return(SecurityManagerPrincipalFactory.Create(user.Tenant.GetHandle(), user.GetHandle(), null));
                    }
                }
            }
        }