Adding permissions to AutoQuery data stored in Redis

New to ServiceStack,

I have an issue where a couple of datasets are added via the AutoQueryDataFeature and I want to add ActiveDirectory authorization on them.

I see that for endpoints that inherit from Service its as easy as decorating the functions with [RequiresAnyRole] but I can’t figure out how to do the same with the Search and Suggest endpoints that are not implemented the same way. I am assuming that the Search and Suggest endpoints are built into ServiceStack.

Any help is appreciated.

Thanks!

You can either create a Custom AutoQuery Implementation where you can then annotate it the same as your other protected services, e.g:

[RequiredRole("TheRole")]
public class MyServices : Service
{
    public IAutoQueryDb AutoQuery { get; set; }

    public object Any(FindMovies query)
    {
        using var db = AutoQuery.GetDb(query, base.Request);
        var q = AutoQuery.CreateQuery(query, base.Request, db);
        return AutoQuery.Execute(query, q, base.Request, db);
    }
}

Or you can enable Declarative Validation and annotate the AutoQuery Request DTOs with Auth Type Validators, e.g:

[ValidateHasRole("TheRole")]
public class FindMovies : QueryDb<Movie> {}

The data is available as a AutoQueryDataFeature which is defined in Global.asax.cs and is stored in Redis, AutoQuery.GetDb will not work in this case, do I have another option?

AutoQuery RDBMS and AutoQuery Data are completely different implementations with different dependencies, i.e. AutoQuery Data uses IAutoQueryData, here’s an example of a Custom AutoQuery Data Implementation.

Think we are getting closer and thanks for the quick reply

Looked at the example but how can I access the data from Redis when using AutoQuery.CreateQuery?

From the example it looks like it puts data from a log into memory and then queries it.

I think what I am looking for is something like a RedisDataSource that implements QueryDataSource

AutoQuery Data works completely different to AutoQuery RDBMS, e.g. you’d need to configure the Data Sources yourself when using either a Memory Data Source or a Service Data Source.

The only external AutoQuery Data provider supported is AutoQuery DynamoDB, Redis doesn’t support querying data, best you can do is query the Snapshot of data in memory, both AutoQuery Memory Data and AutoQuery Service Data show querying a custom in-memory resultset.

Thank you, working now!

1 Like