I am well aware of role based / activity based authorization in the context of limiting user functionality in a simple on/off manner; however, the problem gets difficult when it's not so black and white.
Take for example:
User A: Is a paid customer of a market data service and has unlimited requests
User B: Is free tier with a maximum of 1000 requests per month
Both users use the same endpoint /api/ticker/AMD?someParam=123
If business rules stated free users could not get market data then it would be as simple as using some declarative style authorization filters to block a call from ever occurring.
[Authorize(Roles = "Paid")]
[HttpGet("ticker/{symb}"]
public IActionResult GetMarketData(string someParam)
It would be fairly easy to implement specific domain logic in the code that needs to be restricted on a case by case basis but that would lead to lots of redundancy.
The only things I can think of right now are:
- Implementing some type of middleware that is injected in the HttpRequest pipeline and contains a factory that would check which endpoint is being called and thus run specific code to limit requests, or limit data output, or any other business rule.
- Move to an actor based pattern (such as akka.net) where actors can easily be added within a specific domain flow (but this won't work with simple synchronous GET requests)
I like approach 2; however, as state in parenthesis, this will not work with simple reads. Through my research it seems akka excels at more of a process based workload.
Approach 1 seems a bit cluttered. It also somewhat seems to mix domain knowledge with technical details.
Are there any well known patterns out there for limiting application functionality in a more conditional format rather than just flat out limiting functionality completely based on roles or activities?