Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(certificate): db enablement company certificates #475

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ValueTask<List<IdentityProviderDetails>> GetOwnCompanyIdentityProviderDet
public async ValueTask<ActionResult<IdentityProviderDetails>> CreateOwnCompanyIdentityProvider([FromQuery] IamIdentityProviderProtocol protocol, [FromQuery] IdentityProviderTypeId typeId, [FromQuery] string? displayName = null)
{
var details = await _businessLogic.CreateOwnCompanyIdentityProviderAsync(protocol, typeId, displayName).ConfigureAwait(false);
return (ActionResult<IdentityProviderDetails>)CreatedAtRoute(nameof(GetOwnCompanyIdentityProvider), new { identityProviderId = details.identityProviderId }, details);
return (ActionResult<IdentityProviderDetails>)CreatedAtRoute(nameof(GetOwnCompanyIdentityProvider), new { identityProviderId = details.IdentityProviderId }, details);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;

public record IdentityProviderDetails(Guid identityProviderId, string? alias, IdentityProviderCategoryId identityProviderCategoryId, IdentityProviderTypeId IdentityProviderTypeId, string? displayName, string? redirectUrl, bool? enabled, IEnumerable<IdentityProviderMapperModel>? mappers)
public record IdentityProviderDetails(Guid IdentityProviderId, string? Alias, IdentityProviderCategoryId IdentityProviderCategoryId, IdentityProviderTypeId IdentityProviderTypeId, string? DisplayName, string? RedirectUrl, bool? Enabled, IEnumerable<IdentityProviderMapperModel>? Mappers)
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IdentityProviderDetailsOidc? oidc { get; init; } = null;
public IdentityProviderDetailsOidc? Oidc { get; init; } = null;

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IdentityProviderDetailsSaml? saml { get; init; } = null;
public IdentityProviderDetailsSaml? Saml { get; init; } = null;
}

public record IdentityProviderDetailsOidc(string authorizationUrl, string clientId, IamIdentityProviderClientAuthMethod clientAuthMethod)
public record IdentityProviderDetailsOidc(string? MetadataUrl, string AuthorizationUrl, string TokenUrl, string? LogoutUrl, string ClientId, bool HasClientSecret, IamIdentityProviderClientAuthMethod ClientAuthMethod)
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IamIdentityProviderSignatureAlgorithm? signatureAlgorithm { get; init; } = null;
public IamIdentityProviderSignatureAlgorithm? SignatureAlgorithm { get; init; } = null;
}

public record IdentityProviderDetailsSaml(string serviceProviderEntityId, string singleSignOnServiceUrl);
public record IdentityProviderDetailsSaml(string ServiceProviderEntityId, string SingleSignOnServiceUrl);
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@

namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models;

public record IdentityProviderEditableDetails(string displayName)
public record IdentityProviderEditableDetails(string DisplayName)
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IdentityProviderEditableDetailsOidc? oidc { get; init; } = null;
public IdentityProviderEditableDetailsOidc? Oidc { get; init; } = null;

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IdentityProviderEditableDetailsSaml? saml { get; init; } = null;
public IdentityProviderEditableDetailsSaml? Saml { get; init; } = null;
}

public record IdentityProviderEditableDetailsOidc(string metadataUrl, IamIdentityProviderClientAuthMethod clientAuthMethod, string clientId)
public record IdentityProviderEditableDetailsOidc(string MetadataUrl, IamIdentityProviderClientAuthMethod ClientAuthMethod, string ClientId)
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? secret { get; init; } = null;
public string? Secret { get; init; } = null;

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IamIdentityProviderSignatureAlgorithm? signatureAlgorithm { get; init; } = null;
public IamIdentityProviderSignatureAlgorithm? SignatureAlgorithm { get; init; } = null;
}

