Exemplo n.º 1
0
 private void Inspect()
 {
     if (authorizer != null && !authorizer.Authorize(context))
     {
         throw new SecurityException("The current user does not have permission to query from the requested resource.");
     }
 }
Exemplo n.º 2
0
            private void Inspect()
            {
                if (authorizer == null)
                {
                    authorizer = context.QueryContext.GetApiService <IQueryExpressionAuthorizer>();
                }

                if (authorizer != null && !authorizer.Authorize(context))
                {
                    throw new SecurityException("The current user does not have permission to query from the requested resource.");
                }
            }
Exemplo n.º 3
0
            private void Inspect()
            {
                if (authorizer == null)
                {
                    authorizer = context.QueryContext.GetApiService <IQueryExpressionAuthorizer>();
                }

                if (authorizer != null && !authorizer.Authorize(context))
                {
                    throw new InvalidOperationException(Resources.InspectionFailed);
                }
            }
Exemplo n.º 4
0
            public override Expression Visit(Expression node)
            {
                if (node == null)
                {
                    return(null);
                }

                // Initialize and push the visited node
                var visited = node;

                context.PushVisitedNode(visited);

                // If visited node has already been processed,
                // skip normalization, inspection and filtering
                // and simply replace with the processed node
                if (processedExpressions.ContainsKey(visited))
                {
                    node = processedExpressions[visited];
                }
                else
                {
                    // Only visit the visited node's children if
                    // the visited node represents API data
                    if (!(context.ModelReference is DataSourceStubModelReference))
                    {
                        // Visit visited node's children
                        node = base.Visit(visited);
                    }

                    // Inspect the visited node
                    //Inspect();

                    if (authorizer != null && !authorizer.Authorize(context))
                    {
                        return(null);
                        // throw new SecurityException("The current user does not have permission to query from the requested resource.");
                    }

                    // Try to expand the visited node
                    // if it represents API data
                    if (context.ModelReference is DataSourceStubModelReference)
                    {
                        node = Expand(visited);
                    }

                    // Process the visited node
                    node = Process(visited, node);
                }

                if (visited == node)
                {
                    if (context.ModelReference is DataSourceStubModelReference)
                    {
                        // If no processing occurred on the visited node
                        // and it represents API data, then it must be
                        // in its most primitive form, so source the node
                        node = Source(node);
                    }

                    if (BaseQuery == null)
                    {
                        // The very first time control reaches here, the
                        // visited node represents the original starting
                        // point for the entire composed query, and thus
                        // it should produce a non-embedded expression.
                        if (!(node is ConstantExpression constant))
                        {
                            throw new NotSupportedException(Resources.OriginalExpressionShouldBeConstant);
                        }

                        BaseQuery = constant.Value as IQueryable;
                        if (BaseQuery == null)
                        {
                            throw new NotSupportedException(Resources.OriginalExpressionShouldBeQueryable);
                        }

                        node = BaseQuery.Expression;
                    }
                }

                // TODO GitHubIssue#28 : Support transformation between API types and data source proxy types
                context.PopVisitedNode();

                if (context.VisitedNode != null)
                {
                    EntitySet = context.ModelReference != null ?
                                context.ModelReference.EntitySet : null;
                }

                return(node);
            }