2017-06-01 3 views
2

Da ich individuelle Ansprüche in meine Anwendung hinzufügen möchten, überprüfte ich den Sourcecode von ClaimTypes (mit JetBrains Decompiler dekompiliert). Hier ist ein Stück davon:was sind die URLs für in Anspruch Typen

namespace System.Security.Claims 
{ 
    /// <summary>Defines constants for the well-known claim types that can be assigned to a subject. This class cannot be inherited.</summary> 
    [ComVisible(false)] 
    public static class ClaimTypes 
    { 
    internal const string ClaimTypeNamespace = "http://schemas.microsoft.com/ws/2008/06/identity/claims"; 
    /// <summary>The URI for a claim that specifies the instant at which an entity was authenticated; http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant.</summary> 
    public const string AuthenticationInstant = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant"; 
    /// <summary>The URI for a claim that specifies the method with which an entity was authenticated; http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod.</summary> 
    public const string AuthenticationMethod = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod"; 
    /// <summary>The URI for a claim that specifies the cookie path; http://schemas.microsoft.com/ws/2008/06/identity/claims/cookiepath.</summary> 
    public const string CookiePath = "http://schemas.microsoft.com/ws/2008/06/identity/claims/cookiepath"; 
    /// <summary>The URI for a claim that specifies the deny-only primary SID on an entity; http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid. A deny-only SID denies the specified entity to a securable object.</summary> 
    public const string DenyOnlyPrimarySid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid"; 
    /// <summary>The URI for a claim that specifies the deny-only primary group SID on an entity; http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroupsid. A deny-only SID denies the specified entity to a securable object.</summary> 
    public const string DenyOnlyPrimaryGroupSid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroupsid"; 

Meine Frage ist (und ich hoffe, es ist nicht zu dumm), was sind die URLs für? Werden sie woanders benutzt? Wenn ich versuche, eine URL zu öffnen, sagt mein Explorer, dass die Site nicht gefunden wurde. Also ich denke, es gibt kein XML-Schema oder etwas dahinter. Wenn ich meine benutzerdefinierten Ansprüche hinzufüge, muss ich auch diese URLs hinzufügen?

Antwort

2

Dies sind ClaimTypes, die die vordefinierten Arten von Ansprüchen darstellen, die eine Entität beanspruchen kann. Die von Ihnen erwähnten sind von WIF, hier sind die IdentityModel ClaimTypes.

Bekannte Anspruchstypen werden automatisch in den Kontext deserialisiert. Wie http://schemas.microsoft.com/ws/2008/06/identity/claims/role wird als Rolle der user.roles-Auflistung hinzugefügt (für IsInRole verwendet).

Also die Typen sind nicht zufällig, sondern nach Spezifikation. Sie können Ihre eigenen Typen hinzufügen. Dies kann eine beliebige Zeichenfolge sein, Sie können jedoch auch dasselbe Format verwenden.

Angenommen, Sie ein CustomerId als Anspruch hinzufügen, dann werden Sie die Ansprüche Sammlung von claimtype="CustomerId" abfragen müssen, oder die uri Sie definiert (wie http://schemas/mycompany.com/2017/06/identity/CustomerId).

Sie können Ansprüche von Code hinzufügen oder durch Aufzeichnungen in den Identity.Claims Tabellen einfügen.

+1

Meinten Sie 'http: //schemas.mycompany ...'? – xr280xr

Verwandte Themen