public record IdentityProviderEditableDetailsSaml(string serviceProviderEntityId, string singleSignOnServiceUrl);
public record IdentityProviderEditableDetailsSaml(string ServiceProviderEntityId, string SingleSignOnServiceUrl);
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ public interface IIdentityProviderRepository
void DeleteIdentityProvider(Guid identityProviderId);
IamIdentityProvider CreateIamIdentityProvider(Guid identityProviderId, string idpAlias);
void DeleteIamIdentityProvider(string idpAlias);
void AttachAndModifyIamIdentityProvider(string idpAlias, Action<IamIdentityProvider>? initialize, Action<IamIdentityProvider> modify);
CompanyIdentityProvider CreateCompanyIdentityProvider(Guid companyId, Guid identityProviderId);
void DeleteCompanyIdentityProvider(Guid companyId, Guid identityProviderId);
void CreateCompanyIdentityProviders(IEnumerable<(Guid CompanyId, Guid IdentityProviderId)> companyIdIdentityProviderIds);
Task<string?> GetSharedIdentityProviderIamAliasDataUntrackedAsync(Guid companyId);
Task<(string? Alias, bool IsValidUser)> GetIdpCategoryIdByUserIdAsync(Guid companyUserId, Guid userCompanyId);
Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnOrOwnerCompany, IdentityProviderTypeId TypeId)> GetOwnCompanyIdentityProviderAliasUntrackedAsync(Guid identityProviderId, Guid companyId);
Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnerCompany, IdentityProviderTypeId TypeId, IEnumerable<ConnectedCompanyData> ConnectedCompanies)> GetOwnIdentityProviderWithConnectedCompanies(Guid identityProviderId, Guid companyId);
Task<(bool IsOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase, bool CompanyUsersLinked, string IdpOwnerName)> GetOwnCompanyIdentityProviderUpdateDataUntrackedAsync(Guid identityProviderId, Guid companyId, bool queryAliase);
IAsyncEnumerable<(Guid IdentityProviderId, IdentityProviderCategoryId CategoryId, string? Alias, IdentityProviderTypeId TypeId)> GetCompanyIdentityProviderCategoryDataUntracked(Guid companyId);
Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnOrOwnerCompany, IdentityProviderTypeId TypeId, string? MetadataUrl)> GetOwnCompanyIdentityProviderAliasUntrackedAsync(Guid identityProviderId, Guid companyId);
Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnerCompany, IdentityProviderTypeId TypeId, string? MetadataUrl, IEnumerable<ConnectedCompanyData> ConnectedCompanies)> GetOwnIdentityProviderWithConnectedCompanies(Guid identityProviderId, Guid companyId);
Task<(bool IsOwner, (string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, string? MetadataUrl) IdentityProviderData, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase, bool CompanyUsersLinked, string IdpOwnerName)> GetOwnCompanyIdentityProviderStatusUpdateData(Guid identityProviderId, Guid companyId, bool queryAliase);
Task<(bool IsOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, string? MetadataUrl)> GetOwnCompanyIdentityProviderUpdateData(Guid identityProviderId, Guid companyId);
Task<(bool IsOwner, string? Alias, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)> CompanyIdAliase, string IdpOwnerName)> GetOwnCompanyIdentityProviderUpdateDataForDelete(Guid identityProviderId, Guid companyId);
IAsyncEnumerable<(Guid IdentityProviderId, IdentityProviderCategoryId CategoryId, string? Alias, IdentityProviderTypeId TypeId, string? MetadataUrl)> GetCompanyIdentityProviderCategoryDataUntracked(Guid companyId);
IAsyncEnumerable<(Guid IdentityProviderId, string Alias)> GetOwnCompanyIdentityProviderAliasDataUntracked(Guid companyId, IEnumerable<Guid> identityProviderIds);
Task<(Guid IdentityProviderId, string? Alias)> GetSingleManagedIdentityProviderAliasDataUntracked(Guid companyId);
IAsyncEnumerable<(Guid IdentityProviderId, string? Alias)> GetManagedIdentityProviderAliasDataUntracked(Guid companyId, IEnumerable<Guid> identityProviderIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public IamIdentityProvider CreateIamIdentityProvider(Guid identityProviderId, st
public void DeleteIamIdentityProvider(string idpAlias) =>
_context.IamIdentityProviders.Remove(new IamIdentityProvider(idpAlias, Guid.Empty));

public void AttachAndModifyIamIdentityProvider(string idpAlias, Action<IamIdentityProvider>? initialize, Action<IamIdentityProvider> modify)
{
var iamIdentityProvider = new IamIdentityProvider(idpAlias, Guid.Empty);
initialize?.Invoke(iamIdentityProvider);
_context.Attach(iamIdentityProvider);
modify(iamIdentityProvider);
}

public Task<string?> GetSharedIdentityProviderIamAliasDataUntrackedAsync(Guid companyId) =>
_context.IdentityProviders
.AsNoTracking()
Expand All @@ -104,61 +112,96 @@ public void DeleteIamIdentityProvider(string idpAlias) =>
true))
.SingleOrDefaultAsync();

public Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnOrOwnerCompany, IdentityProviderTypeId TypeId)> GetOwnCompanyIdentityProviderAliasUntrackedAsync(Guid identityProviderId, Guid companyId) =>
public Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnOrOwnerCompany, IdentityProviderTypeId TypeId, string? MetadataUrl)> GetOwnCompanyIdentityProviderAliasUntrackedAsync(Guid identityProviderId, Guid companyId) =>
_context.IdentityProviders
.Where(identityProvider => identityProvider.Id == identityProviderId)
.Select(identityProvider =>
new ValueTuple<string?, IdentityProviderCategoryId, bool, IdentityProviderTypeId>(
new ValueTuple<string?, IdentityProviderCategoryId, bool, IdentityProviderTypeId, string?>(
identityProvider.IamIdentityProvider!.IamIdpAlias,
identityProvider.IdentityProviderCategoryId,
identityProvider.OwnerId == companyId || identityProvider.Companies.Any(company => company.Id == companyId),
identityProvider.IdentityProviderTypeId))
identityProvider.IdentityProviderTypeId,
identityProvider.IamIdentityProvider.MetadataUrl))
.SingleOrDefaultAsync();

public Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnerCompany, IdentityProviderTypeId TypeId, IEnumerable<ConnectedCompanyData> ConnectedCompanies)> GetOwnIdentityProviderWithConnectedCompanies(Guid identityProviderId, Guid companyId) =>
public Task<(string? Alias, IdentityProviderCategoryId IamIdentityProviderCategory, bool IsOwnerCompany, IdentityProviderTypeId TypeId, string? MetadataUrl, IEnumerable<ConnectedCompanyData> ConnectedCompanies)> GetOwnIdentityProviderWithConnectedCompanies(Guid identityProviderId, Guid companyId) =>
_context.IdentityProviders
.Where(identityProvider => identityProvider.Id == identityProviderId)
.Select(identityProvider =>
new ValueTuple<string?, IdentityProviderCategoryId, bool, IdentityProviderTypeId, IEnumerable<ConnectedCompanyData>>(
new ValueTuple<string?, IdentityProviderCategoryId, bool, IdentityProviderTypeId, string?, IEnumerable<ConnectedCompanyData>>(
identityProvider.IamIdentityProvider!.IamIdpAlias,
identityProvider.IdentityProviderCategoryId,
identityProvider.OwnerId == companyId,
identityProvider.IdentityProviderTypeId,
identityProvider.Companies.Select(c => new ConnectedCompanyData(c.Id, c.Name))
))
identityProvider.IamIdentityProvider.MetadataUrl,
identityProvider.Companies.Select(c => new ConnectedCompanyData(c.Id, c.Name))))
.SingleOrDefaultAsync();

