mirror of https://github.com/abpframework/abp.git
11 changed files with 462 additions and 20 deletions
@ -0,0 +1,65 @@ |
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
//TODO: Should set Id to a GUID (where? on repository?)
|
|||
//TODO: Properties should not be public!
|
|||
|
|||
/// <summary>
|
|||
/// Represents a role in the identity system
|
|||
/// </summary>
|
|||
public class IdentityRole : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the name for this role.
|
|||
/// </summary>
|
|||
public virtual string Name { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the normalized name for this role.
|
|||
/// </summary>
|
|||
public virtual string NormalizedName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Navigation property for claims in this role.
|
|||
/// </summary>
|
|||
public virtual ICollection<IdentityRoleClaim> Claims { get; } = new Collection<IdentityRoleClaim>(); |
|||
|
|||
/// <summary>
|
|||
/// A random value that should change whenever a role is persisted to the store
|
|||
/// </summary>
|
|||
public virtual string ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString(); |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of <see cref="IdentityRole"/>.
|
|||
/// </summary>
|
|||
protected IdentityRole() { } |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of <see cref="IdentityRole"/>.
|
|||
/// </summary>
|
|||
/// <param name="name">The role name.</param>
|
|||
public IdentityRole([NotNull] string name) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
Name = name; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the name of the role.
|
|||
/// </summary>
|
|||
/// <returns>The name of the role.</returns>
|
|||
public override string ToString() |
|||
{ |
|||
return Name; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
using System.Security.Claims; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
/// <summary>
|
|||
/// Represents a claim that is granted to all users within a role.
|
|||
/// </summary>
|
|||
public class IdentityRoleClaim : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the of the primary key of the role associated with this claim.
|
|||
/// </summary>
|
|||
public virtual string RoleId { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the claim type for this claim.
|
|||
/// </summary>
|
|||
public virtual string ClaimType { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the claim value for this claim.
|
|||
/// </summary>
|
|||
public virtual string ClaimValue { get; protected set; } |
|||
|
|||
protected IdentityRoleClaim() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public IdentityRoleClaim([NotNull] string roleId, [NotNull] Claim claim) |
|||
{ |
|||
Check.NotNull(roleId, nameof(roleId)); |
|||
Check.NotNull(claim, nameof(claim)); |
|||
|
|||
RoleId = roleId; |
|||
ClaimType = claim.Type; |
|||
ClaimValue = claim.Value; |
|||
} |
|||
|
|||
public IdentityRoleClaim([NotNull] string roleId, [NotNull] string claimType, string claimValue) |
|||
{ |
|||
Check.NotNull(roleId, nameof(roleId)); |
|||
Check.NotNull(claimType, nameof(claimType)); |
|||
|
|||
RoleId = roleId; |
|||
ClaimType = claimType; |
|||
ClaimValue = claimValue; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Constructs a new claim with the type and value.
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public virtual Claim ToClaim() |
|||
{ |
|||
return new Claim(ClaimType, ClaimValue); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,126 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
//TODO: Should set Id to a GUID (where? on repository?)
|
|||
//TODO: Properties should not be public!
|
|||
|
|||
public class IdentityUser : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the user name for this user.
|
|||
/// </summary>
|
|||
public virtual string UserName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the normalized user name for this user.
|
|||
/// </summary>
|
|||
public virtual string NormalizedUserName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the email address for this user.
|
|||
/// </summary>
|
|||
public virtual string Email { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the normalized email address for this user.
|
|||
/// </summary>
|
|||
public virtual string NormalizedEmail { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets a flag indicating if a user has confirmed their email address.
|
|||
/// </summary>
|
|||
/// <value>True if the email address has been confirmed, otherwise false.</value>
|
|||
public virtual bool EmailConfirmed { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets a salted and hashed representation of the password for this user.
|
|||
/// </summary>
|
|||
public virtual string PasswordHash { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// A random value that must change whenever a users credentials change (password changed, login removed)
|
|||
/// </summary>
|
|||
public virtual string SecurityStamp { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// A random value that must change whenever a user is persisted to the store
|
|||
/// </summary>
|
|||
public virtual string ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString(); |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets a telephone number for the user.
|
|||
/// </summary>
|
|||
public virtual string PhoneNumber { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets a flag indicating if a user has confirmed their telephone address.
|
|||
/// </summary>
|
|||
/// <value>True if the telephone number has been confirmed, otherwise false.</value>
|
|||
public virtual bool PhoneNumberConfirmed { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets a flag indicating if two factor authentication is enabled for this user.
|
|||
/// </summary>
|
|||
/// <value>True if 2fa is enabled, otherwise false.</value>
|
|||
public virtual bool TwoFactorEnabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the date and time, in UTC, when any user lockout ends.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// A value in the past means the user is not locked out.
|
|||
/// </remarks>
|
|||
public virtual DateTimeOffset? LockoutEnd { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets a flag indicating if the user could be locked out.
|
|||
/// </summary>
|
|||
/// <value>True if the user could be locked out, otherwise false.</value>
|
|||
public virtual bool LockoutEnabled { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the number of failed login attempts for the current user.
|
|||
/// </summary>
|
|||
public virtual int AccessFailedCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Navigation property for the roles this user belongs to.
|
|||
/// </summary>
|
|||
public virtual ICollection<IdentityUserRole> Roles { get; } = new Collection<IdentityUserRole>(); |
|||
|
|||
/// <summary>
|
|||
/// Navigation property for the claims this user possesses.
|
|||
/// </summary>
|
|||
public virtual ICollection<IdentityUserClaim> Claims { get; } = new Collection<IdentityUserClaim>(); |
|||
|
|||
/// <summary>
|
|||
/// Navigation property for this users login accounts.
|
|||
/// </summary>
|
|||
public virtual ICollection<IdentityUserLogin> Logins { get; } = new Collection<IdentityUserLogin>(); |
|||
|
|||
protected IdentityUser() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public IdentityUser([NotNull] string userName) |
|||
{ |
|||
Check.NotNull(userName, nameof(userName)); |
|||
|
|||
UserName = userName; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the username for this user.
|
|||
/// </summary>
|
|||
public override string ToString() |
|||
{ |
|||
return $"{base.ToString()} UserName = {UserName}"; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
using System.Security.Claims; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
/// <summary>
|
|||
/// Represents a claim that a user possesses.
|
|||
/// </summary>
|
|||
public class IdentityUserClaim : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the primary key of the user associated with this claim.
|
|||
/// </summary>
|
|||
public virtual string UserId { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the claim type for this claim.
|
|||
/// </summary>
|
|||
public virtual string ClaimType { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the claim value for this claim.
|
|||
/// </summary>
|
|||
public virtual string ClaimValue { get; protected set; } |
|||
|
|||
protected IdentityUserClaim() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public IdentityUserClaim([NotNull] string userId, [NotNull] Claim claim) |
|||
{ |
|||
Check.NotNull(userId, nameof(userId)); |
|||
Check.NotNull(claim, nameof(claim)); |
|||
|
|||
UserId = userId; |
|||
ClaimType = claim.Type; |
|||
ClaimValue = claim.Value; |
|||
} |
|||
|
|||
public IdentityUserClaim([NotNull] string userId, [NotNull] string claimType, string claimValue) |
|||
{ |
|||
Check.NotNull(userId, nameof(userId)); |
|||
Check.NotNull(claimType, nameof(claimType)); |
|||
|
|||
UserId = userId; |
|||
ClaimType = claimType; |
|||
ClaimValue = claimValue; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a Claim instance from this entity.
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public virtual Claim ToClaim() |
|||
{ |
|||
return new Claim(ClaimType, ClaimValue); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
/// <summary>
|
|||
/// Represents a login and its associated provider for a user.
|
|||
/// </summary>
|
|||
public class IdentityUserLogin : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the of the primary key of the user associated with this login.
|
|||
/// </summary>
|
|||
public virtual string UserId { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the login provider for the login (e.g. facebook, google)
|
|||
/// </summary>
|
|||
public virtual string LoginProvider { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the unique provider identifier for this login.
|
|||
/// </summary>
|
|||
public virtual string ProviderKey { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the friendly name used in a UI for this login.
|
|||
/// </summary>
|
|||
public virtual string ProviderDisplayName { get; protected set; } |
|||
|
|||
protected IdentityUserLogin() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public IdentityUserLogin([NotNull] string userId, [NotNull] string loginProvider, [NotNull] string providerKey, string providerDisplayName) |
|||
{ |
|||
Check.NotNull(userId, nameof(userId)); |
|||
Check.NotNull(loginProvider, nameof(loginProvider)); |
|||
Check.NotNull(providerKey, nameof(providerKey)); |
|||
|
|||
UserId = userId; |
|||
LoginProvider = loginProvider; |
|||
ProviderKey = providerKey; |
|||
ProviderDisplayName = providerDisplayName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
/// <summary>
|
|||
/// Represents the link between a user and a role.
|
|||
/// </summary>
|
|||
public class IdentityUserRole : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the primary key of the user that is linked to a role.
|
|||
/// </summary>
|
|||
public virtual string UserId { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the primary key of the role that is linked to the user.
|
|||
/// </summary>
|
|||
public virtual string RoleId { get; protected set; } |
|||
|
|||
protected IdentityUserRole() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public IdentityUserRole([NotNull] string userId, [NotNull] string roleId) |
|||
{ |
|||
Check.NotNull(userId, nameof(userId)); |
|||
Check.NotNull(roleId, nameof(roleId)); |
|||
|
|||
UserId = userId; |
|||
RoleId = roleId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
/// <summary>
|
|||
/// Represents an authentication token for a user.
|
|||
/// </summary>
|
|||
public class IdentityUserToken : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// Gets or sets the primary key of the user that the token belongs to.
|
|||
/// </summary>
|
|||
public virtual string UserId { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the LoginProvider this token is from.
|
|||
/// </summary>
|
|||
public virtual string LoginProvider { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the name of the token.
|
|||
/// </summary>
|
|||
public virtual string Name { get; protected set; } |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the token value.
|
|||
/// </summary>
|
|||
public virtual string Value { get; set; } |
|||
|
|||
protected IdentityUserToken() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public IdentityUserToken([NotNull] string userId, [NotNull] string loginProvider, [NotNull] string name, string value) //TODO: Can value be null?
|
|||
{ |
|||
Check.NotNull(userId, nameof(userId)); |
|||
Check.NotNull(loginProvider, nameof(loginProvider)); |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
UserId = userId; |
|||
LoginProvider = loginProvider; |
|||
Name = name; |
|||
Value = value; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue