本文整理汇总了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);
}
示例2: GetOrCreateStorage
public IRecordStorage GetOrCreateStorage(IIdentity id)
{
if (!s_storages.ContainsKey(id))
s_storages.Add(id, new MemoryRecordStorage(id));
return s_storages[id];
}
示例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;
}
示例4: HttpHandlerContext
public HttpHandlerContext(Server server, HttpRequestProcessor.Host host, Connection connection, IIdentity identity)
{
Server = server;
Host = host;
Connection = connection;
Identity = identity;
}
示例5: CustomPrincipal
public CustomPrincipal(IIdentity identity, String[] roles)
{
if (identity == null) throw new ArgumentNullException("identity");
this.m_Identity = identity;
this.m_Roles = roles;
}
示例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);
}
示例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);
}
示例8: GetTestAggregateReadModelAsync
public override async Task<ITestAggregateReadModel> GetTestAggregateReadModelAsync(IIdentity id)
{
return await _queryProcessor.ProcessAsync(
new ReadModelByIdQuery<InMemoryTestAggregateReadModel>(id.Value),
CancellationToken.None)
.ConfigureAwait(false);
}
示例9: SetUp
public override void SetUp()
{
base.SetUp();
_orderModel = Fixture.Create<PurchaseOrderModel>();
_currentUser = new Mock<IIdentity>().Object;
}
示例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;
}
示例11: RolePrincipal
public RolePrincipal(IIdentity identity)
{
if (identity == null)
throw new ArgumentNullException( "identity" );
_Identity = identity;
Init();
}
示例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);
}
}
示例13: DuplicateOperationException
public DuplicateOperationException(
ISourceId sourceId, IIdentity aggregateId, string message)
: base(message)
{
SourceId = sourceId;
AggregateId = aggregateId;
}
示例14: WebPrincipal
public WebPrincipal(IIdentity identity, string token, string userName, string displayName)
{
_token = token;
_identity = identity;
_displayName = displayName;
_userName = userName;
}
示例15: CustomIdentity
public CustomIdentity(IIdentity identity)
{
this.AuthenticationType = identity.AuthenticationType;
this.IsAuthenticated = identity.IsAuthenticated;
this.Name = identity.Name;
this.Role = "admin";
}