From b3a671d8ce7cef56ed35e190ffab39b149a53b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 31 Jan 2018 16:46:53 +0300 Subject: [PATCH] Extract abstract IdentityClaim class. --- .../Volo/Abp/Identity/IdentityClaim.cs | 57 +++++++++++++++++++ .../Volo/Abp/Identity/IdentityRoleClaim.cs | 32 ++--------- .../Volo/Abp/Identity/IdentityUserClaim.cs | 41 ++----------- 3 files changed, 66 insertions(+), 64 deletions(-) create mode 100644 src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs new file mode 100644 index 0000000000..5114d64446 --- /dev/null +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs @@ -0,0 +1,57 @@ +using System; +using System.Security.Claims; +using JetBrains.Annotations; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.Identity +{ + public abstract class IdentityClaim : Entity + { + /// + /// Gets or sets the claim type for this claim. + /// + public virtual string ClaimType { get; protected set; } + + /// + /// Gets or sets the claim value for this claim. + /// + public virtual string ClaimValue { get; protected set; } + + protected IdentityClaim() + { + + } + + protected internal IdentityClaim(Guid id, [NotNull] Claim claim) + : this(id, claim.Type, claim.Value) + { + + } + + protected internal IdentityClaim(Guid id, [NotNull] string claimType, string claimValue) + { + Check.NotNull(claimType, nameof(claimType)); + + Id = id; + ClaimType = claimType; + ClaimValue = claimValue; + } + + /// + /// Creates a Claim instance from this entity. + /// + /// + public virtual Claim ToClaim() + { + return new Claim(ClaimType, ClaimValue); + } + + public virtual void SetClaim([NotNull] Claim claim) + { + Check.NotNull(claim, nameof(claim)); + + ClaimType = claim.Type; + ClaimValue = claim.Value; + } + } +} diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs index ec659f3f03..716d5b52b6 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs @@ -1,58 +1,34 @@ using System; using System.Security.Claims; using JetBrains.Annotations; -using Volo.Abp.Domain.Entities; namespace Volo.Abp.Identity { /// /// Represents a claim that is granted to all users within a role. /// - public class IdentityRoleClaim : Entity + public class IdentityRoleClaim : IdentityClaim { /// /// Gets or sets the of the primary key of the role associated with this claim. /// public virtual Guid RoleId { get; protected set; } - /// - /// Gets or sets the claim type for this claim. - /// - public virtual string ClaimType { get; protected set; } - - /// - /// Gets or sets the claim value for this claim. - /// - public virtual string ClaimValue { get; protected set; } - protected IdentityRoleClaim() { } protected internal IdentityRoleClaim(Guid id, Guid roleId, [NotNull] Claim claim) - : this(id, roleId, claim.Type, claim.Value) + : base(id, claim) { - + RoleId = roleId; } protected internal IdentityRoleClaim(Guid id, Guid roleId, [NotNull] string claimType, string claimValue) + : base(id, claimType, claimValue) { - Check.NotNull(claimType, nameof(claimType)); - - Id = id; RoleId = roleId; - ClaimType = claimType; - ClaimValue = claimValue; - } - - /// - /// Constructs a new claim with the type and value. - /// - /// - public virtual Claim ToClaim() - { - return new Claim(ClaimType, ClaimValue); } } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs index 4129034547..655f95f637 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs @@ -1,66 +1,35 @@ using System; using System.Security.Claims; using JetBrains.Annotations; -using Volo.Abp.Domain.Entities; namespace Volo.Abp.Identity { /// /// Represents a claim that a user possesses. /// - public class IdentityUserClaim : Entity + public class IdentityUserClaim : IdentityClaim { /// /// Gets or sets the primary key of the user associated with this claim. /// public virtual Guid UserId { get; protected set; } - /// - /// Gets or sets the claim type for this claim. - /// - public virtual string ClaimType { get; protected set; } - - /// - /// Gets or sets the claim value for this claim. - /// - public virtual string ClaimValue { get; protected set; } - protected IdentityUserClaim() { - + } protected internal IdentityUserClaim(Guid id, Guid userId, [NotNull] Claim claim) - : this(id, userId, claim.Type, claim.Value) + : base(id, claim) { + UserId = userId; } protected internal IdentityUserClaim(Guid id, Guid userId, [NotNull] string claimType, string claimValue) + : base(id, claimType, claimValue) { - Check.NotNull(claimType, nameof(claimType)); - - Id = id; UserId = userId; - ClaimType = claimType; - ClaimValue = claimValue; - } - - /// - /// Creates a Claim instance from this entity. - /// - /// - public virtual Claim ToClaim() - { - return new Claim(ClaimType, ClaimValue); - } - - public void SetClaim([NotNull] Claim claim) - { - Check.NotNull(claim, nameof(claim)); - - ClaimType = claim.Type; - ClaimValue = claim.Value; } } } \ No newline at end of file