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


C# EvaluationContext.AddClaimSet方法代码示例

本文整理汇总了C#中System.IdentityModel.Policy.EvaluationContext.AddClaimSet方法的典型用法代码示例。如果您正苦于以下问题:C# EvaluationContext.AddClaimSet方法的具体用法?C# EvaluationContext.AddClaimSet怎么用?C# EvaluationContext.AddClaimSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IdentityModel.Policy.EvaluationContext的用法示例。


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

示例1: Evaluate

        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            IPrincipal principal = null;
            if (HttpContext.Current != null)
            {
                principal = HttpContext.Current.User;
            }

            if (principal != null)
            {
                // set the identity (for PrimaryIdentity)
                evaluationContext.Properties["Identities"] =
                    new List<IIdentity>() { principal.Identity };

                evaluationContext.Properties["Principal"] = principal;

                var nameClaim = Claim.CreateNameClaim(principal.Identity.Name);
                ClaimSet set;

                if (HttpContext.Current != null)
                {
                    set = new DefaultClaimSet(
                        nameClaim,
                        new Claim(ClaimTypes.Authentication, HttpContext.Current.User.Identity, Rights.Identity));
                }
                else
                {
                    set = new DefaultClaimSet(nameClaim);
                }

                evaluationContext.AddClaimSet(this, set);
            }

            return true;
        }
开发者ID:amido,项目名称:Amido.PreProcessor,代码行数:35,代码来源:HttpContextIdentityPolicy.cs

示例2: Evaluate

        /**
        This method receives the claim sets evaluated so far by other authorization policies.
        For example, it may include a claim set for each token passed in the request message,
         * thus contain a WindowsClaimSet or UserNameClaimSet or x509 cliams set and so on.
         *
         * Responsible for inspecting claims based on the credentials provided,
         * mapping those claims to normalized claims,
         * and constructing a security principal for the request thread.
         *
         * The method should return false if this authorization policy was not able to complete its authorization.
         *
         * If false, the service model will invoke other authorization policies and then call this one once more, passing the updated claim sets.
         * This gives the authorization policy another chance to authorize calls.
         *
        **/
        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            object obj;
            if (!evaluationContext.Properties.TryGetValue("Identities", out obj))
                return false;

            IList<IIdentity> identities = obj as IList<IIdentity>;
            if (obj == null || identities.Count <= 0)
                return false;

            IIdentity identity = identities[0];

            //This is claims conversion
            ClaimSet claims = MapClaims(identity);

            if (claims == null)
                return false;

            GenericPrincipal newPrincipal = new GenericPrincipal(identity, null);

            evaluationContext.Properties["Principal"] = newPrincipal;

            evaluationContext.AddClaimSet(this, claims);

            return true;
        }
开发者ID:cleancodenz,项目名称:ServiceBus,代码行数:41,代码来源:MyClaimsAuthorizationPolicy.cs

示例3: Evaluate

 public bool Evaluate(EvaluationContext evaluationContext, ref object state)
 {
   evaluationContext.AddClaimSet(this, new DefaultClaimSet(Claim.CreateNameClaim(_principal.Identity.Name)));
   evaluationContext.Properties["Identities"] = new List<IIdentity>(new[] {_principal.Identity});
   evaluationContext.Properties["Principal"] = _principal;
   return true;
 }
开发者ID:yonglehou,项目名称:DevDefined.OAuth,代码行数:7,代码来源:PrincipalAuthorizationPolicy.cs

示例4: foreach

        bool IAuthorizationPolicy.Evaluate( EvaluationContext evaluationContext, ref object state )
        {
            foreach ( ClaimSet issuance in _issuedClaimSets )
                evaluationContext.AddClaimSet( this, issuance );

            return true;
        }
开发者ID:Sn3b,项目名称:Omniture-API,代码行数:7,代码来源:SecurityTokenAuthorizationPolicy.cs

示例5: Evaluate

        public bool Evaluate(EvaluationContext context, ref object state)
        {
            foreach (ClaimSet issuance in this.issuedClaimSets)
            {
                context.AddClaimSet(this, issuance);
            }

            return true;
        }
开发者ID:cleancodenz,项目名称:ServiceBus,代码行数:9,代码来源:CreditCardTokenAuthorizationPolicy.cs

示例6:

 bool IAuthorizationPolicy.Evaluate( EvaluationContext evaluationContext, ref object state )
 {
     if ( evaluationContext == null )
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "evaluationContext" );
     }
     evaluationContext.AddClaimSet( this, _issuer );
     return true;
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:9,代码来源:SctAuthorizationPolicy.cs

示例7: Evaluate

        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            bool bRet = false;
            CustomAuthState customstate = null;

            // If state is null, then we've not been called before so we need
            // to set up our custom state
            if (state == null)
            {
                customstate = new CustomAuthState();
                state = customstate;
            }
            else
                customstate = (CustomAuthState)state;

            Console.WriteLine("Inside MyAuthorizationPolicy::Evaluate");

            // If we've not added claims yet...
            if (!customstate.ClaimsAdded)
            {
                // Create an empty list of Claims
                IList<Claim> claims = new List<Claim>();

                // Iterate through each of the claimsets in the evaluation context
                foreach (ClaimSet cs in evaluationContext.ClaimSets)
                    // Look for Name claims in the current claimset...
                    foreach (Claim c in cs.FindClaims(ClaimTypes.Name, Rights.PossessProperty))
                        // Get the list of operations the given username is allowed to call...
                        foreach (string s in GetAllowedOpList(c.Resource.ToString()))
                        {
                            // Check numbers aren't too large
                            

                            // Add claims to the list
                            claims.Add(new Claim("http://example.org/claims/allowedoperation", s, Rights.PossessProperty));
                            Console.WriteLine("Claim added {0}", s);
                        }

                // Add claims to the evaluation context    
                evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer, claims));

                // record that we've added claims
                customstate.ClaimsAdded = true;

                // return true, indicating we do not need to be called again.
                bRet = true;
            }
            else
            {
                // Should never get here, but just in case...
                bRet = true;
            }


            return bRet;
        }
开发者ID:ssickles,项目名称:archive,代码行数:56,代码来源:MyAuthorizationPolicy.cs

示例8: Evaluate

        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            // find identity
            Claim id = evaluationContext.ClaimSets.FindIdentityClaim();
            string userId = Map(id);

            evaluationContext.AddClaimSet(this, new CustomerClaimSet(userId, Issuer));

            return true;
        }
开发者ID:calderonsteven,项目名称:Preparation_For_Exam70-513,代码行数:10,代码来源:CustomerAuthorizationPolicy.cs

示例9: Evaluate

        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            Claim claim = Claim.CreateNameClaim(user.Identity.Name);
            evaluationContext.AddClaimSet(this, new DefaultClaimSet(claim));

            evaluationContext.Properties["Identities"] =
                new List<IIdentity>(new IIdentity[] { user.Identity });

            evaluationContext.Properties["Principal"] = user;

            return true;
        }
开发者ID:BorisMomtchev,项目名称:NiCris.Dashboard-.NET-4.5,代码行数:12,代码来源:PrincipalAuthorizationPolicy.cs

示例10: Evaluate

        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            if (evaluationContext.Properties.ContainsKey("Identities"))
            {
                IIdentity identity;
                ClaimSet claims = MapClaims(evaluationContext, out identity);
                
                CustomPrincipal newPrincipal = new CustomPrincipal(identity, claims);
                evaluationContext.Properties["Principal"] = newPrincipal;
                evaluationContext.AddClaimSet(this, claims);
            }
            return true;

        }
开发者ID:ssickles,项目名称:archive,代码行数:14,代码来源:CustomAuthorizationPolicy.cs

示例11: Evaluate

        public bool Evaluate(EvaluationContext context, ref object state)
        {
            var identities = new List<IIdentity> {_identity};

            context.AddClaimSet(this,
                new DefaultClaimSet(Issuer, new Claim(ClaimTypes.Name, _identity == null ? null : _identity.Name, Rights.Identity)));

            if (context.Properties.ContainsKey(AuthContextIdentityPropertyName))
                context.Properties[AuthContextIdentityPropertyName] = identities;
            else
                context.Properties.Add(AuthContextIdentityPropertyName, identities);

            return true;
        }
开发者ID:richet,项目名称:WcfRestContrib,代码行数:14,代码来源:IdentityAuthorizationPolicy.cs

