14 March 2013 Claims Robert Muehsig

Bei einer Umstellung von einer .NET 4.0 Anwendung, welche unter anderem auch die Windows Identity Foundation benutzt, auf .NET 4.5 ist mir aufgefallen dass der Typ “Claim” unter Umständen in drei Namespaces definiert sein kann:

image

Die 3 Namespaces mit den Claim

Seit .NET 4.5 gibt es Claims in diesen zwei Namenspaces:

System.Security.Claims.Claim

System.IdentityModel.Claims.Claim

Unter umständen (wenn die Referenz Microsoft.IdentityModel.dll noch im Projekt ist) hat man noch dies zur Auswahl:

Microsoft.IdentityModel.Claims

Erkläuterung:

Das Konzept der Claims wurde mit .NET 4.5 direkt ins Framework eingebunden. Daher gibt es auch einige Interfaces, wie z.B. IClaimsIdentity, nicht mehr. Der Artikel “What’s New in Windows Identity Foundation 4.5” listet alles genauer auf. Die Microsoft.IdentityModel.* Namespaces sind damit veraltet.

Wichtigste Parts meiner Meinung nach:

WIF Is Now Part of the .NET Framework

WIF classes are now spread across several assemblies, the main ones being mscorlib, System.IdentityModel, System.IdentityModel.Services, and System.ServiceModel. Likewise, the WIF classes are spread across several namespaces: System.Security.Claims, several System.IdentityModel namespaces, and System.ServiceModel.Security. TheSystem.Security.Claims namespace contains the new ClaimsPrincipal and ClaimsIdentity classes (see below). All principals in .NET now derive from ClaimsPrincipal. For more detailed information about the WIF namespaces and the kinds of classes that they contain, see WIF API Reference. For information about how namespaces map between WIF 3.5 and WIF 4.5, see Namespace Mapping between WIF 3.5 and WIF 4.5.

New Claims Model and Principal Object

Claims are at the very core of the .NET Framework 4.5. The base claim classes (Claim, ClaimsIdentity, ClaimsPrincipal, ClaimTypes, and ClaimValueTypes) all live directly in mscorlib in the System.Security.Claims namespace. It is no longer necessary to use interfaces in order to plug claims into the .NET identity system: WindowsPrincipal, GenericPrincipal, and RolePrincipal now inherit from ClaimsPrincipal; and WindowsIdentity, GenericIdentity, and FormsIdentity now inherit from ClaimsIdentity. In short, every principal class will now serve claims. The WIF 3.5 integration classes and interfaces (WindowsClaimsIdentity, WindowsClaimsPrincipal, IClaimsPrincipal, IClaimsIdentity) have thus been removed. In addition, the ClaimsIdentity class now exposes methods which make it easier to query the identity’s claims collection.

Migration auf Windows Identity Foundation 4.5

Wer eine Anwendung migriert, der schaut am besten in der Mapping Tabelle nach.

Wenn im Code diese Klassen “WindowsClaimsIdentity, WindowsClaimsPrincipal, IClaimsPrincipal,IClaimsIdentity” vorkommen, dann kann man es meist sehr einfach mit ClaimsPrinciple bzw. ClaimsIdentity austauschen.

Ansonsten ist die hauptsächliche Claim-Definition im System.Security.Claims Namespace!


Written by Robert Muehsig

Software Developer - from Saxony, Germany - working on primedocs.io. Microsoft MVP & Web Geek.
Other Projects: KnowYourStack.com | ExpensiveMeeting | EinKofferVollerReisen.de