public Task<(bool IsOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase, bool CompanyUsersLinked, string IdpOwnerName)> GetOwnCompanyIdentityProviderUpdateDataUntrackedAsync(Guid identityProviderId, Guid companyId, bool queryAliase) =>
public Task<(bool IsOwner, (string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, string? MetadataUrl) IdentityProviderData, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)>? CompanyIdAliase, bool CompanyUsersLinked, string IdpOwnerName)> GetOwnCompanyIdentityProviderStatusUpdateData(Guid identityProviderId, Guid companyId, bool queryAliase) =>
_context.IdentityProviders
.Where(identityProvider => identityProvider.Id == identityProviderId)
.Select(identityProvider =>
new ValueTuple<bool, string?, IdentityProviderCategoryId, IdentityProviderTypeId, IEnumerable<(Guid, IEnumerable<string>)>?, bool, string>(
new ValueTuple<bool, (string?, IdentityProviderCategoryId, IdentityProviderTypeId, string?), IEnumerable<(Guid, IEnumerable<string>)>?, bool, string>(
identityProvider.OwnerId == companyId,
new ValueTuple<string?, IdentityProviderCategoryId, IdentityProviderTypeId, string?>(
identityProvider.IamIdentityProvider!.IamIdpAlias,
identityProvider.IdentityProviderCategoryId,
identityProvider.IdentityProviderTypeId,
identityProvider.IamIdentityProvider.MetadataUrl),
queryAliase
? identityProvider.Companies
.Select(c => new ValueTuple<Guid, IEnumerable<string>>(
c.Id,
c.IdentityProviders
.Where(i => i.IamIdentityProvider != null)
.Select(i => i.IamIdentityProvider!.IamIdpAlias)))
: null,
identityProvider.CompanyUserAssignedIdentityProviders.Any(),
identityProvider.Owner!.Name
))
.SingleOrDefaultAsync();

public Task<(bool IsOwner, string? Alias, IdentityProviderCategoryId IdentityProviderCategory, IdentityProviderTypeId IdentityProviderTypeId, string? MetadataUrl)> GetOwnCompanyIdentityProviderUpdateData(Guid identityProviderId, Guid companyId) =>
_context.IdentityProviders
.Where(identityProvider => identityProvider.Id == identityProviderId)
.Select(identityProvider =>
new ValueTuple<bool, string?, IdentityProviderCategoryId, IdentityProviderTypeId, string?>(
identityProvider.OwnerId == companyId,
identityProvider.IamIdentityProvider!.IamIdpAlias,
identityProvider.IdentityProviderCategoryId,
identityProvider.IdentityProviderTypeId,
queryAliase
? identityProvider.Companies
.Select(c => new ValueTuple<Guid, IEnumerable<string>>(
c.Id,
c.IdentityProviders
.Where(i => i.IamIdentityProvider != null)
.Select(i => i.IamIdentityProvider!.IamIdpAlias)))
: null,
identityProvider.CompanyUserAssignedIdentityProviders.Any(),
identityProvider.IamIdentityProvider.MetadataUrl
))
.SingleOrDefaultAsync();

public Task<(bool IsOwner, string? Alias, IdentityProviderTypeId IdentityProviderTypeId, IEnumerable<(Guid CompanyId, IEnumerable<string> Aliase)> CompanyIdAliase, string IdpOwnerName)> GetOwnCompanyIdentityProviderUpdateDataForDelete(Guid identityProviderId, Guid companyId) =>
_context.IdentityProviders
.Where(identityProvider => identityProvider.Id == identityProviderId)
.Select(identityProvider =>
new ValueTuple<bool, string?, IdentityProviderTypeId, IEnumerable<(Guid, IEnumerable<string>)>, string>(
identityProvider.OwnerId == companyId,
identityProvider.IamIdentityProvider!.IamIdpAlias,
identityProvider.IdentityProviderTypeId,
identityProvider.Companies
.Select(c => new ValueTuple<Guid, IEnumerable<string>>(
c.Id,
c.IdentityProviders
.Where(i => i.IamIdentityProvider != null)
.Select(i => i.IamIdentityProvider!.IamIdpAlias))),
identityProvider.Owner!.Name
))
.SingleOrDefaultAsync();

public IAsyncEnumerable<(Guid IdentityProviderId, IdentityProviderCategoryId CategoryId, string? Alias, IdentityProviderTypeId TypeId)> GetCompanyIdentityProviderCategoryDataUntracked(Guid companyId) =>
public IAsyncEnumerable<(Guid IdentityProviderId, IdentityProviderCategoryId CategoryId, string? Alias, IdentityProviderTypeId TypeId, string? MetadataUrl)> GetCompanyIdentityProviderCategoryDataUntracked(Guid companyId) =>
_context.IdentityProviders
.AsNoTracking()
.Where(identityProvider => identityProvider.OwnerId == companyId || identityProvider.Companies.Any(company => company.Id == companyId))
.Select(identityProvider => new ValueTuple<Guid, IdentityProviderCategoryId, string?, IdentityProviderTypeId>(
.Select(identityProvider => new ValueTuple<Guid, IdentityProviderCategoryId, string?, IdentityProviderTypeId, string?>(
identityProvider.Id,
identityProvider.IdentityProviderCategoryId,
identityProvider.IamIdentityProvider!.IamIdpAlias,
identityProvider.IdentityProviderTypeId
identityProvider.IdentityProviderTypeId,
identityProvider.IamIdentityProvider.MetadataUrl
))
.ToAsyncEnumerable();

Expand Down
Loading
Loading