zoukankan      html  css  js  c++  java
  • Claims Identity

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Security.Claims;
    using System.Security.Principal;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;

    namespace SecurityDemo
    {
    class Program
    {
    static void Main(string[] args)
    {
    Setup();
    CheckCompatibility();
    CheckNewClaimsUsage();
    Console.ReadLine();
    }

    private static void Setup()
    {
    IList<Claim> claimCollection = new List<Claim>
    {
    new Claim(ClaimTypes.Name, "Andras")
    , new Claim(ClaimTypes.Country, "Sweden")
    , new Claim(ClaimTypes.Gender, "M")
    , new Claim(ClaimTypes.Surname, "Nemes")
    , new Claim(ClaimTypes.Email, "hello@me.com")
    , new Claim(ClaimTypes.Role, "IT")
    };

    ClaimsIdentity claimsIdentity =new ClaimsIdentity(claimCollection, "My e-commerce website");

    Console.WriteLine(claimsIdentity.IsAuthenticated);

    ClaimsPrincipal principal = new ClaimsPrincipal(claimsIdentity);
    Thread.CurrentPrincipal = principal;

    }

    private static void CheckCompatibility()
    {
    IPrincipal currentPrincipal = Thread.CurrentPrincipal;
    Console.WriteLine(currentPrincipal.Identity.Name);
    }

    private static void CheckNewClaimsUsage()
    {
    ClaimsPrincipal currentClaimsPrincipal = ClaimsPrincipal.Current;//Thread.CurrentPrincipal as ClaimsPrincipal;
    Claim nameClaim = currentClaimsPrincipal.FindFirst(ClaimTypes.Name);
    Console.WriteLine(nameClaim.Value);
    foreach (ClaimsIdentity ci in currentClaimsPrincipal.Identities)
    {
    Console.WriteLine(ci.Name);
    }
    }
    }
    }

  • 相关阅读:
    字体文件以base64编码的方式引入内嵌到样式文件中
    css content 如何自定义生成图标?
    很好的个人博客网址
    较好的第三方框架-网址
    html Javascript MD5
    html svg 编辑器
    ajax笔试面试题
    工作备忘录
    移动端页面兼容性问题解决方案整理(三)
    移动端页面兼容性问题解决方案整理(二)
  • 原文地址:https://www.cnblogs.com/shineqiujuan/p/4023903.html
Copyright © 2011-2022 走看看