< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Claims.KestrunClaimExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Claims/UserIdentityClaim.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 61
Uncovered lines: 0
Coverable lines: 61
Total lines: 370
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
ToClaimUri(...)100%11100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Claims/UserIdentityClaim.cs

#LineLine coverage
 1using System.Security.Claims;
 2
 3namespace Kestrun.Claims;
 4/// <summary>
 5/// Represents the set of claims supported by Kestrun for authentication and authorization purposes.
 6/// </summary>
 7public enum UserIdentityClaim
 8{
 9    /// <summary>
 10    /// Specifies the actor claim, representing the identity of the acting party.
 11    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/actor
 12    /// </summary>
 13    Actor,
 14    /// <summary>
 15    /// Specifies the anonymous claim, representing an unauthenticated user.
 16    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/anonymous
 17    /// </summary>
 18    Anonymous,
 19    /// <summary>
 20    /// Specifies the authentication claim, representing the authentication method used.
 21    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/authentication
 22    /// </summary>
 23    Authentication,
 24    /// <summary>
 25    /// Specifies the authentication instant claim, representing the time at which the user was authenticated.
 26    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant
 27    /// </summary>
 28    AuthenticationInstant,
 29    /// <summary>
 30    /// Specifies the authentication method claim, representing the method used to authenticate the user.
 31    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod
 32    /// </summary>
 33    AuthenticationMethod,
 34    /// <summary>
 35    /// Specifies the authorization decision claim, representing the decision made by the authorization system.
 36    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/authorizationdecision
 37    /// </summary>
 38    AuthorizationDecision,
 39    /// <summary>
 40    /// Specifies the country claim, representing the country of the user.
 41    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/country
 42    /// </summary>
 43    Country,
 44    /// <summary>
 45    /// Specifies the date of birth claim, representing the user's date of birth.
 46    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/dateofbirth
 47    /// </summary>
 48    DateOfBirth,
 49    /// <summary>
 50    /// Specifies the DNS claim, representing the DNS name of the user.
 51    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns
 52    /// </summary>
 53    Dns,
 54    /// <summary>
 55    /// Specifies the deny only primary group SID claim, representing a security identifier for a group.
 56    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroupsid
 57    /// </summary>
 58    DenyOnlyPrimaryGroupSid,
 59    /// <summary>
 60    /// Specifies the deny only primary sid claim, representing a security identifier for a user.
 61    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid
 62    /// </summary>
 63    DenyOnlyPrimarySid,
 64    /// <summary>
 65    /// Specifies the deny only sid claim, representing a security identifier.
 66    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlysid
 67    /// </summary>
 68    DenyOnlySid,
 69    /// <summary>
 70    /// Specifies the deny only Windows device group claim, representing a security identifier for a Windows device grou
 71    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlywindowsdevicegroup
 72    /// </summary>
 73    DenyOnlyWindowsDeviceGroup,
 74    /// <summary>
 75    /// Specifies the email claim, representing the user's email address.
 76    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/email
 77    /// </summary>
 78    Email,
 79    /// <summary>
 80    /// Specifies the email address claim, representing the user's email address.
 81    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
 82    /// </summary>
 83    EmailAddress,
 84    /// <summary>
 85    /// Specifies the expiration claim, representing the expiration time of the token.
 86    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/expiration
 87    /// </summary>
 88    Expiration,
 89    /// <summary>
 90    /// Specifies the given name claim, representing the user's first name.
 91    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
 92    /// </summary>
 93    GivenName,
 94    /// <summary>
 95    /// Specifies the gender claim, representing the user's gender.
 96    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/gender
 97    /// </summary>
 98    Gender,
 99    /// <summary>
 100    /// Specifies the group SID claim, representing the security identifier for a group.
 101    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/groupsid
 102    /// </summary>
 103    GroupSid,
 104    /// <summary>
 105    /// Specifies the hash claim, representing a hash of the user's data.
 106    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/hash
 107    /// </summary>
 108    Hash,
 109    /// <summary>
 110    /// Specifies the home phone claim, representing the user's home phone number.
 111    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/homephone
 112    /// </summary>
 113    HomePhone,
 114    /// <summary>
 115    /// Specifies the is persistent claim, representing whether the user's session is persistent.
 116    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/ispersistent
 117    /// </summary>
 118    IsPersistent,
 119    /// <summary>
 120    /// Specifies the issuer claim, representing the issuer of the token.
 121    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/issuer
 122    /// </summary>
 123    Issuer,
 124    /// <summary>
 125    /// Specifies the locality claim, representing the user's locality.
 126    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/locality
 127    /// </summary>
 128    Locality,
 129    /// <summary>
 130    /// Specifies the mobile phone claim, representing the user's mobile phone number.
 131    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone
 132    /// </summary>
 133    MobilePhone,
 134    /// <summary>
 135    /// Specifies the name claim, representing the user's full name.
 136    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
 137    /// </summary>
 138    Name,
 139    /// <summary>
 140    /// Specifies the name identifier claim, representing the user's unique identifier.
 141    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier
 142    /// </summary>
 143    NameIdentifier,
 144    /// <summary>
 145    /// Specifies the other phone claim, representing the user's other phone number.
 146    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/otherphone
 147    /// </summary>
 148    OtherPhone,
 149    /// <summary>
 150    /// Specifies the postal code claim, representing the user's postal code.
 151    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/postalcode
 152    /// </summary>
 153    PostalCode,
 154    /// <summary>
 155    /// Specifies the primary group SID claim, representing the primary security identifier for a group.
 156    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/primarygroupsid
 157    /// </summary>
 158    PrimaryGroupSid,
 159    /// <summary>
 160    /// Specifies the personal identifier claim, representing the user's personal identifier.
 161    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/ppid
 162    /// </summary>
 163    Ppid,
 164    /// <summary>
 165    /// Specifies the private personal identifier claim, representing the user's private personal identifier.
 166    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privateppid
 167    /// </summary>
 168    PrivatePpid,
 169    /// <summary>
 170    /// Specifies the role claim, representing the user's role in the system.
 171    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/role
 172    /// </summary>
 173    Role,
 174    /// <summary>
 175    /// Specifies the RSA claim, representing the user's RSA public key.
 176    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/rsa
 177    /// </summary>
 178    Rsa,
 179    /// <summary>
 180    /// Specifies the serial number claim, representing the user's serial number.
 181    /// http://schemas.microsoft.com/ws/2008/06/identity/claims/serialnumber
 182    /// </summary>
 183    SerialNumber,
 184    /// <summary>
 185    /// Specifies the sid claim, representing the security identifier for a user.
 186    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sid
 187    /// </summary>
 188    Sid,
 189    /// <summary>
 190    /// Specifies the state or province claim, representing the user's state or province.
 191    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/stateorprovince
 192    /// </summary>
 193    StateOrProvince,
 194    /// <summary>
 195    /// Specifies the service principal name (SPN) claim, representing the SPN for the user.
 196    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/spn
 197    /// </summary>
 198    Spn,
 199    /// <summary>
 200    /// Specifies the street address claim, representing the user's street address.
 201    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/streetaddress
 202    /// </summary>
 203    StreetAddress,
 204    /// <summary>
 205    /// Specifies the surname claim, representing the user's last name.
 206    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname
 207    /// </summary>
 208    Surname,
 209    /// <summary>
 210    /// Specifies the thumbprint claim, representing the user's certificate thumbprint.
 211    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint
 212    /// </summary>
 213    Thumbprint,
 214    /// <summary>
 215    /// Specifies the user data claim, representing additional user data.
 216    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/userdata
 217    /// </summary>
 218    UserData,
 219    /// <summary>
 220    /// Specifies the upn claim, representing the user's User Principal Name.
 221    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn
 222    /// </summary>
 223    Upn,
 224    /// <summary>
 225    /// Specifies the URI claim, representing a URI associated with the user.
 226    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uri
 227    /// </summary>
 228    Uri,
 229    /// <summary>
 230    /// Specifies the version claim, representing the version of the user's data.
 231    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/version
 232    /// </summary>
 233    Version,
 234    /// <summary>
 235    /// Specifies the webpage claim, representing the user's webpage.
 236    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/webpage
 237    /// </summary>
 238    Webpage,
 239    /// <summary>
 240    /// Specifies the system claim, representing the user's system information.
 241    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/system
 242    /// </summary>
 243    System,
 244    /// <summary>
 245    /// Specifies the Windows account name claim, representing the user's Windows account name.
 246    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsaccountname
 247    /// </summary>
 248    WindowsAccountName,
 249    /// <summary>
 250    /// Specifies the Windows device claim, representing the user's Windows device information.
 251    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsdevice
 252    /// </summary>
 253    WindowsDevice,
 254    /// <summary>
 255    /// Specifies the Windows device group claim, representing the user's Windows device group information.
 256    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsdevicegroup
 257    /// </summary>
 258    WindowsDeviceGroup,
 259    /// <summary>
 260    /// Specifies the Windows FQBN version claim, representing the version of the Windows device.
 261    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsfqbnversion
 262    /// </summary>
 263    WindowsFqbnVersion,
 264    /// <summary>
 265    /// Specifies the Windows group SID claim, representing the security identifier for a Windows group.
 266    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsgroupsid
 267    /// </summary>
 268    WindowsGroupSid,
 269    /// <summary>
 270    /// Specifies the Windows group claim, representing the user's Windows group information.
 271    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsgroup
 272    /// </summary>
 273    WindowsGroup,
 274    /// <summary>
 275    /// Specifies the Windows device claim, representing the user's Windows device information.
 276    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsdeviceClaim
 277    /// </summary>
 278    WindowsDeviceClaim,
 279    /// <summary>
 280    /// Specifies the Windows sub-authority claim, representing a sub-authority in the Windows security identifier.
 281    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowssubauthority
 282    /// </summary>
 283    WindowsSubAuthority,
 284    /// <summary>
 285    /// Specifies the Windows SID claim, representing the security identifier for a Windows user.
 286    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsid
 287    /// </summary>
 288    WindowsSid,
 289    /// <summary>
 290    /// Specifies the primary SID claim, representing the primary security identifier for a user.
 291    /// http://schemas.xmlsoap.org/ws/2005/05/identity/claims/primarysid
 292    /// </summary>
 293    PrimarySid
 294}
 295
 296/// <summary>
 297/// Provides extension methods for the KestrunClaim enum.
 298/// </summary>
 299public static class KestrunClaimExtensions
 300{
 1301    private static readonly Dictionary<UserIdentityClaim, string> _map = new()
 1302    {
 1303        [UserIdentityClaim.Actor] = ClaimTypes.Actor,
 1304        [UserIdentityClaim.Anonymous] = ClaimTypes.Anonymous,
 1305        [UserIdentityClaim.Authentication] = ClaimTypes.Authentication,
 1306        [UserIdentityClaim.AuthenticationInstant] = ClaimTypes.AuthenticationInstant,
 1307        [UserIdentityClaim.AuthenticationMethod] = ClaimTypes.AuthenticationMethod,
 1308        [UserIdentityClaim.AuthorizationDecision] = ClaimTypes.AuthorizationDecision,
 1309        [UserIdentityClaim.Country] = ClaimTypes.Country,
 1310        [UserIdentityClaim.DateOfBirth] = ClaimTypes.DateOfBirth,
 1311        [UserIdentityClaim.Dns] = ClaimTypes.Dns,
 1312        [UserIdentityClaim.DenyOnlyPrimaryGroupSid] = ClaimTypes.DenyOnlyPrimaryGroupSid,
 1313        [UserIdentityClaim.DenyOnlyPrimarySid] = ClaimTypes.DenyOnlyPrimarySid,
 1314        [UserIdentityClaim.DenyOnlySid] = ClaimTypes.DenyOnlySid,
 1315        [UserIdentityClaim.DenyOnlyWindowsDeviceGroup] = ClaimTypes.DenyOnlyWindowsDeviceGroup,
 1316        [UserIdentityClaim.Email] = "http://schemas.microsoft.com/ws/2008/06/identity/claims/email",
 1317        [UserIdentityClaim.EmailAddress] = ClaimTypes.Email,
 1318        [UserIdentityClaim.Expiration] = "http://schemas.microsoft.com/ws/2008/06/identity/claims/expiration",
 1319        [UserIdentityClaim.GivenName] = ClaimTypes.GivenName,
 1320        [UserIdentityClaim.Gender] = ClaimTypes.Gender,
 1321        [UserIdentityClaim.GroupSid] = ClaimTypes.GroupSid,
 1322        [UserIdentityClaim.Hash] = ClaimTypes.Hash,
 1323        [UserIdentityClaim.HomePhone] = ClaimTypes.HomePhone,
 1324        [UserIdentityClaim.IsPersistent] = ClaimTypes.IsPersistent,
 1325        [UserIdentityClaim.Issuer] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/issuer",
 1326        [UserIdentityClaim.Locality] = ClaimTypes.Locality,
 1327        [UserIdentityClaim.MobilePhone] = ClaimTypes.MobilePhone,
 1328        [UserIdentityClaim.Name] = ClaimTypes.Name,
 1329        [UserIdentityClaim.NameIdentifier] = ClaimTypes.NameIdentifier,
 1330        [UserIdentityClaim.OtherPhone] = ClaimTypes.OtherPhone,
 1331        [UserIdentityClaim.PostalCode] = ClaimTypes.PostalCode,
 1332        [UserIdentityClaim.PrimaryGroupSid] = ClaimTypes.PrimaryGroupSid,
 1333        [UserIdentityClaim.Ppid] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/ppid",
 1334        [UserIdentityClaim.PrivatePpid] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privateppid",
 1335        [UserIdentityClaim.Role] = ClaimTypes.Role,
 1336        [UserIdentityClaim.Rsa] = ClaimTypes.Rsa,
 1337        [UserIdentityClaim.SerialNumber] = ClaimTypes.SerialNumber,
 1338        [UserIdentityClaim.Sid] = ClaimTypes.Sid,
 1339        [UserIdentityClaim.StateOrProvince] = ClaimTypes.StateOrProvince,
 1340        [UserIdentityClaim.Spn] = ClaimTypes.Spn,
 1341        [UserIdentityClaim.StreetAddress] = ClaimTypes.StreetAddress,
 1342        [UserIdentityClaim.Surname] = ClaimTypes.Surname,
 1343        [UserIdentityClaim.Thumbprint] = ClaimTypes.Thumbprint,
 1344        [UserIdentityClaim.UserData] = ClaimTypes.UserData,
 1345        [UserIdentityClaim.Upn] = ClaimTypes.Upn,
 1346        [UserIdentityClaim.Uri] = ClaimTypes.Uri,
 1347        [UserIdentityClaim.Version] = ClaimTypes.Version,
 1348        [UserIdentityClaim.Webpage] = ClaimTypes.Webpage,
 1349        [UserIdentityClaim.System] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/system",
 1350        [UserIdentityClaim.WindowsAccountName] = ClaimTypes.WindowsAccountName,
 1351        [UserIdentityClaim.WindowsDevice] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsdevice",
 1352        [UserIdentityClaim.WindowsDeviceGroup] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsdevicegro
 1353        [UserIdentityClaim.WindowsFqbnVersion] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsfqbnversi
 1354        [UserIdentityClaim.WindowsGroupSid] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsgroupsid",
 1355        [UserIdentityClaim.WindowsGroup] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsgroup",
 1356        [UserIdentityClaim.WindowsDeviceClaim] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsdeviceCla
 1357        [UserIdentityClaim.WindowsSubAuthority] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowssubautho
 1358        [UserIdentityClaim.WindowsSid] = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/windowsid",
 1359        [UserIdentityClaim.PrimarySid] = ClaimTypes.PrimarySid
 1360    };
 361
 362    /// <summary>
 363    /// Converts the specified <see cref="UserIdentityClaim"/> to its corresponding claim URI string.
 364    /// </summary>
 365    /// <param name="claim">The claim to convert.</param>
 366    /// <returns>The URI string representation of the claim.</returns>
 367    public static string ToClaimUri(this UserIdentityClaim claim)
 69368        => _map[claim];
 369}
 370