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. Apache Spark技术实战之5 -- SparkR的安装及使用

    欢迎转载,转载请注明出处,徽沪一郎. 概要 根据论坛上的信息,在Sparkrelease计划中,在Spark 1.3中有将SparkR纳入到发行版的可能.本文就提前展示一下如何安装及使用SparkR. ...

  2. 直观友好的单个memcache监控工具:phpmemcache.php

    上传phpmemcache.php到指定文件 修改文件中的: define('ADMIN_USERNAME','user');     // Admin Usernamedefine('ADMIN_P ...

  3. 获取唯一UUID/UDID方案

    概述 如何保证获取到的UUID能够唯一标识每一台设备呢?我们知道通过UIDevice可以获取到UUIDString,但是如果App被删除了然后重新安装,就会得到不同的UUIDString,这并不是我们 ...

  4. angularJ表单验证

    常用的表单验证指令 1. 必填项验证 某个表单输入是否已填写,只要在输入字段元素上添加HTML5标记required即可: <input type="text" requir ...

  5. iOS 深浅拷贝

    -(void)copyDemo { // 在非集合类对象中:对immutable对象进行copy操作,是指针复制,mutableCopy操作时内容复制:对mutable对象进行copy和mutable ...

  6. 设置SQLServer的行版本控制隔离级别

    1.--查询数据库状态 select name,user_access,user_access_desc,snapshot_isolation_state,snapshot_isolation_sta ...

  7. mongoDb(2)聚合

    1.mongodb的聚合是有专门的一个方法的.

  8. DuiLib事件分析(一)——鼠标事件响应

    最近在处理DuiLib中自定义列表行元素事件,因为处理方案得不到较好的效果,于是只好一层一层的去剥离DuiLib事件是怎么来的,看能否在某一层截取消息,自己重写. 我这里使用CListContaine ...

  9. Mysql----------的一些常用命令

    1.查询一张表中某个字段重复值的记录 select id,cert_number from (select id,cert_number,count(*)as n from 表明 group by c ...

  10. linux--------wdcp中的各种坑。

    1.刚买的空间客服给安装了wdcplinux,结果上去一看PHP是5.2版本的,这不是搞笑嘛.然后就有了下面的升级: 复制这条命令回车然后敲Y就可以: wget http://soft.itbulu. ...