Solved

Limiting access to WCF service using Windows authentication

Posted on 2016-10-12
5
87 Views
Last Modified: 2016-11-02
I have a WCF service that can only be accessed by domain users. I used the following config:
    <system.web>
        <authentication mode="Windows" />
        <authorization>
            <deny users="?" />
        </authorization>
    </system.web>

Open in new window

The service is hosted on IIS 6, where Windows authentication is enabled and anonymous - disabled. the above worked fine for me but now i want to limit access to only a single uers. i tried the following:

    <system.web>
        <authentication mode="Windows" />
        <authorization>
            <allow users="DOMAIN\user1" />
            <deny users="*" />
        </authorization>
    </system.web>

Open in new window

but that did not work - all the domain users have access, not just user1.

I also tried:
    <authorization>
            <allow users="DOMAIN\Group1"/>
            <deny users="DOMAIN\Domain Users"/>
    </authorization>

Open in new window

I also tried to utilize PrincipalPermission attribute to limit access to a method:

 [PrincipalPermission(SecurityAction.Demand, Role = "Group1")]

Open in new window


But it did not make any difference at all. What can i do to limit the access to a user or group?
0
Comment
Question by:YZlat
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:Dan McFadden
ID: 41841468
Here is an article that explains Authorization & Authentication.

Link:  https://weblogs.asp.net/gurusarkar/setting-authorization-rules-for-a-particular-page-or-folder-in-web-config

Here is the MSDN reference:  https://msdn.microsoft.com/en-us/library/wce3kxhd.aspx

An IIS Forum thread over issues with Authorization:  https://forums.iis.net/p/1173012/1961218.aspx

I've also answered a similar question recently here on EE:

https://www.experts-exchange.com/questions/28974384/IIs-block-files-web-config.html

Dan
0
 
LVL 35

Author Comment

by:YZlat
ID: 41846905
@DanMcFadden, per my code above, I am already using techniques described in the articles but it is not working.

None of the links you have provided helped me, plus most of them are on Forms authentication while I am using Windows authentication
0
 
LVL 27

Expert Comment

by:Dan McFadden
ID: 41857020
OK, have you read thru the followng article which explains the various strategies for using Authentication and Authorization is .NET apps?

Link:  https://msdn.microsoft.com/en-us/library/ff649337.aspx#secnetch08_authstrategies

It was released a while back, but the concepts remain essentially the same.

Also, what OS version are you using?

Have you only tried modifying the web.config?  Have you tried building the rules thru the IIS Manager?

Have you tried your config like this"

<authorization>
    <allow roles="DOMAIN\Group1"/>
    <deny roles="DOMAIN\Domain Users"/>
</authorization>

Open in new window


Dan
0
 
LVL 35

Author Comment

by:YZlat
ID: 41857189
Hi Dan. Yes, i have tried the above but found that when it comes to WCF services, authorization is a bit complicated. i am currently looking into creating custom WCF authorization using ServiceAuthorizationManager. Are you familiar with it?
0
 
LVL 27

Accepted Solution

by:
Dan McFadden earned 500 total points
ID: 41857195
I have read about it and played in DEV with the developers, but not implemented any production web services with it.

I do have an interesting article, its old but most likely still relevant.

Link:  https://pieterderycke.wordpress.com/2011/04/07/implementing-restricted-access-to-a-wcf-service-with-the-serviceauthorizationmanager/

Seems in line with the current MSDN article:  https://msdn.microsoft.com/en-us/library/ms731774(v=vs.110).aspx

Dan
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question