1
0
mirror of https://github.com/bitwarden/server synced 2025-12-25 12:43:14 +00:00

[PM-1188] Server owner auth migration (#2825)

* [PM-1188] add sso project to auth

* [PM-1188] move sso api models to auth

* [PM-1188] fix sso api model namespace & imports

* [PM-1188] move core files to auth

* [PM-1188] fix core sso namespace & models

* [PM-1188] move sso repository files to auth

* [PM-1188] fix sso repo files namespace & imports

* [PM-1188] move sso sql files to auth folder

* [PM-1188] move sso test files to auth folders

* [PM-1188] fix sso tests namespace & imports

* [PM-1188] move auth api files to auth folder

* [PM-1188] fix auth api files namespace & imports

* [PM-1188] move auth core files to auth folder

* [PM-1188] fix auth core files namespace & imports

* [PM-1188] move auth email templates to auth folder

* [PM-1188] move auth email folder back into shared directory

* [PM-1188] fix auth email names

* [PM-1188] move auth core models to auth folder

* [PM-1188] fix auth model namespace & imports

* [PM-1188] add entire Identity project to auth codeowners

* [PM-1188] fix auth orm files namespace & imports

* [PM-1188] move auth orm files to auth folder

* [PM-1188] move auth sql files to auth folder

* [PM-1188] move auth tests to auth folder

* [PM-1188] fix auth test files namespace & imports

* [PM-1188] move emergency access api files to auth folder

* [PM-1188] fix emergencyaccess api files namespace & imports

* [PM-1188] move emergency access core files to auth folder

* [PM-1188] fix emergency access core files namespace & imports

* [PM-1188] move emergency access orm files to auth folder

* [PM-1188] fix emergency access orm files namespace & imports

* [PM-1188] move emergency access sql files to auth folder

* [PM-1188] move emergencyaccess test files to auth folder

* [PM-1188] fix emergency access test files namespace & imports

* [PM-1188] move captcha files to auth folder

* [PM-1188] fix captcha files namespace & imports

* [PM-1188] move auth admin files into auth folder

* [PM-1188] fix admin auth files namespace & imports
- configure mvc to look in auth folders for views

* [PM-1188] remove extra imports and formatting

* [PM-1188] fix ef auth model imports

* [PM-1188] fix DatabaseContextModelSnapshot paths

* [PM-1188] fix grant import in ef

* [PM-1188] update sqlproj

* [PM-1188] move missed sqlproj files

* [PM-1188] move auth ef models out of auth folder

* [PM-1188] fix auth ef models namespace

* [PM-1188] remove auth ef models unused imports

* [PM-1188] fix imports for auth ef models

* [PM-1188] fix more ef model imports

* [PM-1188] fix file encodings
This commit is contained in:
Jake Fink
2023-04-14 13:25:56 -04:00
committed by GitHub
parent 2529c5b36f
commit 88dd745070
332 changed files with 704 additions and 522 deletions

View File

@@ -1,12 +1,13 @@
using AutoMapper;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories;
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories;
public class AuthRequestRepository : Repository<Core.Entities.AuthRequest, AuthRequest, Guid>, IAuthRequestRepository
public class AuthRequestRepository : Repository<Core.Auth.Entities.AuthRequest, AuthRequest, Guid>, IAuthRequestRepository
{
public AuthRequestRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.AuthRequests)
@@ -23,13 +24,13 @@ public class AuthRequestRepository : Repository<Core.Entities.AuthRequest, AuthR
}
}
public async Task<ICollection<Core.Entities.AuthRequest>> GetManyByUserIdAsync(Guid userId)
public async Task<ICollection<Core.Auth.Entities.AuthRequest>> GetManyByUserIdAsync(Guid userId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var userAuthRequests = await dbContext.AuthRequests.Where(a => a.UserId.Equals(userId)).ToListAsync();
return Mapper.Map<List<Core.Entities.AuthRequest>>(userAuthRequests);
return Mapper.Map<List<Core.Auth.Entities.AuthRequest>>(userAuthRequests);
}
}
}

View File

