当前位置: 首页>>代码示例>>C#>>正文


C# IIdentity类代码示例

本文整理汇总了C#中IIdentity的典型用法代码示例。如果您正苦于以下问题:C# IIdentity类的具体用法?C# IIdentity怎么用?C# IIdentity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IIdentity类属于命名空间,在下文中一共展示了IIdentity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsNotAuthenticated

 /// <summary>
 /// Asserts that <paramref name="identity"/> is not authenticated.
 /// </summary>		
 public static void IsNotAuthenticated(IIdentity identity)
 {
     Assert.IsNotNull(identity);
     Assert.IsFalse(identity.IsAuthenticated,
                   "Identity {0} authentitcated",
                   identity.Name);
 }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:10,代码来源:OldSecurityAssert.cs

示例2: GetOrCreateStorage

        public IRecordStorage GetOrCreateStorage(IIdentity id)
        {
            if (!s_storages.ContainsKey(id))
                s_storages.Add(id, new MemoryRecordStorage(id));

            return s_storages[id];
        }
开发者ID:sahina,项目名称:aec_cqrs,代码行数:7,代码来源:MemoryRecordStorageFactory.cs

示例3: AddUserIdentity

        /// <summary>
        /// Add an additional ClaimsIdentity to the ClaimsPrincipal in the "server.User" environment key
        /// </summary>
        /// <param name="identity"></param>
        public void AddUserIdentity(IIdentity identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }
            var newClaimsPrincipal = new ClaimsPrincipal(identity);

            IPrincipal existingPrincipal = _context.Request.User;
            if (existingPrincipal != null)
            {
                var existingClaimsPrincipal = existingPrincipal as ClaimsPrincipal;
                if (existingClaimsPrincipal == null)
                {
                    IIdentity existingIdentity = existingPrincipal.Identity;
                    if (existingIdentity.IsAuthenticated)
                    {
                        newClaimsPrincipal.AddIdentity(existingIdentity as ClaimsIdentity ?? new ClaimsIdentity(existingIdentity));
                    }
                }
                else
                {
                    foreach (var existingClaimsIdentity in existingClaimsPrincipal.Identities)
                    {
                        if (existingClaimsIdentity.IsAuthenticated)
                        {
                            newClaimsPrincipal.AddIdentity(existingClaimsIdentity);
                        }
                    }
                }
            }
            _context.Request.User = newClaimsPrincipal;
        }
开发者ID:jizhonglee,项目名称:Security,代码行数:37,代码来源:SecurityHelper.cs

示例4: HttpHandlerContext

		public HttpHandlerContext(Server server, HttpRequestProcessor.Host host, Connection connection, IIdentity identity)
		{
			Server = server;
			Host = host;
			Connection = connection;
			Identity = identity;
		}
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:7,代码来源:HttpHandlerContext.cs

示例5: CustomPrincipal

        public CustomPrincipal(IIdentity identity, String[] roles)
        {
            if (identity == null) throw new ArgumentNullException("identity");

            this.m_Identity = identity;
            this.m_Roles = roles;
        }
开发者ID:yaoyel,项目名称:Finework,代码行数:7,代码来源:CustomPrincipal.cs

