Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to limit WCF Service to specific User Accounts

Tags:

c#

.net

wcf

I will be hosting a basic HTTP WCF service using Window Service / Service Host. I would like to limit the service to 2 specific window active directory users and these accounts will vary between PRD and DEV environments so they will be set in a config file.

I was wondering what is the best way to do this, I know normally if I was hosting the service using IIS then I could limit it in the Web.config: http://www.rickgaribay.net/archive/2007/04/04/recipe-wcf-basichttpbinding-with-windows-authentication.aspx However since i'm hosting using ServiceHost then I don't believe this is an option.

From what I read it seems possible to do this using PrincipalPermission Declarative attribute at the service class level: http://msdn.microsoft.com/en-us/library/vstudio/ms731200(v=vs.100).aspx However I'm not too clear whether this will pass the window account of window service or the account which made the HTTP request. What I need is to pass the HTTP request account. Also, with declartive attributes, is it possible to use a config file attribute rather than a hard coded one?

Any suggestions, if you need any more info then let me know.

like image 767
Rubans Avatar asked Nov 10 '12 21:11

Rubans


People also ask

How do I restrict WCF service access?

Open the Computer Management Windows applet. Create a Windows group that contains the specific Windows users to which you wish to give access. For example, a group can be called “CalculatorClients”. Configure your service to require ClientCredentialType = “Windows”.

What are 3 basic WCF configurations required for hosting a WCF service?

There are three types of hosting environments for WCF services: IIS, WAS, and self-hosting. The term “self-hosting” refers to any application that provides its own code to initialize the hosting environment. This includes console, Windows Forms, WPF, and managed Windows services.

What is WCF self hosting?

This is referred to as a self hosting WCF service, the exact meaning of Self Hosted is that it hosts the service in an application that could be a Console Application or Windows Forms and so on. Earlier we saw what a WCF Service is in the . Net environment. We can host a WCF service in IIS and a Windows service also.


2 Answers

Try to use Role-Based authorization. http://msdn.microsoft.com/en-us/magazine/cc948343.aspx#id0070004

like image 156
Max Kilovatiy Avatar answered Sep 28 '22 23:09

Max Kilovatiy


I found the following article suitable for what I needed, basically it involved authorisation using a behavior: http://allen-conway-dotnet.blogspot.co.uk/2010/01/how-to-create-aspnet-windows.html

like image 34
Rubans Avatar answered Sep 29 '22 01:09

Rubans