How to implement a custom authentication mechanism for a WCF Web Service
I have just created my first WCF service. Now I would like to do the following:
Add my custom authentication mechanism, e.g., querying a database's user table.
Make the results of my service's operations dependent on the user that has logged in.
How do I do that?
NOTE: I have already tried googling, even using site filters such as "site:stackoverflow.com" and "site:codeproject.com", but couldn't find what I nee开发者_运维问答d.
Greetings,
Depending on the size of the project, some of the solutions outlined in the link below may be overkill, however, feel free to take a look.
WCF Security Practices
Create a custom UserNamePasswordValidator and override the Validate method.
http://msdn.microsoft.com/en-us/library/aa702565.aspx
Inside your service implementation you'll have access to "OperationContext.Current.ServiceSecurityContext.PrimaryIdentity" which is the user that was authenticated.
精彩评论