No problem! I am not happy with the current implementation because I cannot pack all information I need into a single string field, I need a complex object. Here is what I would need:
public interface IRole
{
string Name { get; set; }
string Description { get; set; }
string ApplicationId { get; set; } //could also be a int, Guid, but string is more universal
RoleType Type { get; set; }
}
public enum RoleType
{
SystemRole,
StandardRole,
ApplicationRole,
// maybe others.....
}
public class Role : IRole
{
public string Name { get; set; }
public string Description { get; set; }
public string ApplicationId { get; set; }
public RoleType Type { get; set; }
// maybe other props if needed
public Role()
{
Type = RoleType.ApplicationRole;
}
// stuff for Redis only
// hash:IRole:Name>ApplicationId
// hash:IRole:RoleType>RoleType
// hash:IUserAuth:UserName:Role>RoleName
// hash:IRole:Name>IUserAuth:UserName
// also your nice UserNameOrEmail ....
}
And this is an example how I would use it:
public void Dosomething()
{
var adminRole = new Role
{
Name = "Administrator",
Description = "General Administrator role, has no limitations",
ApplicationId = "All",
Type = RoleType.SystemRole
};
var userRole = new Role
{
Name = "User",
Description = "General user role, allowed to perform standard business operations",
ApplicationId = "All",
Type = RoleType.SystemRole
};
var invoiceApproverRole = new Role
{
Name = "ApproveInvoices",
Description = "Members are allowed to approve invoices",
ApplicationId = "Invoice",
Type = RoleType.ApplicationRole
};
var invoicePosterRole = new Role
{
Name = "PostInvoices",
Description = "Members are allowed to post approved invoices",
ApplicationId = "Invoice",
Type = RoleType.ApplicationRole
};
}
The background is: I have multiple applications (services) that use the same (single-signon) user / role database (Moved from SQLServer/NHibernate to Redis). Business data is stored on MongoDB and still some stuff on MSSQL / PostgreSQL. Some general roles like ‘User’ and ‘Administrator’ are available everywhere. Usually an Administrator can do admin things like creating a new user, a user can do standard business stuff like query addresses, products, invoices etc.
Every application may define specific roles as outlined above for an invoicing application. I have some more complex scenarios, e.g. a payroll application which has a few more roles to cover…
The UI offers a possibility to assign roles to specific users in a specific application. Technically this requires the ability to
- List all roles per application
- List all role types
- Find all roles that a user is member of
- The stuff which is already there: addUserToRole, removeUserFromRole, …
All my apps are multi-tenant, so I have extended my IUserAuth implementation with a property
int TenantId, which is a fixed length integer hash calculated from some mandatory props of my tenant object (Name, parts of the address etc). So I have access to the tenant via this ID. I have created one database per tenant which is very easy when using MongoDB and quite heavy when using any RDBMS… (I made some comments on Stackoverflow yesterday…)
Thats about it. If you think this could be useful for Servicestack let me know if I can be of any help. Please remember that I am quite new to ServiceStack and also C# (which means I am still discovering a lot of new things…) but a C/C++, Java, Groovy and SQL / BI hacker for 20+ years.