0

I need to run some code which checks the user's subscription during certain service calls, so I figured something like an AOP approach would be nice.

The call should determine whether the method should proceed or to return an error message.

How can this be done within the ServiceStack framework?

vonec
  • 681
  • 10
  • 22

2 Answers2

1

Depending on what you mean by the user's subscription the built in Authentication and Roles might be suitable for what you need.

There's a lot of information in the wiki and also in this answer but essentially you can add attributes to classes to prevent access in cases where users don't have the specified role:

[Authenticate]
//All HTTP (GET, POST...) methods need "CanAccess"
[RequiredRole("Admin")]
[RequiredPermission("CanAccess")]
public class Secured
{
    public bool Test { get; set; }
} 
Community
  • 1
  • 1
RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41
  • It's a little more than just access roles, because they could have the correct role, but depending on the action, they may be denied. E.g. the user is subscribed to have 10 users, but we want to make sure that when they create an 11th user the service returns an error message. So rather than having this logic everywhere in the various services that would affect the number of users, it would be nice be able to specify which services should check for this. – vonec May 05 '15 at 06:06
0

You can look at how AutoQuery dynamically generates Services for how to use code-gen to dynamically generate Service implementations.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390