473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

WCF Security: How restrict an endpoint to only response to a given windows user or group?

Hi,

I am trying to limit my wcf service endpoint to response to only given
windows user or group. How can I do that? Is there any way to configure that
in the .config file?

Thank you,
Max
Oct 9 '08 #1
5 9117
Hi Max,

As for security Authorization, the standard approach is to implement a
custom AuthorizationManager so that we can define our own authorization
code logic inside the AuthorizationManager(you can write code which read
authorization rules from config file). Here are some articles about
implementing a custom AuthorizationManager:

#How to: Create a Custom Authorization Manager for a Service
http://msdn.microsoft.com/en-us/library/ms731774.aspx

#How-To: Implement a WCF Authorization Manager Using AzMan
http://weblogs.asp.net/spano/archive...nt-a-wcf-autho
rization-manager-using-azman.aspx

In addition, if you use some certain bindings which support
"TransportCredentialOnly" security mode(such as basicHttpbinding), you can
simply write code in your WCF service to check the current Thread's
security identity. For example, here is an example WCF service which use
basichttpbinding and configured to use "TransportCredentialOnly" + windows
client credential.

=============================
<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">

<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="secBinding"
contract="IService">

<identity>
<dns value="localhost"/>
</identity>
</endpoint>

</service>
</services>

<bindings>

<basicHttpBinding>
<binding name="secBinding" >
<security mode="TransportCredentialOnly" >
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
===================================

in service code, you can check the client identity via;

=====service method=======
public string GetData(int value)
{
string name = HttpContext.Current.User.Identity.Name;

return string.Format("You entered: {0}", value.ToString() +
Thread.CurrentPrincipal.Identity.Name);
}
============

and in client-side code, you need to supply the correct user credentials:

================
static void Run()
{
WCFSVC.ServiceClient client = new
ConsoleClient.WCFSVC.ServiceClient();

//or you can use the default credentials instead of supply a custom account
client.ClientCredentials.Windows.ClientCredential = new
System.Net.NetworkCredential("username", "Password!");

string ret = client.GetData(5);

Console.WriteLine(ret);
}
==================
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Max2006" <al*******@newsgroup.nospam>
Subject: WCF Security: How restrict an endpoint to only response to a given
windows user or group?
Date: Thu, 9 Oct 2008 11:25:31 -0400

Hi,

I am trying to limit my wcf service endpoint to response to only given
windows user or group. How can I do that? Is there any way to configure
that
in the .config file?

Thank you,
Max

Oct 10 '08 #2
Hi Steven,

Since this is a very simple authorization requirement (response only to
DOMAIN\Group) I am wondering if there is any out of the box feature in WCF
to address the requirement.

Thank you,
Max

""Steven Cheng"" <st*****@online.microsoft.comwrote in message
news:AA**************@TK2MSFTNGHUB02.phx.gbl...
Hi Max,

As for security Authorization, the standard approach is to implement a
custom AuthorizationManager so that we can define our own authorization
code logic inside the AuthorizationManager(you can write code which read
authorization rules from config file). Here are some articles about
implementing a custom AuthorizationManager:

#How to: Create a Custom Authorization Manager for a Service
http://msdn.microsoft.com/en-us/library/ms731774.aspx

#How-To: Implement a WCF Authorization Manager Using AzMan
http://weblogs.asp.net/spano/archive...nt-a-wcf-autho
rization-manager-using-azman.aspx

In addition, if you use some certain bindings which support
"TransportCredentialOnly" security mode(such as basicHttpbinding), you can
simply write code in your WCF service to check the current Thread's
security identity. For example, here is an example WCF service which use
basichttpbinding and configured to use "TransportCredentialOnly" + windows
client credential.

=============================
<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">

<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="secBinding"
contract="IService">

<identity>
<dns value="localhost"/>
</identity>
</endpoint>

</service>
</services>

<bindings>

