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);
}
}
}
}

Claims Identity的更多相关文章

  1. 全新的membership框架Asp.net Identity(2)——绕不过的Claims

    本来想直接就开始介绍Identity的部分,奈何自己挖坑太深,高举高打的方法不行.只能自己默默下载了Katana的源代码研究了好一段时间.发现要想能够理解好用好Identity, Claims是一个绕 ...

  2. Identity Server 4 - Hybrid Flow - Claims

    前一篇 Identity Server 4 - Hybrid Flow - MVC客户端身份验证: https://www.cnblogs.com/cgzl/p/9253667.html Claims ...

  3. AspNet Identity 和 Owin 谁是谁

    英文原文:http://tech.trailmax.info/2014/08/aspnet-identity-and-owin-who-is-who/ 最近我发现Stackoverflow上有一个非常 ...

  4. 译:Asp.Net Identity与Owin,到底谁是谁?

    送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...

  5. Identity Server 4 - Hybrid Flow - MVC客户端身份验证

    预备知识 可能需要看一点点预备知识 OAuth 2.0 不完全简介: https://www.cnblogs.com/cgzl/p/9221488.html OpenID Connect 不完全简介: ...

  6. Web API2 使用默认Identity

    当您选择个人账户在Web API项目模板,项目包含一个令牌授权服务器验证用户凭证和问题.下面的图显示了相同的凭证流的Web API组件. 发送一个未经授权的请求 首先,运行应用程序并单击按钮调用的AP ...

  7. 【译】Asp.Net Identity与Owin,到底谁是谁?

    送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...

  8. SharePoint Adventures : Using Claims with Reporting Services

    Cannot convert claims identity to a windows token.  This may be due to user not logging in using win ...

  9. DotNet 资源大全中文版(Awesome最新版)

    Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...

随机推荐

  1. KMP快速字符串匹配

    KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时发现.KMP算法的关键是利用匹配失败后的信息,从错误中吸取经验,尽量减少模式串与主串的匹配次数以 ...

  2. Fiddler-009-AutoResponder 简单的 MOCK SERVER 应用实例

    在我们日常的测试中经常需要测试特定的响应对应的客户端展示样式是否正确无误,实现测试方法一般有如下三种: 创建新的测试数据(工作量较大) 修改已有测试数据(例如修改对应的状态码,若是最终需要测试的按钮状 ...

  3. LeetCode Number of 1 Bits

    原题链接在这里:https://leetcode.com/problems/number-of-1-bits/ 题目: Write a function that takes an unsigned ...

  4. LeetCode Palindrome Permutation II

    原题链接在这里:https://leetcode.com/problems/palindrome-permutation-ii/ 题目: Given a string s, return all th ...

  5. LeetCode Strobogrammatic Number II

    原题链接在这里:https://leetcode.com/problems/strobogrammatic-number-ii/ 题目: A strobogrammatic number is a n ...

  6. Git commit 常见用法

        Git commit git commit 主要是将用户通过git add命令添加到暂存区里的改动给提交到本地的版本库,关于版本库的构成可以查看我先前的笔记. 每次提交我们都会在本地版本库生成 ...

  7. zabbix的一些优化参数随笔

    StartDBSyncers=12  如果proxy过多 可以适当加大这个参数 ProxyConfigFrequency=60ProxyDataFrequency=60 这两个参数很重要,一个是ser ...

  8. Hadoop学习笔记: MapReduce Java编程简介

    概述 本文主要基于Hadoop 1.0.0后推出的新Java API为例介绍MapReduce的Java编程模型.新旧API主要区别在于新API(org.apache.hadoop.mapreduce ...

  9. Java基础之在窗口中绘图——渐变填充(GradientApplet 1)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; @SuppressWarnings("s ...

  10. Oracle配置本地网络服务名

    Oracle安装完成后,可以使用客户端自带的的网络配置向导(Net Configuration Assistant)进行配置 1.启动Net Configuration Assistant.选择&qu ...