Browse Source

Create Identity entities #16

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent
commit
81e121f9cb
  1. 7
      src/Volo.Abp.Identity/Volo.Abp.Identity.xproj
  2. 65
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRole.cs
  3. 61
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleClaim.cs
  4. 126
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs
  5. 61
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserClaim.cs
  6. 48
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserLogin.cs
  7. 35
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserRole.cs
  8. 48
      src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserToken.cs
  9. 3
      src/Volo.Abp.Identity/project.json
  10. 15
      src/Volo.Abp/Volo/Abp/Domain/Entities/Entity.cs
  11. 13
      src/Volo.Abp/Volo/Abp/Domain/Entities/IEntity.cs

7
src/Volo.Abp.Identity/Volo.Abp.Identity.xproj

@ -4,18 +4,17 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>17dbb40a-243e-41f7-a672-fa316ecb1e33</ProjectGuid>
<RootNamespace>Volo.Abp.Identity</RootNamespace>
<RootNamespace>
</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>

65
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRole.cs

@ -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;
}
}
}

61
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityRoleClaim.cs

@ -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);
}
}
}

126
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUser.cs

@ -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}";
}
}
}

61
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserClaim.cs

@ -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);
}
}
}

48
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserLogin.cs

@ -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;
}
}
}

35
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserRole.cs

@ -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;
}
}
}

48
src/Volo.Abp.Identity/Volo/Abp/Identity/IdentityUserToken.cs

@ -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;
}
}
}

3
src/Volo.Abp.Identity/project.json

@ -3,7 +3,8 @@
"dependencies": {
"NETStandard.Library": "1.6.1",
"Microsoft.AspNetCore.Identity": "1.1.0"
"Microsoft.AspNetCore.Identity": "1.1.0",
"Volo.Abp": "1.0.0-*"
},
"frameworks": {

15
src/Volo.Abp/Volo/Abp/Domain/Entities/Entity.cs

@ -4,14 +4,13 @@ using System.Reflection;
namespace Volo.Abp.Domain.Entities
{
//TODO: Think on Entity class without PK
///// <summary>
///// A shortcut of <see cref="Entity{TPrimaryKey}"/> for most used primary key type (<see cref="int"/>).
///// </summary>
//public abstract class Entity : Entity<string>, IEntity<>
//{
//}
/// <summary>
/// A shortcut of <see cref="Entity{TPrimaryKey}"/> for default primary key type (<see cref="string"/>).
/// </summary>
public abstract class Entity : Entity<string>, IEntity
{
}
/// <summary>
/// Basic implementation of IEntity interface.

13
src/Volo.Abp/Volo/Abp/Domain/Entities/IEntity.cs

@ -1,13 +1,12 @@
namespace Volo.Abp.Domain.Entities
{
//TODO: Think on Entity class without PK
///// <summary>
///// A shortcut of <see cref="IEntity{TPrimaryKey}"/> for most used primary key type (<see cref="int"/>).
///// </summary>
//public interface IEntity : IEntity<int>
//{
/// <summary>
/// A shortcut of <see cref="IEntity{TPrimaryKey}"/> for default primary key type (<see cref="string"/>).
/// </summary>
public interface IEntity : IEntity<string>
{
//}
}
/// <summary>
/// Defines interface for base entity type. All entities in the system must implement this interface.

Loading…
Cancel
Save