本文整理汇总了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;
}
示例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;
}
示例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;
}
示例4: foreach
bool IAuthorizationPolicy.Evaluate( EvaluationContext evaluationContext, ref object state )
{
foreach ( ClaimSet issuance in _issuedClaimSets )
evaluationContext.AddClaimSet( this, issuance );
return true;
}
示例5: Evaluate
public bool Evaluate(EvaluationContext context, ref object state)
{
foreach (ClaimSet issuance in this.issuedClaimSets)
{
context.AddClaimSet(this, issuance);
}
return true;
}
示例6:
bool IAuthorizationPolicy.Evaluate( EvaluationContext evaluationContext, ref object state )
{
if ( evaluationContext == null )
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "evaluationContext" );
}
evaluationContext.AddClaimSet( this, _issuer );
return true;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}