示例#1
0
        /// <summary>
        /// All <see cref="UserAccount"/>s in the <see cref="Role"/> with the name
        /// <paramref name="roleName"/>.
        /// </summary>
        /// <param name="roleName">
        /// The role name. This cannot be null, empty or whitespace.
        /// </param>
        /// <returns>
        /// The query.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="roleName"/> cannot be null, empty or whitespace.
        /// </exception>
        public static StructuredQuery ActiveUsersInRole(string roleName)
        {
            ResourceEntity  rootEntity;
            ResourceEntity  relatedRoleEntity;
            ResourceEntity  activeStatusEntity;
            StructuredQuery structuredQuery;

            activeStatusEntity = new RelatedResource(new EntityRef("core:accountStatus"))
            {
                NodeId = Guid.NewGuid()
            };
            relatedRoleEntity = new RelatedResource(new EntityRef("core:userHasRole"))
            {
                NodeId    = Guid.NewGuid(),
                Recursive = RecursionMode.RecursiveWithSelf
            };
            rootEntity = new ResourceEntity
            {
                EntityTypeId    = Entity.GetId("core:userAccount"),
                ExactType       = false,
                NodeId          = Guid.NewGuid(),
                RelatedEntities = new List <ReadiNow.Metadata.Query.Structured.Entity>()
                {
                    relatedRoleEntity,
                    activeStatusEntity
                }
            };

            structuredQuery = new StructuredQuery
            {
                RootEntity    = rootEntity,
                SelectColumns = new List <SelectColumn>()
            };
            structuredQuery.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(relatedRoleEntity, new EntityRef("core:name")),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue(roleName),
            });
            structuredQuery.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(activeStatusEntity, new EntityRef("core:alias")),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue("active"),
            });
            structuredQuery.SelectColumns.Add(new SelectColumn
            {
                Expression = new IdExpression()
                {
                    NodeId = rootEntity.NodeId
                }
            });

            return(structuredQuery);
        }
示例#2
0
        /// <summary>
        /// All <see cref="EntityType"/>s that have access rules/security queries
        /// from <see cref="Subject"/>s with the name <see cref="subjectName"/>.
        /// </summary>
        /// <param name="subjectName">
        /// The role name. This cannot be null, empty or whitespace.
        /// </param>
        /// <returns>
        /// The query.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="subjectName"/> cannot be null, empty or whitespace.
        /// </exception>
        public static StructuredQuery TypesSecuredBySubjects(string subjectName)
        {
            ResourceEntity  rootEntity;
            ResourceEntity  allowAccessEntity;
            ResourceEntity  controlAccessEntity;
            StructuredQuery structuredQuery;

            allowAccessEntity = new RelatedResource(new EntityRef("core:allowAccess"), RelationshipDirection.Reverse)
            {
                NodeId = Guid.NewGuid()
            };
            controlAccessEntity = new RelatedResource(new EntityRef("core:controlAccess"), RelationshipDirection.Reverse)
            {
                NodeId          = Guid.NewGuid(),
                RelatedEntities = new List <ReadiNow.Metadata.Query.Structured.Entity>()
                {
                    allowAccessEntity
                }
            };
            rootEntity = new ResourceEntity
            {
                EntityTypeId    = Entity.GetId("core:type"),
                ExactType       = false,
                NodeId          = Guid.NewGuid(),
                RelatedEntities = new List <ReadiNow.Metadata.Query.Structured.Entity>()
                {
                    controlAccessEntity
                }
            };

            structuredQuery = new StructuredQuery
            {
                RootEntity    = rootEntity,
                SelectColumns = new List <SelectColumn>()
            };
            structuredQuery.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(allowAccessEntity, new EntityRef("core:name")),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue(subjectName),
            });
            structuredQuery.SelectColumns.Add(new SelectColumn
            {
                Expression = new IdExpression()
                {
                    NodeId = rootEntity.NodeId
                }
            });
            structuredQuery.SelectColumns.Add(new SelectColumn
            {
                Expression = new ResourceDataColumn(rootEntity, new EntityRef("core:name"))
            });

            return(structuredQuery);
        }
示例#3
0
        /// <summary>
        /// Find all enabled <see cref="AccessRule"/> entities related to the
        /// <see cref="Permission"/> named <paramref name="name"/>.
        /// </summary>
        /// <param name="name">
        /// The name to check. This cannot be null, empty or whitespace.
        /// </param>
        /// <returns>
        /// The query.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="name"/> cannot be null, empty or whitespace.
        /// </exception>
        public static StructuredQuery AccessRulesWithNamedPermission(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            ResourceEntity  rootEntity;
            ResourceEntity  relatedPermissionEntity;
            StructuredQuery structuredQuery;

            relatedPermissionEntity = new RelatedResource(new EntityRef("core:permissionAccess"))
            {
                NodeId = Guid.NewGuid()
            };
            rootEntity = new ResourceEntity
            {
                EntityTypeId    = Entity.GetId("core:accessRule"),
                ExactType       = false,
                NodeId          = Guid.NewGuid(),
                RelatedEntities = new List <ReadiNow.Metadata.Query.Structured.Entity>()
                {
                    relatedPermissionEntity
                }
            };

            structuredQuery = new StructuredQuery
            {
                RootEntity    = rootEntity,
                SelectColumns = new List <SelectColumn>()
            };
            structuredQuery.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(relatedPermissionEntity, new EntityRef("core:name")),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue(name),
            });
            structuredQuery.Conditions.Add(new QueryCondition
            {
                Expression = new ResourceDataColumn(rootEntity, new EntityRef("core:accessRuleEnabled")),
                Operator   = ConditionType.Equal,
                Argument   = new TypedValue(1),
            });
            structuredQuery.SelectColumns.Add(new SelectColumn
            {
                Expression = new IdExpression()
                {
                    NodeId = rootEntity.NodeId
                }
            });

            return(structuredQuery);
        }