@@ -1,15 +1,16 @@
using AutoMapper;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Auth.Enums;
using Bit.Core.Auth.Models.Data;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories;
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories;
public class EmergencyAccessRepository : Repository<Core.Entities.EmergencyAccess, EmergencyAccess, Guid>, IEmergencyAccessRepository
public class EmergencyAccessRepository : Repository<Core.Auth.Entities.EmergencyAccess, EmergencyAccess, Guid>, IEmergencyAccessRepository
{
public EmergencyAccessRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.EmergencyAccesses)
@@ -21,7 +22,7 @@ public class EmergencyAccessRepository : Repository<Core.Entities.EmergencyAcces
return await GetCountFromQuery(query);
}
public override async Task DeleteAsync(Core.Entities.EmergencyAccess emergencyAccess)
public override async Task DeleteAsync(Core.Auth.Entities.EmergencyAccess emergencyAccess)
{
using (var scope = ServiceScopeFactory.CreateScope())
{

View File

@@ -1,10 +1,11 @@
using AutoMapper;
using Bit.Core.Repositories;
using Bit.Core.Auth.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories;
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories;
public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
{
@@ -41,7 +42,7 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
}
}
public async Task<Core.Entities.Grant> GetByKeyAsync(string key)
public async Task<Core.Auth.Entities.Grant> GetByKeyAsync(string key)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
@@ -54,7 +55,7 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
}
}
public async Task<ICollection<Core.Entities.Grant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type)
public async Task<ICollection<Core.Auth.Entities.Grant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
@@ -66,11 +67,11 @@ public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
g.Type == type
select g;
var grants = await query.ToListAsync();
return (ICollection<Core.Entities.Grant>)grants;
return (ICollection<Core.Auth.Entities.Grant>)grants;
}
}
public async Task SaveAsync(Core.Entities.Grant obj)
public async Task SaveAsync(Core.Auth.Entities.Grant obj)
{
using (var scope = ServiceScopeFactory.CreateScope())
{

View File

@@ -1,6 +1,8 @@
using Bit.Core.Models.Data;
using Bit.Core.Auth.Models.Data;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries;
public class EmergencyAccessDetailsViewQuery : IQuery<EmergencyAccessDetails>
{

View File

@@ -1,6 +1,8 @@
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
namespace Bit.Infrastructure.EntityFramework.Auth.Repositories.Queries;
public class EmergencyAccessReadCountByGrantorIdEmailQuery : IQuery<EmergencyAccess>
{

View File

@@ -1,45 +1,45 @@
using AutoMapper;
using Bit.Core.Repositories;
using Bit.Core.Auth.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories;
public class SsoConfigRepository : Repository<Core.Entities.SsoConfig, SsoConfig, long>, ISsoConfigRepository
public class SsoConfigRepository : Repository<Core.Auth.Entities.SsoConfig, SsoConfig, long>, ISsoConfigRepository
{
public SsoConfigRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.SsoConfigs)
{ }
public async Task<Core.Entities.SsoConfig> GetByOrganizationIdAsync(Guid organizationId)
public async Task<Core.Auth.Entities.SsoConfig> GetByOrganizationIdAsync(Guid organizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var ssoConfig = await GetDbSet(dbContext).SingleOrDefaultAsync(sc => sc.OrganizationId == organizationId);
return Mapper.Map<Core.Entities.SsoConfig>(ssoConfig);
return Mapper.Map<Core.Auth.Entities.SsoConfig>(ssoConfig);
}
}
public async Task<Core.Entities.SsoConfig> GetByIdentifierAsync(string identifier)
public async Task<Core.Auth.Entities.SsoConfig> GetByIdentifierAsync(string identifier)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var ssoConfig = await GetDbSet(dbContext).SingleOrDefaultAsync(sc => sc.Organization.Identifier == identifier);
return Mapper.Map<Core.Entities.SsoConfig>(ssoConfig);
return Mapper.Map<Core.Auth.Entities.SsoConfig>(ssoConfig);
}
}
public async Task<ICollection<Core.Entities.SsoConfig>> GetManyByRevisionNotBeforeDate(DateTime? notBefore)
public async Task<ICollection<Core.Auth.Entities.SsoConfig>> GetManyByRevisionNotBeforeDate(DateTime? notBefore)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var ssoConfigs = await GetDbSet(dbContext).Where(sc => sc.Enabled && sc.RevisionDate >= notBefore).ToListAsync();
return Mapper.Map<List<Core.Entities.SsoConfig>>(ssoConfigs);
return Mapper.Map<List<Core.Auth.Entities.SsoConfig>>(ssoConfigs);
}
}
}

View File

