-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define subtype for compliance & mitigation
verinice-veo#3073
- Loading branch information
1 parent
fdad36b
commit a89a719
Showing
13 changed files
with
285 additions
and
2 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
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
34 changes: 34 additions & 0 deletions
34
veo-core-entity/src/main/java/org/veo/core/entity/ControlImplementationConfiguration.java
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,34 @@ | ||
/******************************************************************************* | ||
* verinice.veo | ||
* Copyright (C) 2024 Urs Zeidler | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
package org.veo.core.entity; | ||
|
||
import jakarta.validation.constraints.Size; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.veo.core.entity.aspects.ElementDomainAssociation; | ||
|
||
public record ControlImplementationConfiguration( | ||
@Nullable @Size(max = ElementDomainAssociation.SUB_TYPE_MAX_LENGTH) | ||
String complianceControlSubType, | ||
@Nullable @Size(max = ElementDomainAssociation.SUB_TYPE_MAX_LENGTH) | ||
String mitigationControlSubType) { | ||
public ControlImplementationConfiguration() { | ||
this(null, null); | ||
} | ||
} |
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
76 changes: 76 additions & 0 deletions
76
.../main/java/org/veo/core/usecase/domain/SaveControlImplementationConfigurationUseCase.java
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,76 @@ | ||
/******************************************************************************* | ||
* verinice.veo | ||
* Copyright (C) 2024 Jonas Jordan | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
package org.veo.core.usecase.domain; | ||
|
||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import org.veo.core.entity.Client; | ||
import org.veo.core.entity.Control; | ||
import org.veo.core.entity.ControlImplementationConfiguration; | ||
import org.veo.core.entity.Key; | ||
import org.veo.core.entity.definitions.ElementTypeDefinition; | ||
import org.veo.core.repository.DomainRepository; | ||
import org.veo.core.usecase.TransactionalUseCase; | ||
import org.veo.core.usecase.UseCase; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class SaveControlImplementationConfigurationUseCase | ||
implements TransactionalUseCase< | ||
SaveControlImplementationConfigurationUseCase.InputData, UseCase.EmptyOutput> { | ||
|
||
private final DomainRepository domainRepository; | ||
|
||
@Override | ||
public EmptyOutput execute(InputData input) { | ||
var domain = domainRepository.getActiveById(input.domainId, input.authenticatedClient.getId()); | ||
validate( | ||
domain.getElementTypeDefinition(Control.SINGULAR_TERM), | ||
input.controlImplementationConfiguration); | ||
domain.setControlImplementationConfiguration(input.controlImplementationConfiguration); | ||
domain.setUpdatedAt(Instant.now()); | ||
return EmptyOutput.INSTANCE; | ||
} | ||
|
||
private void validate( | ||
ElementTypeDefinition elementTypeDefinition, | ||
@NotNull ControlImplementationConfiguration controlImplementationConfiguration) { | ||
Optional.ofNullable(controlImplementationConfiguration.complianceControlSubType()) | ||
.ifPresent(elementTypeDefinition::getSubTypeDefinition); | ||
Optional.ofNullable(controlImplementationConfiguration.mitigationControlSubType()) | ||
.ifPresent(elementTypeDefinition::getSubTypeDefinition); | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly() { | ||
return false; | ||
} | ||
|
||
@Valid | ||
public record InputData( | ||
@NotNull Client authenticatedClient, | ||
@NotNull Key<UUID> domainId, | ||
@NotNull ControlImplementationConfiguration controlImplementationConfiguration) | ||
implements UseCase.InputData {} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...groovy/org/veo/persistence/migrations/V96__add_controlImplementation_configuration.groovy
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,52 @@ | ||
/******************************************************************************* | ||
* verinice.veo | ||
* Copyright (C) 2023 Jonas Jordan | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
package org.veo.persistence.migrations | ||
|
||
import org.flywaydb.core.api.migration.BaseJavaMigration | ||
import org.flywaydb.core.api.migration.Context | ||
|
||
import groovy.sql.Sql | ||
|
||
class V96__add_controlImplementation_configuration extends BaseJavaMigration { | ||
@Override | ||
void migrate(Context context) throws Exception { | ||
new Sql(context.connection).with { | ||
migrateTable("domain", it) | ||
migrateTable("domaintemplate", it) | ||
} | ||
} | ||
|
||
private static boolean migrateTable(String table, Sql context) { | ||
context.execute(""" | ||
alter table $table | ||
add column control_implementation_configuration jsonb; | ||
update $table | ||
set control_implementation_configuration = | ||
CASE WHEN name = 'IT-Grundschutz' | ||
THEN '{"complianceControlSubType": "CTL_Module" ,"mitigationControlSubType": "CTL_Safeguard" }'::jsonb | ||
WHEN name = 'DS-GVO' | ||
THEN '{"mitigationControlSubType": "CTL_TOM" }'::jsonb | ||
WHEN name = 'ISO/IEC 27000' | ||
THEN '{"mitigationControlSubType": "CTL_ISOControl" }'::jsonb | ||
ELSE '{}'::jsonb | ||
END; | ||
alter table $table | ||
alter column control_implementation_configuration set not null; | ||
""".toString()) | ||
} | ||
} |
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
Oops, something went wrong.