WCF Data Service: Intercepting all queries

435 views Asked by At

I've been trying to secure my WCF data service by developing a customized per-session authentication mechanism that identifies the client based on multiple criteria. Then I wanna intercept all queries and non-query request based on the result of this authentication. Interception of queries is no problem, but since I may have a lot of tables, I've been looking for a way to intercept all queries all in the same place.

For example instead of

[QueryInterceptor("Entities")]
public Expression<Func<Entity, Boolean> FilterEntities(){
    return x=> IsAuthenticated;
}

doing

[QueryInterceptor("*")]
public Expression<Func<T, Boolean> FilterEntities<T>(){
    return x=> IsAuthenticated;
} // As a logical description only, of course it won't work as it is

So is there any way to filter all query and non-query requests in WCF data service at all?

1

There are 1 answers

0
Karata On

Looks like it is not achievable for now by using QueryInterceptor, and you would have to add each entity set name manually: https://github.com/OData/odata.net/blob/ODATAV3/WCFDataService/Service/System/Data/Services/DataServiceStaticConfiguration.cs#L188

But you can refer to this blog series for doing auth in WCF Data Service. http://blogs.msdn.com/b/odatateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx