示例#1
0
文件: Test.cs 项目: whesius/allors
        public RoleType[] GetBooleanRoles(ObjectType type)
        {
            var roleList = new ArrayList();
            foreach (var metaRole in type.RoleTypes)
            {
                if (metaRole.ObjectType.IsBoolean)
                {
                    roleList.Add(metaRole);
                }
            }

            return (RoleType[])roleList.ToArray(typeof(RoleType));
        }
示例#2
0
        public void Deny(ObjectType objectType, ObjectState objectState, params Operation[] operations)
        {
            var actualOperations = operations ?? ReadWriteExecute;
            foreach (var operation in actualOperations)
            {
                Dictionary<OperandType, Permission> permissionByOperandType;
                switch (operation)
                {
                    case Operation.Read:
                        this.readPermissionsByObjectTypeId.TryGetValue(objectType.Id, out permissionByOperandType);
                        break;

                    case Operation.Write:
                        this.writePermissionsByObjectTypeId.TryGetValue(objectType.Id, out permissionByOperandType);
                        break;

                    case Operation.Execute:
                        this.executePermissionsByObjectTypeId.TryGetValue(objectType.Id, out permissionByOperandType);
                        break;

                    default:
                        throw new Exception("Unkown operation: " + operations);
                }

                if (permissionByOperandType != null)
                {
                    foreach (var dictionaryEntry in permissionByOperandType)
                    {
                        objectState.AddDeniedPermission(dictionaryEntry.Value);
                    }
                }
            }
        }
示例#3
0
 public void GrantSales(ObjectType objectType, OperandType operandType, params Operation[] operations)
 {
     this.Grant(Roles.SalesId, objectType, operandType, operations);
 }
示例#4
0
文件: Test.cs 项目: whesius/allors
 public abstract IObject[] CreateArray(ObjectType objectType, int count);
示例#5
0
 /// <summary>
 /// Derive super types recursively.
 /// </summary>
 /// <param name="type">The type .</param>
 /// <param name="superTypes">The super types.</param>
 private void DeriveSupertypesRecursively(ObjectType type, HashSet<Interface> superTypes)
 {
     foreach (var directSupertype in this.derivedDirectSupertypes)
     {
         if (!Equals(directSupertype, type))
         {
             superTypes.Add(directSupertype);
             directSupertype.DeriveSupertypesRecursively(type, superTypes);
         }
     }
 }
示例#6
0
文件: Setup.cs 项目: whesius/allors
 /// <summary>
 /// The dependee is set up before the dependent object;
 /// </summary>
 /// <param name="dependent"></param>
 /// <param name="dependee"></param>
 public void AddDependency(ObjectType dependent, ObjectType dependee)
 {
     this.objectsGraph.AddDependency(this.objectsByObjectType[dependent], this.objectsByObjectType[dependee]);
 }
示例#7
0
 public void GrantOwner(ObjectType objectType, params Operation[] operations)
 {
     this.Grant(Roles.OwnerId, objectType, operations);
 }
示例#8
0
 public void GrantAdministrator(ObjectType objectType, params Operation[] operations)
 {
     this.Grant(Roles.AdministratorId, objectType, operations);
 }
示例#9
0
 internal void Sync(ObjectType concreteClass, OperandType operandType, Operation operation)
 {
     this.OperandType = operandType;
     this.Operation = operation;
     this.ConcreteClassPointer = concreteClass.Id;
 }
示例#10
0
文件: Security.cs 项目: Allors/demo
 public void GrantEmployee(ObjectType objectType, params Operation[] operations)
 {
     this.Grant(Roles.EmployeeId, objectType, operations);
 }
示例#11
0
文件: Security.cs 项目: Allors/demo
 public void GrantAccountant(ObjectType objectType, params Operation[] operations)
 {
     this.Grant(Roles.AccountantId, objectType, operations);
 }
示例#12
0
        private IObject[] CreateRolesWithSameClass(ISession session, RelationType relationType, ObjectType roleClass)
        {
            IObject[] allRoles = this.CreateArray(relationType.RoleType.ObjectType, this.GetRoleCount());
            for (int i = 0; i < allRoles.Length; i++)
            {
                allRoles[i] = session.Create(roleClass);
            }

            return allRoles;
        }
示例#13
0
 private IObject[] CreateRolesWithSameClass(RelationType relationType, ObjectType roleClass)
 {
     return this.CreateRolesWithSameClass(this.GetSession(), relationType, roleClass);
 }
示例#14
0
        private IObject[] CreateAssociationsWithSameClass(RelationType relationType, ObjectType associationClass)
        {
            IObject[] associations = this.CreateArray(relationType.AssociationType.ObjectType, this.GetAssociationCount());
            for (int i = 0; i < this.GetAssociationCount(); i++)
            {
                associations[i] = this.GetSession().Create(associationClass);
            }

            return associations;
        }
示例#15
0
 public void Deny(ObjectType objectType, ObjectState objectState, params OperandType[] operandTypes)
 {
     Dictionary<Guid, Permission> deniablePermissionByOperandTypeId;
     if (this.deniablePermissionByOperandTypeIdByObjectTypeId.TryGetValue(objectType.Id, out deniablePermissionByOperandTypeId))
     {
         foreach (var operandType in operandTypes)
         {
             Permission permission;
             if (deniablePermissionByOperandTypeId.TryGetValue(operandType.Id, out permission))
             {
                 objectState.AddDeniedPermission(permission);
             }
         }
     }
 }
示例#16
0
 public void GrantOperations(ObjectType objectType, params Operations[] operations)
 {
     this.Grant(Roles.OperationsId, objectType, operations);
 }
示例#17
0
        public void Grant(Guid roleId, ObjectType objectType, OperandType operandType, params Operation[] operations)
        {
            Role role;
            if (this.roleById.TryGetValue(roleId, out role))
            {
                var actualOperations = operations ?? ReadWriteExecute;
                foreach (var operation in actualOperations)
                {
                    Dictionary<OperandType, Permission> permissionByOperandType;
                    switch (operation)
                    {
                        case Operation.Read:
                            this.readPermissionsByObjectTypeId.TryGetValue(objectType.Id, out permissionByOperandType);
                            break;

                        case Operation.Write:
                            this.writePermissionsByObjectTypeId.TryGetValue(objectType.Id, out permissionByOperandType);
                            break;

                        case Operation.Execute:
                            this.executePermissionsByObjectTypeId.TryGetValue(objectType.Id, out permissionByOperandType);
                            break;

                        default:
                            throw new Exception("Unkown operation: " + operations);
                    }

                    if (permissionByOperandType != null)
                    {
                        Permission permission;
                        if (permissionByOperandType.TryGetValue(operandType, out permission))
                        {
                            role.AddPermission(permission);
                        }
                    }
                }
            }
        }
示例#18
0
 public void GrantPartner(ObjectType objectType, params Operations[] operations)
 {
     this.Grant(Roles.PartnerRoleId, objectType, operations);
 }
示例#19
0
 public void GrantGuest(ObjectType objectType, params Operation[] operations)
 {
     this.Grant(Roles.GuestId, objectType, operations);
 }
示例#20
0
 public void GrantSupplier(ObjectType objectType, OperandType operandType, params Operations[] operations)
 {
     this.Grant(Roles.SupplierRoleId, objectType, operandType, operations);
 }
示例#21
0
文件: Profile.cs 项目: whesius/allors
 public IObject[] CreateArray(ObjectType objectType, int count)
 {
     var type = this.GetPopulation().DomainAssembly.GetType(objectType.FullNameForCts);
     var allorsObjects = (IObject[])Array.CreateInstance(type, count);
     return allorsObjects;
 }
示例#22
0
 private Permission FindPermission(ObjectType objectType, RoleType roleType, Operation operation)
 {
     Extent<Permission> permissions = this.DatabaseSession.Extent<Permission>();
     permissions.Filter.AddEquals(Permissions.Meta.ConcreteClassPointer, objectType.Id);
     permissions.Filter.AddEquals(Permissions.Meta.OperandTypePointer, roleType.Id);
     permissions.Filter.AddEquals(Permissions.Meta.OperationEnum, operation);
     return permissions.First;
 }
示例#23
0
        public Dictionary<Guid, IList<Operation>> GetOperationsByOperandTypeId(HashSet<Guid> roleUniqueIds, ObjectType objectType, out bool hasWriteOperation, out bool hasReadOperation)
        {
            var resultOperationsByOperandId = new Dictionary<Guid, IList<Operation>>();

            hasWriteOperation = false;
            hasReadOperation = false;

            foreach (var roleUniqueId in roleUniqueIds)
            {
                var roleOperationsByOperandIdByObjectType = this.operationsByOperandTypeIdByObjectTypeIdByRoleId[roleUniqueId];
                Dictionary<Guid, List<Operation>> roleOperationsByOperandObjectId;
                if (roleOperationsByOperandIdByObjectType.TryGetValue(objectType.Id, out roleOperationsByOperandObjectId))
                {
                    foreach (var dictionaryEntry in roleOperationsByOperandObjectId)
                    {
                        var roleOperandTypeId = dictionaryEntry.Key;
                        var roleOperations = dictionaryEntry.Value;

                        IList<Operation> resultOperations;
                        if (!resultOperationsByOperandId.TryGetValue(roleOperandTypeId, out resultOperations))
                        {
                            resultOperations = new List<Operation>();
                            resultOperationsByOperandId[roleOperandTypeId] = resultOperations;
                        }

                        foreach (var roleOperation in roleOperations)
                        {
                            if (!resultOperations.Contains(roleOperation))
                            {
                                if (roleOperation == Operation.Write)
                                {
                                    hasWriteOperation = true;
                                }

                                if (roleOperation == Operation.Read)
                                {
                                    hasReadOperation = true;
                                }

                                resultOperations.Add(roleOperation);
                            }
                        }
                    }
                }
            }

            return resultOperationsByOperandId;
        }
示例#24
0
 public void GrantProcurement(ObjectType objectType, OperandType operandType, params Operation[] operations)
 {
     this.Grant(Roles.ProcurementId, objectType, operandType, operations);
 }
示例#25
0
 public override IObject[] CreateArray(ObjectType objectType, int count)
 {
     return this.profile.CreateArray(objectType, count);
 }
示例#26
0
 /// <summary>
 /// Derive super types recursively.
 /// </summary>
 /// <param name="type">The type .</param>
 /// <param name="subTypes">The super types.</param>
 private void DeriveSubtypesRecursively(ObjectType type, HashSet<Composite> subTypes)
 {
     foreach (var directSubtype in this.derivedDirectSubtypes)
     {
         if (!Equals(directSubtype, type))
         {
             subTypes.Add(directSubtype);
             if (directSubtype is IInterface)
             {
                 ((Interface)directSubtype).DeriveSubtypesRecursively(this, subTypes);
             }
         }
     }
 }