Beispiel #1
0
 public Permission(long id, IClass @class, IOperandType operandType, Operations operation)
 {
     this.Id          = id;
     this.Class       = @class;
     this.OperandType = operandType;
     this.Operation   = operation;
 }
Beispiel #2
0
        public bool IsPermitted(IOperandType operandType, Operations operation)
        {
            this.LazyLoad();

            if (this.deniedPermissions.Length > 0)
            {
                if (this.deniedPermissions.Any(deniedPermission => deniedPermission.OperandTypePointer.Equals(operandType.Id) && deniedPermission.Operation.Equals(operation)))
                {
                    return(false);
                }
            }

            if (this.PermissionIdByOperationByOperandTypeId.TryGetValue(operandType.Id, out var permissionIdByOperation))
            {
                if (permissionIdByOperation.TryGetValue(operation, out var permissionId))
                {
                    return(this.permissionIds.Contains(permissionId));
                }
            }

            return(false);
        }
Beispiel #3
0
        public Permission GetPermission(IClass @class, IOperandType roleType, Operations operation)
        {
            switch (operation)
            {
            case Operations.Read:
                if (this.readPermissionByOperandTypeByClass.TryGetValue(@class, out var readPermissionByOperandType))
                {
                    if (readPermissionByOperandType.TryGetValue(roleType, out var readPermission))
                    {
                        return(readPermission);
                    }
                }

                return(null);

            case Operations.Write:
                if (this.writePermissionByOperandTypeByClass.TryGetValue(@class, out var writePermissionByOperandType))
                {
                    if (writePermissionByOperandType.TryGetValue(roleType, out var writePermission))
                    {
                        return(writePermission);
                    }
                }

                return(null);

            default:
                if (this.executePermissionByOperandTypeByClass.TryGetValue(@class, out var executePermissionByOperandType))
                {
                    if (executePermissionByOperandType.TryGetValue(roleType, out var executePermission))
                    {
                        return(executePermission);
                    }
                }

                return(null);
            }
        }
        public bool IsPermitted(IOperandType operandType, Operations operation)
        {
            if (this.Object == null)
            {
                return(operation == Operations.Read);
            }

            this.LazyLoad();

            if (this.permissionIdByOperationByOperandTypeId.TryGetValue(operandType.Id, out var permissionIdByOperation))
            {
                if (permissionIdByOperation.TryGetValue(operation, out var permissionId))
                {
                    if (this.deniedPermissions?.Contains(permissionId) == true)
                    {
                        return(false);
                    }

                    return(this.accessControls.Any(v => this.AccessControlLists.EffectivePermissionIdsByAccessControl[v].Contains(permissionId)));
                }
            }

            return(false);
        }
Beispiel #5
0
        public void Grant(Guid roleId, ObjectType objectType, IOperandType operandType, params Operations[] operations)
        {
            if (this.roleById.TryGetValue(roleId, out var role))
            {
                var actualOperations = operations ?? ReadWriteExecute;
                foreach (var operation in actualOperations)
                {
                    Dictionary <IOperandType, Permission> permissionByOperandType;
                    switch (operation)
                    {
                    case Operations.Read:
                        this.readPermissionsByObjectTypeId.TryGetValue(objectType.Id, out permissionByOperandType);
                        break;

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

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

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

                    if (permissionByOperandType != null)
                    {
                        if (permissionByOperandType.TryGetValue(operandType, out var permission))
                        {
                            role.AddPermission(permission);
                        }
                    }
                }
            }
        }
Beispiel #6
0
 public void GrantSales(ObjectType objectType, IOperandType operandType, params Operations[] operations) => this.Grant(Roles.SalesId, objectType, operandType, operations);
Beispiel #7
0
 public void GrantProcurement(ObjectType objectType, IOperandType operandType, params Operations[] operations) => this.Grant(Roles.ProcurementId, objectType, operandType, operations);
Beispiel #8
0
        public TypeReferenceCount GetBodyReferences()
        {
            var types = new TypeReferenceCount();

            if (method.HasBody && method.Body != null)
            {
                foreach (var variable in GetMethodBodyVariables(method))
                {
                    types.Add(variable);
                }

                foreach (var instruction in method.Body.Instructions)
                {
                    var operand = instruction.Operand;
                    if (operand != null)
                    {
                        var operandProcessors = new IOperandType[]
                        {
                            new MemberReferenceType(operand),
                            new ParameterDefinitionType(operand),
                            new VariableDefinitionType(operand),
                            new PrimitiveType(operand), 
                        };

                        foreach (var operandProcessor in operandProcessors)
                        {
                            var type = operandProcessor.GetOperandType();
                            if (type != null)
                            {
                                types.Add(type);
                                break;
                            }
                        }
                    }
                }
            }

            return types;
        }