I am trying to implement authorization for a WCF service but I have run into some significant difficulties. I think I need to use a hybrid solution combining custom authentication and claims, but I am not sure if this is correct.
My application uses Windows authentication to connect to the application. Once the user has been authorized, access to functions needs to be granted based on permission information stored in the database.
Users can be assigned permissions via the application interface. One level of the permission heirarchy corresponds to access to individual WCF functions:
- Access to module (purely organizational)
- Access to function (access to WCF function, checked automatically)
- Function-specific permissions (checked dynamically in code)
- Access to function (access to WCF function, checked automatically)
Sample structure and usage:
- Shipping
- Can Create Shipment
- Can override naming conventions
- Can Package Shipment
- Must be verified by supervisor
- Can generate customs documentation ...
- Can Create Shipment
class ShippingService : IShippingService { // Access corresponds to "Can create shipment" permission public bool CreateShipment(string name) { ... // Check the function-specific permission dynamically. if (!ConformsToNamingConvention(name) && !CheckPermission(Permissions.CanOverrideNamingConvention)) return false; .... return true; } }
I think what I need to do is to create a custom Authorization Policy by implementing IAuthorizationPolicy. This will connect to the database, pull the permissions for the user and add a claim for each of the permissions. I will then need to create a custom authorization manager that will compare the requested action with the list of claims to determine if the connecting user is authorized.
Is this the correct way to approach this, or am I:
a) overcomplicating the issue, or
b) using WCF components incorrectly (such as claims, IAuthorizationPolicy, AuthorizationManager...)
Thanks in advance for any help, and best regards.