From 4b38b990fc30d2da71bb56d5e483ab46d52482cf Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Mon, 22 Apr 2024 12:13:23 +0300 Subject: [PATCH] tenant configuration changes --- .../builder/deposit/DepositSourceBuilder.java | 30 ++++++-- .../FileTransformerSourceBuilder.java | 33 ++++++++- .../DepositTenantConfigurationBuilder.java | 2 +- ...TransformerTenantConfigurationBuilder.java | 2 +- .../eudat/query/lookup/EntityDoiLookup.java | 40 +++++++++++ .../lookup/TenantConfigurationLookup.java | 16 +++++ .../eudat/service/tenant/TenantService.java | 1 - .../service/tenant/TenantServiceImpl.java | 24 +------ .../TenantConfigurationService.java | 8 ++- .../TenantConfigurationServiceImpl.java | 70 ++++++++++++++----- .../TenantConfigurationController.java | 8 ++- .../eudat/controllers/TenantController.java | 5 -- 12 files changed, 181 insertions(+), 58 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositSourceBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositSourceBuilder.java index 770923ee5..416df7c70 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositSourceBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositSourceBuilder.java @@ -1,14 +1,12 @@ package eu.eudat.model.builder.deposit; import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.scope.tenant.TenantScope; import eu.eudat.commons.types.deposit.DepositSourceEntity; import eu.eudat.convention.ConventionService; import eu.eudat.model.builder.BaseBuilder; import eu.eudat.model.deposit.DepositSource; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; +import eu.eudat.service.encryption.EncryptionService; +import eu.eudat.service.tenant.TenantProperties; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.DataLogEntry; @@ -25,11 +23,16 @@ import java.util.*; @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class DepositSourceBuilder extends BaseBuilder { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private boolean encrypted; + private final EncryptionService encryptionService; + private final TenantProperties tenantProperties; @Autowired public DepositSourceBuilder( - ConventionService conventionService) { + ConventionService conventionService, EncryptionService encryptionService, TenantProperties tenantProperties) { super(conventionService, new LoggerService(LoggerFactory.getLogger(DepositSourceBuilder.class))); + this.encryptionService = encryptionService; + this.tenantProperties = tenantProperties; } public DepositSourceBuilder authorize(EnumSet values) { @@ -37,6 +40,11 @@ public class DepositSourceBuilder extends BaseBuilder build(FieldSet fields, List data) throws MyApplicationException { this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); @@ -51,7 +59,17 @@ public class DepositSourceBuilder extends BaseBuilder { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - + private final EncryptionService encryptionService; + private final TenantProperties tenantProperties; + private boolean encrypted; @Autowired public FileTransformerSourceBuilder( - ConventionService conventionService) { + ConventionService conventionService, EncryptionService encryptionService, TenantProperties tenantProperties) { super(conventionService, new LoggerService(LoggerFactory.getLogger(FileTransformerSourceBuilder.class))); + this.encryptionService = encryptionService; + this.tenantProperties = tenantProperties; } public FileTransformerSourceBuilder authorize(EnumSet values) { @@ -33,6 +45,11 @@ public class FileTransformerSourceBuilder extends BaseBuilder build(FieldSet fields, List data) throws MyApplicationException { this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); @@ -47,7 +64,17 @@ public class FileTransformerSourceBuilder extends BaseBuilder dois; + public List getIsActive() { + return isActive; + } + + public void setIsActive(List isActive) { + this.isActive = isActive; + } + + public List getTypes() { + return types; + } + + public void setTypes(List types) { + this.types = types; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + public List getExcludedIds() { + return excludedIds; + } + + public void setExcludedIds(List excludedIds) { + this.excludedIds = excludedIds; + } + + public List getDois() { + return dois; + } + + public void setDois(List dois) { + this.dois = dois; + } + public EntityDoiQuery enrich(QueryFactory queryFactory) { EntityDoiQuery query = queryFactory.query(EntityDoiQuery.class); if (this.isActive != null) diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/TenantConfigurationLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/TenantConfigurationLookup.java index b29d160a3..d8f7a8091 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/TenantConfigurationLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/TenantConfigurationLookup.java @@ -51,6 +51,22 @@ public class TenantConfigurationLookup extends Lookup { this.types = types; } + public List getTenantIds() { + return tenantIds; + } + + public void setTenantIds(List tenantIds) { + this.tenantIds = tenantIds; + } + + public Boolean getTenantIsSet() { + return tenantIsSet; + } + + public void setTenantIsSet(Boolean tenantIsSet) { + this.tenantIsSet = tenantIsSet; + } + public TenantConfigurationQuery enrich(QueryFactory queryFactory) { TenantConfigurationQuery query = queryFactory.query(TenantConfigurationQuery.class); if (this.types != null) query.types(this.types); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantService.java b/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantService.java index 311b91c15..aaf06e5ad 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantService.java @@ -25,6 +25,5 @@ public interface TenantService { Tenant persist(TenantPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException; - Tenant decryptTenant(Tenant model) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, InvalidApplicationException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java index 7848f8dbb..a1f729271 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/tenant/TenantServiceImpl.java @@ -51,7 +51,6 @@ import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.time.Instant; -import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -190,28 +189,7 @@ public class TenantServiceImpl implements TenantService { } - @Override - public Tenant decryptTenant(Tenant model) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, InvalidApplicationException { -// if (model.getConfig() != null && model.getConfig().getDeposit() != null && model.getConfig().getDeposit().getSources() != null) { -// for (TenantSource source : model.getConfig().getDeposit().getSources().stream().toList()) { -// source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv())); -// } -// } -// if (model.getConfig() != null && model.getConfig().getFileTransformers() != null && model.getConfig().getFileTransformers().getSources() != null) { -// for (TenantSource source : model.getConfig().getFileTransformers().getSources().stream().toList()) { -// source.setClientSecret(this.encryptionService.decryptAES(source.getClientSecret(), properties.getConfigEncryptionAesKey(), properties.getConfigEncryptionAesIv())); -// } -// } - - TenantEntity data = this.entityManager.find(TenantEntity.class, model.getId()); - if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale())); - - TenantTouchedIntegrationEvent tenantTouchedIntegrationEvent = new TenantTouchedIntegrationEvent(); - tenantTouchedIntegrationEvent.setId(data.getId()); - tenantTouchedIntegrationEvent.setCode(data.getCode()); - this.tenantTouchedIntegrationEventHandler.handle(tenantTouchedIntegrationEvent); - return model; - } + @Override public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationService.java b/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationService.java index 686f6c6f0..fbc587643 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationService.java @@ -9,12 +9,18 @@ import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.exception.MyValidationException; import gr.cite.tools.fieldset.FieldSet; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import javax.management.InvalidApplicationException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.UUID; public interface TenantConfigurationService { - TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException; + TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationServiceImpl.java index 680cf1f61..d5f0f5ad4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/tenantconfiguration/TenantConfigurationServiceImpl.java @@ -4,25 +4,26 @@ import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.JsonHandlingService; -import eu.eudat.commons.enums.EntityType; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.StorageType; +import eu.eudat.commons.enums.TenantConfigurationType; import eu.eudat.commons.types.deposit.DepositSourceEntity; -import eu.eudat.commons.types.dmp.DmpPropertiesEntity; import eu.eudat.commons.types.filetransformer.FileTransformerSourceEntity; import eu.eudat.commons.types.tenantconfiguration.*; import eu.eudat.convention.ConventionService; import eu.eudat.data.TenantConfigurationEntity; import eu.eudat.data.TenantEntityManager; import eu.eudat.errorcode.ErrorThesaurusProperties; +import eu.eudat.model.StorageFile; import eu.eudat.model.builder.tenantconfiguration.TenantConfigurationBuilder; import eu.eudat.model.deleter.TenantConfigurationDeleter; import eu.eudat.model.persist.deposit.DepositSourcePersist; -import eu.eudat.model.persist.dmpproperties.DmpBlueprintValuePersist; -import eu.eudat.model.persist.dmpproperties.DmpContactPersist; -import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist; import eu.eudat.model.persist.filetransformer.FileTransformerSourcePersist; import eu.eudat.model.persist.tenantconfiguration.*; import eu.eudat.model.tenantconfiguration.TenantConfiguration; +import eu.eudat.service.encryption.EncryptionService; +import eu.eudat.service.storage.StorageFileService; +import eu.eudat.service.tenant.TenantProperties; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.deleter.DeleterFactory; @@ -41,7 +42,13 @@ import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import javax.management.InvalidApplicationException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -68,7 +75,10 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic private final JsonHandlingService jsonHandlingService; + private final EncryptionService encryptionService; + private final TenantProperties tenantProperties; + private final StorageFileService storageFileService; @Autowired public TenantConfigurationServiceImpl( TenantEntityManager entityManager, @@ -77,7 +87,7 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic BuilderFactory builderFactory, ConventionService conventionService, ErrorThesaurusProperties errors, - MessageSource messageSource, JsonHandlingService jsonHandlingService) { + MessageSource messageSource, JsonHandlingService jsonHandlingService, EncryptionService encryptionService, TenantProperties tenantProperties, StorageFileService storageFileService) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -86,9 +96,12 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic this.errors = errors; this.messageSource = messageSource; this.jsonHandlingService = jsonHandlingService; + this.encryptionService = encryptionService; + this.tenantProperties = tenantProperties; + this.storageFileService = storageFileService; } - public TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { + public TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { logger.debug(new MapLogEntry("persisting data TenantConfiguration").And("model", model).And("fields", fields)); this.authorizationService.authorizeForce(Permission.EditTenantConfiguration); @@ -109,12 +122,16 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic data.setType(model.getType()); } + switch (data.getType()){ case CssColors -> data.setValue(this.jsonHandlingService.toJson(this.buildCssColorsTenantConfigurationEntity(model.getCssColors()))); case DefaultUserLocale -> data.setValue(this.jsonHandlingService.toJson(this.buildDefaultUserLocaleTenantConfigurationEntity(model.getDefaultUserLocale()))); case DepositPlugins -> data.setValue(this.jsonHandlingService.toJson(this.buildDepositTenantConfigurationEntity(model.getDepositPlugins()))); case FileTransformerPlugins -> data.setValue(this.jsonHandlingService.toJson(this.buildFileTransformerTenantConfigurationEntity(model.getFileTransformerPlugins()))); - case Logo -> data.setValue(this.jsonHandlingService.toJson(this.buildLogoTenantConfigurationEntity(model.getLogo()))); + case Logo -> { + LogoTenantConfigurationEntity oldValue = this.conventionService.isNullOrEmpty(data.getValue()) ? null : this.jsonHandlingService.fromJsonSafe(LogoTenantConfigurationEntity.class, data.getValue()); + data.setValue(this.jsonHandlingService.toJson(this.buildLogoTenantConfigurationEntity(model.getLogo(), oldValue))); + } default -> throw new InternalError("unknown type: " + data.getType()); } data.setUpdatedAt(Instant.now()); @@ -128,7 +145,7 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic return this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, TenantConfiguration._id), data); } - private @NotNull DepositTenantConfigurationEntity buildDepositTenantConfigurationEntity(DepositTenantConfigurationPersist persist){ + private @NotNull DepositTenantConfigurationEntity buildDepositTenantConfigurationEntity(DepositTenantConfigurationPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { DepositTenantConfigurationEntity data = new DepositTenantConfigurationEntity(); if (persist == null || this.conventionService.isListNullOrEmpty(persist.getSources())) return data; data.setSources(new ArrayList<>()); @@ -138,10 +155,10 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic return data; } - private DepositSourceEntity buildDepositSourceEntity(DepositSourcePersist depositSourcePersist) { + private DepositSourceEntity buildDepositSourceEntity(DepositSourcePersist depositSourcePersist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { DepositSourceEntity depositSourceEntity = new DepositSourceEntity(); depositSourceEntity.setClientId(depositSourcePersist.getClientId()); - depositSourceEntity.setClientSecret(depositSourcePersist.getClientSecret()); + if (!this.conventionService.isNullOrEmpty(depositSourcePersist.getClientSecret())) depositSourceEntity.setClientSecret(this.encryptionService.encryptAES(depositSourcePersist.getClientSecret(), this.tenantProperties.getConfigEncryptionAesKey(), this.tenantProperties.getConfigEncryptionAesIv())); depositSourceEntity.setRepositoryId(depositSourcePersist.getRepositoryId()); depositSourceEntity.setUrl(depositSourcePersist.getUrl()); depositSourceEntity.setIssuerUrl(depositSourcePersist.getIssuerUrl()); @@ -151,7 +168,7 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic return depositSourceEntity; } - private @NotNull FileTransformerTenantConfigurationEntity buildFileTransformerTenantConfigurationEntity(FileTransformerTenantConfigurationPersist persist){ + private @NotNull FileTransformerTenantConfigurationEntity buildFileTransformerTenantConfigurationEntity(FileTransformerTenantConfigurationPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { FileTransformerTenantConfigurationEntity data = new FileTransformerTenantConfigurationEntity(); if (persist == null || this.conventionService.isListNullOrEmpty(persist.getSources())) return data; data.setSources(new ArrayList<>()); @@ -161,10 +178,10 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic return data; } - private FileTransformerSourceEntity buildFileTransformerSourceEntity(FileTransformerSourcePersist depositSourcePersist) { + private FileTransformerSourceEntity buildFileTransformerSourceEntity(FileTransformerSourcePersist depositSourcePersist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { FileTransformerSourceEntity depositSourceEntity = new FileTransformerSourceEntity(); depositSourceEntity.setClientId(depositSourcePersist.getClientId()); - depositSourceEntity.setClientSecret(depositSourcePersist.getClientSecret()); + if (!this.conventionService.isNullOrEmpty(depositSourcePersist.getClientSecret())) depositSourceEntity.setClientSecret(this.encryptionService.encryptAES(depositSourcePersist.getClientSecret(), this.tenantProperties.getConfigEncryptionAesKey(), this.tenantProperties.getConfigEncryptionAesIv())); depositSourceEntity.setUrl(depositSourcePersist.getUrl()); depositSourceEntity.setIssuerUrl(depositSourcePersist.getIssuerUrl()); depositSourceEntity.setScope(depositSourcePersist.getScope()); @@ -191,11 +208,25 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic return data; } - private @NotNull LogoTenantConfigurationEntity buildLogoTenantConfigurationEntity(LogoTenantConfigurationPersist persist){ + private @NotNull LogoTenantConfigurationEntity buildLogoTenantConfigurationEntity(LogoTenantConfigurationPersist persist, LogoTenantConfigurationEntity oldValue) throws InvalidApplicationException { LogoTenantConfigurationEntity data = new LogoTenantConfigurationEntity(); if (persist == null) return data; data.setStorageFileId(persist.getStorageFileId()); - //TODO + + UUID existingFileId = oldValue != null ? oldValue.getStorageFileId() : null; + if (persist.getStorageFileId() != null){ + if (!persist.getStorageFileId().equals(existingFileId)) { + StorageFile storageFile = this.storageFileService.copyToStorage(persist.getStorageFileId(), StorageType.Main, true, new BaseFieldSet().ensure(StorageFile._id)); + this.storageFileService.updatePurgeAt(storageFile.getId(), null); + if (existingFileId != null) this.storageFileService.updatePurgeAt(existingFileId, Instant.now().minusSeconds(60)); + data.setStorageFileId(storageFile.getId()); + } else { + data.setStorageFileId(existingFileId); + } + } else { + if (existingFileId != null) this.storageFileService.updatePurgeAt(existingFileId, Instant.now().minusSeconds(60)); + data.setStorageFileId(null); + } return data; } @@ -204,6 +235,13 @@ public class TenantConfigurationServiceImpl implements TenantConfigurationServic this.authorizationService.authorizeForce(Permission.DeleteTenantConfiguration); + TenantConfigurationEntity data = this.entityManager.find(TenantConfigurationEntity.class, id); + if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + if (data.getType().equals(TenantConfigurationType.Logo)){ + LogoTenantConfigurationEntity oldValue = this.conventionService.isNullOrEmpty(data.getValue()) ? null : this.jsonHandlingService.fromJsonSafe(LogoTenantConfigurationEntity.class, data.getValue()); + if (oldValue != null && oldValue.getStorageFileId() != null) this.storageFileService.updatePurgeAt(oldValue.getStorageFileId(), Instant.now().minusSeconds(60)); + } this.deleterFactory.deleter(TenantConfigurationDeleter.class).deleteAndSaveByIds(List.of(id)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java index e7425cca0..2c8b5236d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java @@ -30,7 +30,13 @@ import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import javax.management.InvalidApplicationException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.*; @RestController @@ -104,7 +110,7 @@ public class TenantConfigurationController { @PostMapping("persist") @Transactional @ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model") - public TenantConfiguration Persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException { + public TenantConfiguration Persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantController.java index feef64391..7533320b9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantController.java @@ -86,9 +86,6 @@ public class TenantController { List data = query.collectAs(lookup.getProject()); List models = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); - for (Tenant model : models) { - models.set(models.indexOf(model), this.tenantService.decryptTenant(model)); - } long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.Tenant_Query, "lookup", lookup); @@ -107,8 +104,6 @@ public class TenantController { if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale())); - model = this.tenantService.decryptTenant(model); - this.auditService.track(AuditableAction.Tenant_Lookup, Map.ofEntries( new AbstractMap.SimpleEntry("id", id), new AbstractMap.SimpleEntry("fields", fieldSet)