Browse Source

Extract abstract IdentityClaim class.

pull/206/head
Halil İbrahim Kalkan 8 years ago
parent
commit
b3a671d8ce
  1. 57
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs
  2. 32
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs
  3. 41
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserClaim.cs

57
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<Guid>
{
/// <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 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;
}
/// <summary>
/// Creates a Claim instance from this entity.
/// </summary>
/// <returns></returns>
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;
}
}
}

32
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
{
/// <summary>
/// Represents a claim that is granted to all users within a role.
/// </summary>
public class IdentityRoleClaim : Entity<Guid>
public class IdentityRoleClaim : IdentityClaim
{
/// <summary>
/// Gets or sets the of the primary key of the role associated with this claim.
/// </summary>
public virtual Guid 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()
{
}
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;
}
/// <summary>
/// Constructs a new claim with the type and value.
/// </summary>
/// <returns></returns>
public virtual Claim ToClaim()
{
return new Claim(ClaimType, ClaimValue);
}
}
}

41
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
{
/// <summary>
/// Represents a claim that a user possesses.
/// </summary>
public class IdentityUserClaim : Entity<Guid>
public class IdentityUserClaim : IdentityClaim
{
/// <summary>
/// Gets or sets the primary key of the user associated with this claim.
/// </summary>
public virtual Guid 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()
{
}
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;
}
/// <summary>
/// Creates a Claim instance from this entity.
/// </summary>
/// <returns></returns>
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;
}
}
}
Loading…
Cancel
Save