-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connector): adjust connector deletion
* add flag to define whether a linked service account should be deleted * adjust deletion logic for service accounts when deleting a connector Refs: #966 #967
- Loading branch information
Showing
20 changed files
with
448 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/administration/Administration.Service/BusinessLogic/IServiceAccountManagement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; | ||
|
||
public interface IServiceAccountManagement | ||
{ | ||
Task DeleteServiceAccount(Guid serviceAccountId, DeleteServiceAccountData result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/administration/Administration.Service/BusinessLogic/ServiceAccountManagement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling; | ||
using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; | ||
using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; | ||
using Org.Eclipse.TractusX.Portal.Backend.Processes.Library; | ||
using Org.Eclipse.TractusX.Portal.Backend.Provisioning.Library; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; | ||
|
||
public class ServiceAccountManagement(IProvisioningManager provisioningManager, IPortalRepositories portalRepositories) : IServiceAccountManagement | ||
{ | ||
public async Task DeleteServiceAccount(Guid serviceAccountId, DeleteServiceAccountData result) | ||
{ | ||
var userStatus = UserStatusId.DELETED; | ||
switch (result) | ||
{ | ||
case { IsDimServiceAccount: true, CreationProcessInProgress: false }: | ||
userStatus = await CreateDeletionProcess(serviceAccountId, result.ProcessId).ConfigureAwait(ConfigureAwaitOptions.None); | ||
break; | ||
case { IsDimServiceAccount: true, CreationProcessInProgress: true }: | ||
throw ConflictException.Create(AdministrationServiceAccountErrors.TECHNICAL_USER_CREATION_IN_PROGRESS); | ||
default: | ||
if (!string.IsNullOrWhiteSpace(result.ClientClientId)) | ||
{ | ||
await provisioningManager.DeleteCentralClientAsync(result.ClientClientId).ConfigureAwait(ConfigureAwaitOptions.None); | ||
} | ||
|
||
break; | ||
} | ||
|
||
portalRepositories.GetInstance<IUserRepository>().AttachAndModifyIdentity( | ||
serviceAccountId, | ||
i => | ||
{ | ||
i.UserStatusId = UserStatusId.PENDING; | ||
}, | ||
i => | ||
{ | ||
i.UserStatusId = userStatus; | ||
}); | ||
portalRepositories.GetInstance<IUserRolesRepository>().DeleteCompanyUserAssignedRoles(result.UserRoleIds.Select(userRoleId => (serviceAccountId, userRoleId))); | ||
} | ||
|
||
private async Task<UserStatusId> CreateDeletionProcess(Guid serviceAccountId, Guid? processId) | ||
{ | ||
if (processId == null) | ||
{ | ||
throw ConflictException.Create(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_LINKED_TO_PROCESS, [new ErrorParameter("serviceAccountId", serviceAccountId.ToString())]); | ||
} | ||
|
||
var processData = await portalRepositories.GetInstance<IProcessStepRepository>() | ||
.GetProcessDataForServiceAccountDeletionCallback(processId.Value, null) | ||
.ConfigureAwait(ConfigureAwaitOptions.None); | ||
|
||
var context = processData.ProcessData.CreateManualProcessData(null, | ||
portalRepositories, () => $"externalId {processId}"); | ||
|
||
context.ProcessSteps.Where(step => step.ProcessStepTypeId != ProcessStepTypeId.DELETE_DIM_TECHNICAL_USER).IfAny(pending => | ||
throw ConflictException.Create(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_PENDING_PROCESS_STEPS, [new ErrorParameter("serviceAccountId", serviceAccountId.ToString()), new("processStepTypeIds", string.Join<ProcessStep>(",", pending))])); | ||
|
||
if (context.ProcessSteps.Any(step => step.ProcessStepTypeId == ProcessStepTypeId.DELETE_DIM_TECHNICAL_USER)) | ||
return UserStatusId.DELETED; | ||
|
||
context.ScheduleProcessSteps([ProcessStepTypeId.DELETE_DIM_TECHNICAL_USER]); | ||
context.FinalizeProcessStep(); | ||
return UserStatusId.PENDING_DELETION; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/portalbackend/PortalBackend.DBAccess/Models/DeleteServiceAccountData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
|
||
public record DeleteServiceAccountData( | ||
IEnumerable<Guid> UserRoleIds, | ||
string? ClientClientId, | ||
bool IsDimServiceAccount, | ||
bool CreationProcessInProgress, | ||
Guid? ProcessId | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.