<basicHttpBinding>
<binding name="secBinding" >
<security mode="TransportCredentialOnly" >
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
===================================

in service code, you can check the client identity via;

=====service method=======
public string GetData(int value)
{
string name = HttpContext.Current.User.Identity.Name;

return string.Format("You entered: {0}", value.ToString() +
Thread.CurrentPrincipal.Identity.Name);
}
============

and in client-side code, you need to supply the correct user credentials:

================
static void Run()
{
WCFSVC.ServiceClient client = new
ConsoleClient.WCFSVC.ServiceClient();

//or you can use the default credentials instead of supply a custom
account
client.ClientCredentials.Windows.ClientCredential = new
System.Net.NetworkCredential("username", "Password!");

string ret = client.GetData(5);

Console.WriteLine(ret);
}
==================
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
From: "Max2006" <al*******@newsgroup.nospam>
Subject: WCF Security: How restrict an endpoint to only response to a
given
windows user or group?
Date: Thu, 9 Oct 2008 11:25:31 -0400

Hi,

I am trying to limit my wcf service endpoint to response to only given
windows user or group. How can I do that? Is there any way to configure
that
in the .config file?

Thank you,
Max
Oct 10 '08 #3
Thanks for your reply Max,

Yes, since impelementing a pure WCF solution is abit overkill, I first look
for some solution which rely on the ASP.NET authorization (which can
leverage the web.config <authorization>). However, based on my local test,
WCF requests doesn't be processed via that authorization system. And so
far the simple solution I can find is just use windows authentication and
let the identity of client be forwarded to WCF service, and we perform
check on the current thread's security identity to do authorization.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

--------------------
From: "Max2006" <al*******@newsgroup.nospam>
References: <D1**********************************@microsoft.co m>
<AA**************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: WCF Security: How restrict an endpoint to only response to a
given windows user or group?
Date: Fri, 10 Oct 2008 11:44:17 -0400
Hi Steven,

Since this is a very simple authorization requirement (response only to
DOMAIN\Group) I am wondering if there is any out of the box feature in WCF
to address the requirement.

Thank you,
Max

""Steven Cheng"" <st*****@online.microsoft.comwrote in message
news:AA**************@TK2MSFTNGHUB02.phx.gbl...
Hi Max,

As for security Authorization, the standard approach is to implement a
custom AuthorizationManager so that we can define our own authorization
code logic inside the AuthorizationManager(you can write code which read
authorization rules from config file). Here are some articles about
implementing a custom AuthorizationManager:

#How to: Create a Custom Authorization Manager for a Service
http://msdn.microsoft.com/en-us/library/ms731774.aspx

#How-To: Implement a WCF Authorization Manager Using AzMan
http://weblogs.asp.net/spano/archive...nt-a-wcf-autho
rization-manager-using-azman.aspx

In addition, if you use some certain bindings which support
"TransportCredentialOnly" security mode(such as basicHttpbinding), you can
simply write code in your WCF service to check the current Thread's
security identity. For example, here is an example WCF service which use
basichttpbinding and configured to use "TransportCredentialOnly" + windows
client credential.
Oct 13 '08 #4
Hi Steven,
>And so far the simple solution I can find is just use windows
authentication and let the identity of client be forwarded to WCF
service, and we perform check on the current thread's security identity
to do authorization.
We have 740 service methods and we want to secure them. It is a questionable
architecture if we have to add the check code to any single method.
Is there anyway in WCF to add the authorization behavior to all services?

Thank you,
Max

""Steven Cheng"" <st*****@online.microsoft.comwrote in message
news:oS**************@TK2MSFTNGHUB02.phx.gbl...
Thanks for your reply Max,

Yes, since impelementing a pure WCF solution is abit overkill, I first
look
for some solution which rely on the ASP.NET authorization (which can
leverage the web.config <authorization>). However, based on my local test,
WCF requests doesn't be processed via that authorization system. And so
far the simple solution I can find is just use windows authentication and
let the identity of client be forwarded to WCF service, and we perform
check on the current thread's security identity to do authorization.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

