So in Programming WCF Security - One, we discussed core security features that WCF addresses &
Transport Level Security, & in Programming WCF Security - Two, Lets move to next I’ll discuss more about Authentication ,
Authorization & Impersonation ...
Although it might seems like
it should be a simple process to determine who someone is? The reality is that
it’s not. Problems are well understood, who confirms the credentials? Which
encryption is used? Describing how WCF provides answers to these questions is
purpose of this discussion. Here I will discuss more about Authentication,
Authorization & little bit about Impersonation too.
Authentication
Basically, authentication is
process of one party verifying that the claims regarding the identity of second
party are correct. Typically that would be client needing to be verified by the
service; however this is possible for the service to also authenticate itself
with the client. WCF offers a variety of authentication mechanisms:
- No Authentication (Anonymous Authentication)
- Windows Authentication
- User name & password
- X.509 certificate
- Issued tokens Authentication
- Custom Authentication
Issued tokens Authentication
The main idea behind the
issued token credentials is to allow a third-party token granting authority to
perform the authentication process. The client requests a token and then
includes that token in the request to the WCF service. The WCF service then
hands that token to the token granting authority to retrieve information about
the requester. With following sample of service configuration file:
<services>
<service name=”Samples.Service” behaviorConfiguration=”ServiceBehavior”>
<!– Use the base address provided by the host. –>
<endpoint address=”" binding=”wsHttpBinding”
bindingConfiguration=”requireInfocard″
contract=”Samples.IService” >
<service name=”Samples.Service” behaviorConfiguration=”ServiceBehavior”>
<!– Use the base address provided by the host. –>
<endpoint address=”" binding=”wsHttpBinding”
bindingConfiguration=”requireInfocard″
contract=”Samples.IService” >
<identity>
<certificateReference
findValue=”” X509FindType=”” storelocation=”” storename=””
</identity>
</endpoint>
</service>
</services>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name=” requireInfocard”>
<security mode=”message”>
<message
clientCredentialType=”IssuedToken”
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name=”ServiceCredentials”>
<serviceCredentials>
<serviceCertificate
=”” X509FindType=”” storelocation=”” storename=”” />
<issuedTokenAuthentication allowUntrustedRsaIssuers=”True” />
</serviceCredentials>
</behavior>
<serviceBehaviors>
</behaviors>
Above settings provide
details of which authentication facility to use.
Authorization & Impersonation
Being able to identify the
client it just half the process, Authorization determines the access that is
allowed to various resources. You can control access in several ways with
Windows Communication Foundation (WCF)
- PrincipalPermissionAttribute
- Identity Model
We will only discuss how Restrict
Access with the PrincipalPermissionAttribute Class here, for Identity Model
Please visit MSDN.
Controlling the access to
resources on a Windows-domain computer is a basic security task. For example,
only certain users should be able to view sensitive data, such as payroll
information. The task consists of two separate procedures.
The first creates the group
and populates it with users. The second applies the PrincipalPermissionAttribute
class to specify the group.
To create a Windows group
- Open the Computer Management console. In the left panel, click Local Users and Groups.
- Right-click Groups, and click New Group.
- In the Group Name box, type a name for the new group.
- In the Description box, type a description of the new group.
- Click the Add button to add new members to the group.
- If you have added yourself to the group and want
to test the following code, you must log off the computer and log back on to be
included in the group.
To demand user membership
1. Open the Windows Communication Foundation (WCF) code file that contains the implemented service contract code.
2. Apply the PrincipalPermissionAttribute attribute to each method that must be restricted to a specific group. Set the Action property to Demand and the Role property to the name of the group. For example:
[PrincipalPermission(SecurityAction.Demand,
Role =
"CalculatorClients")]
public double
Add(double a, double b)
{ return a + b; }
Using a Certificate to
Control Access to a Method
[PrincipalPermission(SecurityAction.Demand,
Name = "CN=ReplaceWithSubjectName;
123456712345677E8E230FDE624F841B1CE9D41E
")]
public double
Add(double a, double b)
{ return a + b; }
Impersonation Basics
Windows Communication
Foundation (WCF) supports impersonation for a variety of client credentials by following
two approaches
- Cached Token Impersonation
- S4U-Based Impersonation
The extent to which the
service can impersonate the client depends on the privileges the service
account holds when it attempts impersonation, the type of impersonation used,
and possibly the extent of impersonation the client permits. To enable impersonation, set
the Impersonation property to one of the Impersonation Option enumeration
values as follows
[OperationBehavior(Impersonation
= ImpersonationOption.Required)]
public string
Hello(string message)
{return
"hello";}
This is all about Windows Communication
Foundation Security Infrastructure.