@@ -1,12 +1,12 @@
using AutoMapper;
using Bit.Core.Repositories;
using Bit.Core.Auth.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories;
public class SsoUserRepository : Repository<Core.Entities.SsoUser, SsoUser, long>, ISsoUserRepository
public class SsoUserRepository : Repository<Core.Auth.Entities.SsoUser, SsoUser, long>, ISsoUserRepository
{
public SsoUserRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.SsoUsers)
@@ -23,7 +23,7 @@ public class SsoUserRepository : Repository<Core.Entities.SsoUser, SsoUser, long
}
}
public async Task<Core.Entities.SsoUser> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId)
public async Task<Core.Auth.Entities.SsoUser> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{

View File

@@ -1,7 +1,9 @@
using Bit.Core.Enums;
using Bit.Core.Auth.Repositories;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Core.SecretsManager.Repositories;
using Bit.Core.Vault.Repositories;
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.SecretsManager.Repositories;
using Bit.Infrastructure.EntityFramework.Vault.Repositories;

View File

@@ -2,7 +2,7 @@
namespace Bit.Infrastructure.EntityFramework.Models;
public class AuthRequest : Core.Entities.AuthRequest
public class AuthRequest : Core.Auth.Entities.AuthRequest
{
public virtual User User { get; set; }
public virtual Device ResponseDevice { get; set; }
@@ -12,6 +12,6 @@ public class AuthRequestMapperProfile : Profile
{
public AuthRequestMapperProfile()
{
CreateMap<Core.Entities.AuthRequest, AuthRequest>().ReverseMap();
CreateMap<Core.Auth.Entities.AuthRequest, AuthRequest>().ReverseMap();
}
}

View File

@@ -2,7 +2,7 @@
namespace Bit.Infrastructure.EntityFramework.Models;
public class EmergencyAccess : Core.Entities.EmergencyAccess
public class EmergencyAccess : Core.Auth.Entities.EmergencyAccess
{
public virtual User Grantee { get; set; }
public virtual User Grantor { get; set; }
@@ -12,6 +12,6 @@ public class EmergencyAccessMapperProfile : Profile
{
public EmergencyAccessMapperProfile()
{
CreateMap<Core.Entities.EmergencyAccess, EmergencyAccess>().ReverseMap();
CreateMap<Core.Auth.Entities.EmergencyAccess, EmergencyAccess>().ReverseMap();
}
}

View File

@@ -2,7 +2,7 @@
namespace Bit.Infrastructure.EntityFramework.Models;
public class Grant : Core.Entities.Grant
public class Grant : Core.Auth.Entities.Grant
{
}
@@ -10,6 +10,6 @@ public class GrantMapperProfile : Profile
{
public GrantMapperProfile()
{
CreateMap<Core.Entities.Grant, Grant>().ReverseMap();
CreateMap<Core.Auth.Entities.Grant, Grant>().ReverseMap();
}
}

View File

@@ -2,7 +2,7 @@
namespace Bit.Infrastructure.EntityFramework.Models;
public class SsoConfig : Core.Entities.SsoConfig
public class SsoConfig : Core.Auth.Entities.SsoConfig
{
public virtual Organization Organization { get; set; }
}
@@ -11,6 +11,6 @@ public class SsoConfigMapperProfile : Profile
{
public SsoConfigMapperProfile()
{
CreateMap<Core.Entities.SsoConfig, SsoConfig>().ReverseMap();
CreateMap<Core.Auth.Entities.SsoConfig, SsoConfig>().ReverseMap();
}
}

View File

@@ -2,7 +2,7 @@
namespace Bit.Infrastructure.EntityFramework.Models;
public class SsoUser : Core.Entities.SsoUser
public class SsoUser : Core.Auth.Entities.SsoUser
{
public virtual Organization Organization { get; set; }
public virtual User User { get; set; }
@@ -12,6 +12,6 @@ public class SsoUserMapperProfile : Profile
{
public SsoUserMapperProfile()
{
CreateMap<Core.Entities.SsoUser, SsoUser>().ReverseMap();
CreateMap<Core.Auth.Entities.SsoUser, SsoUser>().ReverseMap();
}
}

View File

@@ -1,4 +1,5 @@
using Bit.Core.Enums;
using Bit.Core.Auth.Enums;
using Bit.Core.Enums;
using Bit.Core.Enums.Provider;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
using Microsoft.EntityFrameworkCore;