--------------------
From: "Max2006" <al*******@newsgroup.nospam>
References: <D1**********************************@microsoft.co m>
<AA**************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: WCF Security: How restrict an endpoint to only response to a
given windows user or group?
Date: Fri, 10 Oct 2008 11:44:17 -0400
Hi Steven,

Since this is a very simple authorization requirement (response only to
DOMAIN\Group) I am wondering if there is any out of the box feature in WCF
to address the requirement.

Thank you,
Max

""Steven Cheng"" <st*****@online.microsoft.comwrote in message
news:AA**************@TK2MSFTNGHUB02.phx.gbl...
>Hi Max,

As for security Authorization, the standard approach is to implement a
custom AuthorizationManager so that we can define our own authorization
code logic inside the AuthorizationManager(you can write code which read
authorization rules from config file). Here are some articles about
implementing a custom AuthorizationManager:

#How to: Create a Custom Authorization Manager for a Service
http://msdn.microsoft.com/en-us/library/ms731774.aspx

#How-To: Implement a WCF Authorization Manager Using AzMan
http://weblogs.asp.net/spano/archive...nt-a-wcf-autho
>rization-manager-using-azman.aspx

In addition, if you use some certain bindings which support
"TransportCredentialOnly" security mode(such as basicHttpbinding), you
can
simply write code in your WCF service to check the current Thread's
security identity. For example, here is an example WCF service which use
basichttpbinding and configured to use "TransportCredentialOnly" +
windows
client credential.
Oct 15 '08 #5
"Max2006" <al*******@newsgroup.nospamwrote in message
news:06**********************************@microsof t.com...
Hi Steven,
>>And so far the simple solution I can find is just use windows
authentication and let the identity of client be forwarded to WCF
service, and we perform check on the current thread's security identity
to do authorization.

We have 740 service methods and we want to secure them. It is a
questionable architecture if we have to add the check code to any single
method.
Is there anyway in WCF to add the authorization behavior to all services?
There is. See this month's MSDN Magazine in the Service Station column.
That's what it is about.

BTW, I find there are more WCF experts in the WCF Forum at
http://social.msdn.microsoft.com/for...S/wcf/threads/.
--
John Saunders | MVP - Connected System Developer

Oct 16 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Angelos Karantzalis | last post by:
Is there a way to set Permissions based on user roles by using some configuration file for my application ? I'm coming from a Java background, where that could very easily be accomplished but...
3
by: Br | last post by:
I'm going to go into a fair bit of detail as I'm hoping my methods may be of assistance to anyone else wanting to implement something similar (or totally confusing:) One of systems I've...
16
by: Marina | last post by:
Hi, I am trying to find the minimum security settings to allow a windows control embedded in IE have full trust. If I give the entire Intranet zone full trust, this works. However, this is...
7
by: Stephen | last post by:
I have my intranet setup on our web server. It contains multiple applications, but none are set up in the default application pools. In other words, I create a webform and plop it into a...
6
by: Mr Newbie | last post by:
Hi, Im in a situation where I need to restrict users, but I dont have access or wont be allowed access to manage groups in the domain. How can I restrict access is this case ? -- Best...
1
by: Friends | last post by:
Hi I need to set security for row level but not based on Database user's login. It should be based on the user table login. For the particular user I need to allow only the particular records to...
5
by: isideveloper | last post by:
I'm building a new C# web application that will provide my company some administrative operations that were previously only completed by tweaking the data in the database. 1. Encrypted password...
2
by: Ronald S. Cook | last post by:
Hi, Some users on our domain can run our WCF application no problem. Some get an unhandled exception error re: SOAP security negotiation. I'm wanting the service to not be secure.. I just want...
8
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service and hosted it in Windows Services. It is working fine. Now I am trying to implement the X509 certificates for message layer security. But it is throwing the following...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.