Question

Is it possible to make a custom QueryInterceptor in a WCF Data Service on all entites instead of only one? This is a standard QueryInterceptor:

[QueryInterceptor("Products")]
public Expression<Func<Product, bool>> OnQueryProducts()
{
    var user = HttpContext.Current.User;
    if (user.IsInRole("Administrator"))
        return (Product p) => true;
    else
        return (Product p) => false;
}

I like to do something like this:

[QueryInterceptor("*")]
public Expression<Func<Object, bool>> OnQueryProducts()
{
    var user = HttpContext.Current.User;
    if (user.IsInRole("Administrator"))
        return (Object p) => true;
    else
        return (Object p) => false;
}

Is there any way or do I have to integrate one inceptor for all of my entities?

Was it helpful?

Solution

Unfortunately you can't use a wild card with the QueryInterceptor however you can achieve the same result as in your example by overriding the OnStartProcessingRequest method of the DataService and checking the role of the user there.

protected override void OnStartProcessingRequest(ProcessRequestArgs args)
{
    var user = HttpContext.Current.User;

    // Only Administrator users are allowed access
    if (!user.IsInRole("Administrator"))
    {
        // Any other role throws a security exception
        throw new SecurityException("You do not have permission to access this Service");
    }

    base.OnStartProcessingRequest(args);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top