示例12: Evaluate

        //We will add a custom claim to the EvaluationContext if the 'magic character' exists in the username
        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            //Get the Identities Property
            object obj;
            if (!evaluationContext.Properties.TryGetValue("Identities", out obj))
            {
                Debug.WriteLine("CustomNameCheckerPolicy: Identities is null");
                return false;
            }

            //Get the list of IIdentities
            IList<IIdentity> identities = obj as IList<IIdentity>;
            if (identities == null || identities.Count != 1)
            {
                Debug.WriteLine("CustomNameCheckerPolicy: Identities.count = 0");
                return false;
            }

            //Get the WindowsIdentity
            //Any other type of IIdentity will cause it to return false
            WindowsIdentity wID = identities[0] as WindowsIdentity;
            if (wID == null)
            {
                Debug.WriteLine("CustomNameCheckerPolicy: Not a Windows Identity");
                return false;
            }

            //retrieve the username
            string[] domainAndUsername =  wID.Name.Split(new char[]{'\\'});
            string userName = domainAndUsername[0];
            if (domainAndUsername.Length > 1)
                userName = domainAndUsername[1];

            //Check to see if the 'magic character' exists in the username
            //Add our claim if it does
            if (userName.ToUpper().Contains(Constants.magicCharacter.ToUpper()))
            {
                List<Claim> claims = new List<Claim>(1);
                Claim magicCharacterClaim = new Claim(Constants.PossessesMagicCharacterType, Constants.magicCharacter, Rights.PossessProperty);
                claims.Add(magicCharacterClaim);
                evaluationContext.AddClaimSet(this, new DefaultClaimSet(claims));
            }

            return true;
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:46,代码来源:CustomNameCheckerPolicy.cs

示例13: Evaluate

        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            if (evaluationContext.Properties.ContainsKey("Identities"))
            {
                List<IIdentity> identities = evaluationContext.Properties["Identities"] as List<IIdentity>;
                IIdentity identity = identities.FirstOrDefault(i => i.AuthenticationType == "X509");
                
                GenericPrincipal genprincipal = new GenericPrincipal(identity, null);
                evaluationContext.Properties["Principal"] = genprincipal;

                var user = UserStore.GetUserByCertificate(identity.Name);
                evaluationContext.AddClaimSet(this, new DefaultClaimSet(new Claim("User", user, Rights.Identity)));

                return true;
            }
            else
                return false;
        }
开发者ID:kiszu,项目名称:ForBlog,代码行数:18,代码来源:CustomCertificateAuthorizationPolicy.cs

示例14: Evaluate

			// This method is expected to be thread safe
			public bool Evaluate (EvaluationContext ec, ref object state)
			{
				lock (ec) {
					ec.AddClaimSet (this, CreateClaims ());
					List<IIdentity> list;
					if (!ec.Properties.ContainsKey ("Identities")) {
						list = new List<IIdentity> ();
						ec.Properties ["Identities"] = list;
					} else {
						IList<IIdentity> ilist = (IList<IIdentity>) ec.Properties ["Identities"];
						list = ilist as List<IIdentity>;
						if (list == null) {
							list = new List<IIdentity> (ilist);
							ec.Properties ["Identities"] = list;
						}
					}
					list.Add (CreateIdentity ());
					ec.RecordExpirationTime (DateTime.MaxValue.AddDays (-1));
				}
				// FIXME: is it correct that this should always return true?
				return true;
			}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:CustomUserNameSecurityTokenAuthenticator.cs

示例15: Evaluate

        /// <summary>
        /// Defines the set of rules to for authorizing a user given a set of claims. 
        /// It prepares the evaluation context with relevant information and adds the claims to the evaluation context.
        /// </summary>
        /// <param name="evaluationContext">Evaluation context</param>
        /// <param name="state">State</param>
        /// <returns>return false if this authorization policy was not able to complete its authorization, otherwise true</returns>
        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            if (OperationContext.Current.IncomingMessageProperties[PRINCIPAL] != null)
            {
                IClaimsPrincipal principal = OperationContext.Current.IncomingMessageProperties[PRINCIPAL] as IClaimsPrincipal;

                // If the principal is not an IClaimsPrincipal we can not authorize it
                if (principal == null)
                {
                    return false;
                }

                evaluationContext.Properties[PRINCIPAL] = principal;

                if (principal.Claims != null)
                {
                    evaluationContext.AddClaimSet(this, principal.Claims);
                }

                return true;
            }
            return false;
        }
开发者ID:ognjenm,项目名称:egle,代码行数:30,代码来源:ClaimsAuthorizationPolicy.cs


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