示例6: AddIdentityWithRoles

        /// <summary>
        /// helper method to add roles 
        /// </summary>
        void AddIdentityWithRoles(IIdentity identity, string[] roles)
        {
            ClaimsIdentity claimsIdentity = identity as ClaimsIdentity;

            if (claimsIdentity != null)
            {
                claimsIdentity = claimsIdentity.Clone();
            }
            else
            {
                claimsIdentity = new ClaimsIdentity(identity);
            }

            // Add 'roles' as external claims so they are not serialized
            // TODO - brentsch, we should be able to replace GenericPrincipal and GenericIdentity with ClaimsPrincipal and ClaimsIdentity
            // hence I am not too concerned about perf.
            List<Claim> roleClaims = new List<Claim>();
            if (roles != null && roles.Length > 0)
            {
                foreach (string role in roles)
                {
                    if (!string.IsNullOrWhiteSpace(role))
                    {
                        roleClaims.Add(new Claim(claimsIdentity.RoleClaimType, role, ClaimValueTypes.String, ClaimsIdentity.DefaultIssuer, ClaimsIdentity.DefaultIssuer, claimsIdentity));
                    }
                }

                claimsIdentity.ExternalClaims.Add(roleClaims);
            }

            base.AddIdentity(claimsIdentity);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:35,代码来源:GenericPrincipal.cs

示例7: MapClaims

        private ClaimSet MapClaims(EvaluationContext evaluationContext, out IIdentity identity)
        {

            List<IIdentity> identities = evaluationContext.Properties["Identities"] as List<IIdentity>;
            
            if (identities.Count == 0)
                throw new SecurityException("Authorization failed, identity missing from evaluation context.");

            identity = new CustomIdentity(identities[0].Name);
            
            // TODO: check identity against credential store and 
            // determine the appropriate claims to allocate
            
            // NOTE: in this sample, only partner certificates are provided,
            // and at this point have passed authorization, so we will grant
            // all custom claims 
            
            List<Claim> listClaims = new List<Claim>();

            listClaims.Add(new Claim(CustomClaimTypes.Create, "Application", Rights.PossessProperty));
            listClaims.Add(new Claim(CustomClaimTypes.Delete, "Application", Rights.PossessProperty));
            listClaims.Add(new Claim(CustomClaimTypes.Read, "Application", Rights.PossessProperty));
            listClaims.Add(new Claim(CustomClaimTypes.Update, "Application", Rights.PossessProperty));

            return new DefaultClaimSet(this.m_issuer, listClaims);
        }
开发者ID:ssickles,项目名称:archive,代码行数:26,代码来源:CustomAuthorizationPolicy.cs

示例8: GetTestAggregateReadModelAsync

 public override async Task<ITestAggregateReadModel> GetTestAggregateReadModelAsync(IIdentity id)
 {
     return await _queryProcessor.ProcessAsync(
         new ReadModelByIdQuery<InMemoryTestAggregateReadModel>(id.Value),
         CancellationToken.None)
         .ConfigureAwait(false);
 }
开发者ID:liemqv,项目名称:EventFlow,代码行数:7,代码来源:InMemoryConfiguration.cs

示例9: SetUp

            public override void SetUp()
            {
                base.SetUp();

                _orderModel = Fixture.Create<PurchaseOrderModel>();
                _currentUser = new Mock<IIdentity>().Object;
            }
开发者ID:smchristenson,项目名称:CommerceStarterKit,代码行数:7,代码来源:PaymentCompleteHandlerTests.cs

示例10: GetPrincipalFromCookie

        /// <summary>
        /// Creates Principal and Identity based on the user name and roles from the 
        /// asp.net authentication cookie;
        /// </summary>
        /// <returns>The current principal</returns>
        public static IPrincipal GetPrincipalFromCookie(IIdentity identity)
        {
            string cookieName = FormsAuthentication.FormsCookieName;
            HttpCookie authCookie = HttpContext.Current.Request.Cookies[cookieName];

            if (authCookie == null)
            {
                // There is no authentication cookie.
                return SetEmptyPrincipal();
            }

            FormsAuthenticationTicket authTicket = null;
            try
            {
                authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            }
            catch
            {
                // error occured. Let user authenticate again
                return SetEmptyPrincipal();
            }

            if (authTicket == null)
            {
                // Cookie failed to decrypt.
                return SetEmptyPrincipal();
            }

            // Whenever we load cookie we always load the Roles instead of loading it from Userdata
            string[] roles = Roles.GetRolesForUser(identity.Name);

            IPrincipal principal = new VKeCRMPrincipal(identity, roles);
            HttpContext.Current.User = principal;
            return principal;
        }
开发者ID:VKeCRM,项目名称:V2,代码行数:40,代码来源:VKeCRMPrincipal.cs

示例11: RolePrincipal

 public RolePrincipal(IIdentity identity)
 {
     if (identity == null)
         throw new ArgumentNullException( "identity" );
     _Identity = identity;
     Init();
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:7,代码来源:RolePrincipal.cs

示例12: AppendToStream

        public void AppendToStream(IIdentity id, long expectedVersion, IList<IEvent> newEvents)
        {
            var server = this.client.GetServer();
            var db = server.GetDatabase("EventStore");
            var query = Query<MongoEventDocument>.EQ(s => s.id, id);
            
            var events = db.GetCollection<MongoEventDocument>("Events",_commitSettings);

            //events.Insert<MongoEventDocument>(new MongoEventDocument
            //{
            //    events = newEvents.ToList<IEvent>(),
            //    id = id,
            //    version = 1
            //});

            var doc = events.FindOneAs<MongoEventDocument>(query);
            if (doc == null) events.Insert<MongoEventDocument>(new MongoEventDocument
            {
                events = newEvents.ToList<IEvent>(),
                id = id,
                version = 1
            });
            if (doc != null)
            {
                doc.events.AddRange(newEvents);
                doc.version += 1;
                events.Save(doc);
            }


        }
开发者ID:jcwrequests,项目名称:WYS.MongoDB.EventStore,代码行数:31,代码来源:MongoEventStore.cs

示例13: DuplicateOperationException

 public DuplicateOperationException(
     ISourceId sourceId, IIdentity aggregateId, string message)
     : base(message)
 {
     SourceId = sourceId;
     AggregateId = aggregateId;
 }
开发者ID:liemqv,项目名称:EventFlow,代码行数:7,代码来源:DuplicateOperationException.cs

示例14: WebPrincipal

 public WebPrincipal(IIdentity identity, string token, string userName, string displayName)
 {
     _token = token;
     _identity = identity;
     _displayName = displayName;
     _userName = userName;
 }
开发者ID:kevinburrowes,项目名称:Magazine,代码行数:7,代码来源:WebPrincipal.cs

示例15: CustomIdentity

 public CustomIdentity(IIdentity identity)
 {
     this.AuthenticationType = identity.AuthenticationType;
     this.IsAuthenticated = identity.IsAuthenticated;
     this.Name = identity.Name;
     this.Role = "admin";
 }
开发者ID:antonysamy931,项目名称:WCF-WsHttpBinding,代码行数:7,代码来源:CustomPrincipal.cs


注:本文中的IIdentity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。