本文整理汇总了C#中IIdentity类的典型用法代码示例。如果您正苦于以下问题:C# IIdentity类的具体用法?C# IIdentity怎么用?C# IIdentity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IIdentity类属于命名空间,在下文中一共展示了IIdentity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Identity
internal Identity(IIdentity identity, X509Certificate2 clientCertificate)
{
this.AuthenticationType = identity.AuthenticationType;
this.IsAuthenticated = identity.IsAuthenticated;
this.Name = identity.Name;
this.Certificate = clientCertificate;
}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:Identity.cs
示例17: IsUserInRole
/// <summary>
/// The is user in role.
/// </summary>
/// <param name="identity">
/// The identity.
/// </param>
/// <param name="roles">
/// The roles.
/// </param>
/// <returns>
/// The <see cref="bool" />.
/// </returns>
public bool IsUserInRole(IIdentity identity, string roles)
{
Contract.Requires<ArgumentNullException>(identity != null, "identity");
Contract.Requires<ArgumentNullException>(roles != null, "roles");
return true;
}
开发者ID:Tauron1990,项目名称:Tauron-Application-Common,代码行数:19,代码来源:ISecurable.cs
示例18: AuthorizeAction
/// <summary>
/// Helper method to ensure that the <seealso cref="IIdentity"/> can authenticate against
/// the <seealso cref="Membership"/> and that the <seealso cref="IIdentity"/> is also
/// authorized to make the requested changes against the account retrieved
/// from the accountId
/// </summary>
/// <param name="identity">
/// The <c>IIdentity</c> of the user authorized to delete the <c>EmailAddress</c>
/// from the repository
/// </param>
/// <param name="accountId">
/// The id of the <seealso cref="Account"/> to use for authorization
/// </param>
/// <exception cref="SecurityException">
/// Thrown if the <seealso cref="IIdentity"/> cannot be authenticated or is not authorized
/// to access the records requested
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown if the <seealso cref="Account"/> with the provided id cannot be retrieved from the
/// repository
/// </exception>
public virtual void AuthorizeAction(IIdentity identity, int accountId)
{
var user = Membership.GetUser(identity.Name, false);
if (user == null)
{
throw new SecurityException(
string.Format(
"The user {0} is not properly authenticated against the membership provider.", identity.Name));
}
var ownerAccount = accountReadRepository.FindBy(account => account.Id.Equals(accountId));
if (ownerAccount == null)
{
throw new ArgumentException(
string.Format("The account with id {0} cannot be found", accountId), "accountId");
}
// ReSharper disable PossibleNullReferenceException
if (!ownerAccount.UserId.Equals((Guid)user.ProviderUserKey) && !Roles.IsUserInRole("Admin"))
// ReSharper restore PossibleNullReferenceException)
{
throw new SecurityException(
string.Format(
"The user {0} is not authorized to access the method called for the account owned by {1}",
identity.Name,
ownerAccount.Name));
}
}
开发者ID:gunnerl3510,项目名称:Mobile-Application-for-Care-Management,代码行数:51,代码来源:Security.cs
示例19: LoginEventArgs
/// <summary>
/// Initializes LoginEventArgs instance.
/// </summary>
/// <param name="eventType">Login event type.</param>
/// <param name="identity">Client's identity.</param>
/// <param name="timestamp">Event timestamp.</param>
public LoginEventArgs(LoginEventType eventType, IIdentity identity, DateTime timestamp)
{
EventType = eventType;
Identity = identity;
ClientAddress = string.Empty;
Timestamp = timestamp;
}
开发者ID:yallie,项目名称:zyan,代码行数:13,代码来源:LoginEventArgs.cs
示例20: Controller
public Controller(IIdentity currentUser)
{
if (currentUser.IsAuthenticated)
{
loadCurrentUser();
}
}
开发者ID:ricardopereira,项目名称:csharp.AnimalCare,代码行数:7,代码来源:Controller.cs
注:本文中的IIdentity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论