Browse Source

identity server claim types refactor

pull/736/head
Yunus Emre Kalkan 8 years ago
parent
commit
2707a1ee4b
  1. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  2. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs
  3. 5
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs
  4. 8
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs
  5. 7
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs
  6. 36
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  7. 34
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs
  8. 18
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  9. 18
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

6
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -22,12 +22,6 @@ namespace Volo.Abp.Identity
CancellationToken cancellationToken = default
);
Task UpdateClaimsAsync(Guid id, List<IdentityRoleClaim> claims);
Task<List<IdentityRoleClaim>> GetClaimsAsync(
Guid id,
CancellationToken cancellationToken = default);
Task<long> GetCountAsync(
CancellationToken cancellationToken = default
);

6
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs

@ -40,8 +40,6 @@ namespace Volo.Abp.Identity
CancellationToken cancellationToken = default
);
Task UpdateClaimsAsync(Guid id, List<IdentityUserClaim> claims);
Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync(
string normalizedRoleName,
bool includeDetails = false,
@ -63,10 +61,6 @@ namespace Volo.Abp.Identity
CancellationToken cancellationToken = default
);
Task<List<IdentityUserClaim>> GetClaimsAsync(
Guid id,
CancellationToken cancellationToken = default);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default

5
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs

@ -20,6 +20,11 @@ namespace Volo.Abp.Identity
/// </summary>
public virtual string ClaimValue { get; protected set; }
public virtual bool Equals([NotNull] string claimType, [NotNull] string claimValue)
{
return ClaimType == claimType && ClaimValue == claimValue;
}
protected IdentityClaim()
{

8
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Security.Claims;
using JetBrains.Annotations;
using Volo.Abp.Auditing;
@ -85,6 +86,13 @@ namespace Volo.Abp.Identity
}
}
public virtual IdentityRoleClaim FindClaim([NotNull] Claim claim)
{
Check.NotNull(claim, nameof(claim));
return Claims.FirstOrDefault(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value);
}
public virtual void RemoveClaim([NotNull] Claim claim)
{
Check.NotNull(claim, nameof(claim));

7
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs

@ -201,6 +201,13 @@ namespace Volo.Abp.Identity
}
}
public virtual IdentityUserClaim FindClaim([NotNull] Claim claim)
{
Check.NotNull(claim, nameof(claim));
return Claims.FirstOrDefault(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value);
}
public virtual void ReplaceClaim([NotNull] Claim claim, [NotNull] Claim newClaim)
{
Check.NotNull(claim, nameof(claim));

36
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs

@ -13,12 +13,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
public class EfCoreIdentityRoleRepository : EfCoreRepository<IIdentityDbContext, IdentityRole, Guid>, IIdentityRoleRepository
{
private readonly IGuidGenerator _guidGenerator;
public EfCoreIdentityRoleRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider, IGuidGenerator guidGenerator)
public EfCoreIdentityRoleRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
: base(dbContextProvider)
{
_guidGenerator = guidGenerator;
}
public virtual async Task<IdentityRole> FindByNormalizedNameAsync(
@ -45,37 +42,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task UpdateClaimsAsync(Guid id, List<IdentityRoleClaim> claims)
{
var dbSet = DbContext.Set<IdentityRoleClaim>();
var oldClaims = dbSet.Where(c => c.RoleId == id).ToList();
foreach (var oldClaim in oldClaims)
{
dbSet.Remove(oldClaim);
}
foreach (var claim in claims)
{
dbSet.Add(new IdentityRoleClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id));
}
}
public async Task<List<IdentityRoleClaim>> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default)
{
var query = from roleClaim in DbContext.Set<IdentityRoleClaim>()
where roleClaim.RoleId == id
select roleClaim;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await this.LongCountAsync(GetCancellationToken(cancellationToken));
}
public override IQueryable<IdentityRole> WithDetails()
{
return GetQueryable().IncludeDetails();

34
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

@ -8,18 +8,14 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Guids;
namespace Volo.Abp.Identity.EntityFrameworkCore
{
public class EfCoreIdentityUserRepository : EfCoreRepository<IIdentityDbContext, IdentityUser, Guid>, IIdentityUserRepository
{
private readonly IGuidGenerator _guidGenerator;
public EfCoreIdentityUserRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider, IGuidGenerator guidGenerator)
public EfCoreIdentityUserRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
: base(dbContextProvider)
{
_guidGenerator = guidGenerator;
}
public virtual async Task<IdentityUser> FindByNormalizedUserNameAsync(
@ -134,34 +130,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<IdentityUserClaim>> GetClaimsAsync(
Guid id,
CancellationToken cancellationToken = default)
{
var query = from userClaim in DbContext.Set<IdentityUserClaim>()
where userClaim.UserId == id
select userClaim;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task UpdateClaimsAsync(Guid id, List<IdentityUserClaim> claims)
{
var dbSet = DbContext.Set<IdentityUserClaim>();
var oldClaims = dbSet.Where(c => c.UserId == id).ToList();
foreach (var oldClaim in oldClaims)
{
dbSet.Remove(oldClaim);
}
foreach (var claim in claims)
{
dbSet.Add(new IdentityUserClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id));
}
}
public virtual async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default)

18
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -44,24 +44,6 @@ namespace Volo.Abp.Identity.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task UpdateClaimsAsync(Guid id, List<IdentityRoleClaim> claims)
{
var role = await GetAsync(id);
role.Claims.Clear();
foreach (var claim in claims)
{
role.Claims.Add(new IdentityRoleClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id));
}
}
public async Task<List<IdentityRoleClaim>> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default)
{
var role = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
return role.Claims.ToList();
}
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()

18
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

@ -121,24 +121,6 @@ namespace Volo.Abp.Identity.MongoDB
return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<IdentityUserClaim>> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default)
{
var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
return user.Claims.ToList();
}
public async Task UpdateClaimsAsync(Guid id, List<IdentityUserClaim> claims)
{
var user = await GetAsync(id);
user.Claims.Clear();
foreach (var claim in claims)
{
user.Claims.Add(new IdentityUserClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id));
}
}
public async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default)

Loading…
Cancel
Save