tenant configuration changes

This commit is contained in:
Efstratios Giannopoulos 2024-04-22 12:13:23 +03:00
parent 1b78203d27
commit 4b38b990fc
12 changed files with 181 additions and 58 deletions

View File

@ -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<DepositSource, DepositSourceEntity> {
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
@ -37,6 +40,11 @@ public class DepositSourceBuilder extends BaseBuilder<DepositSource, DepositSour
return this;
}
public DepositSourceBuilder encrypted(boolean encrypted) {
this.encrypted = encrypted;
return this;
}
@Override
public List<DepositSource> build(FieldSet fields, List<DepositSourceEntity> 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<DepositSource, DepositSour
if (fields.hasField(this.asIndexer(DepositSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(DepositSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(DepositSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(DepositSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(DepositSource._clientSecret))) {
if (encrypted) {
try {
if (!this.conventionService.isNullOrEmpty(d.getClientSecret())) m.setClientSecret(this.encryptionService.decryptAES(d.getClientSecret(), tenantProperties.getConfigEncryptionAesKey(), tenantProperties.getConfigEncryptionAesIv()));
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
m.setClientSecret(d.getClientSecret());
}
}
if (fields.hasField(this.asIndexer(DepositSource._scope))) m.setScope(d.getScope());
if (fields.hasField(this.asIndexer(DepositSource._pdfTransformerId))) m.setPdfTransformerId(d.getPdfTransformerId());
if (fields.hasField(this.asIndexer(DepositSource._rdaTransformerId))) m.setRdaTransformerId(d.getRdaTransformerId());

View File

@ -5,6 +5,8 @@ import eu.eudat.commons.types.filetransformer.FileTransformerSourceEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.filetransformer.FileTransformerSource;
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;
@ -15,17 +17,27 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FileTransformerSourceBuilder extends BaseBuilder<FileTransformerSource, FileTransformerSourceEntity> {
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
@ -33,6 +45,11 @@ public class FileTransformerSourceBuilder extends BaseBuilder<FileTransformerSou
return this;
}
public FileTransformerSourceBuilder encrypted(boolean encrypted) {
this.encrypted = encrypted;
return this;
}
@Override
public List<FileTransformerSource> build(FieldSet fields, List<FileTransformerSourceEntity> 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<FileTransformerSou
if (fields.hasField(this.asIndexer(FileTransformerSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientSecret))){
if (encrypted) {
try {
if (!this.conventionService.isNullOrEmpty(d.getClientSecret())) m.setClientSecret(this.encryptionService.decryptAES(d.getClientSecret(), tenantProperties.getConfigEncryptionAesKey(), tenantProperties.getConfigEncryptionAesIv()));
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
m.setClientSecret(d.getClientSecret());
}
}
if (fields.hasField(this.asIndexer(FileTransformerSource._scope))) m.setScope(d.getScope());
models.add(m);
}

View File

@ -51,7 +51,7 @@ public class DepositTenantConfigurationBuilder extends BaseBuilder<DepositTenant
for (DepositTenantConfigurationEntity d : data) {
DepositTenantConfiguration m = new DepositTenantConfiguration();
if (!sourcesFields.isEmpty() && d.getSources() != null){
m.setSources(this.builderFactory.builder(DepositSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
m.setSources(this.builderFactory.builder(DepositSourceBuilder.class).encrypted(true).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}

View File

@ -51,7 +51,7 @@ public class FileTransformerTenantConfigurationBuilder extends BaseBuilder<FileT
for (FileTransformerTenantConfigurationEntity d : data) {
FileTransformerTenantConfiguration m = new FileTransformerTenantConfiguration();
if (!sourcesFields.isEmpty() && d.getSources() != null){
m.setSources(this.builderFactory.builder(FileTransformerSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources()));
m.setSources(this.builderFactory.builder(FileTransformerSourceBuilder.class).encrypted(true).authorize(this.authorize).build(sourcesFields, d.getSources()));
}
models.add(m);
}

View File

@ -21,6 +21,46 @@ public class EntityDoiLookup extends Lookup {
private List<String> dois;
public List<IsActive> getIsActive() {
return isActive;
}
public void setIsActive(List<IsActive> isActive) {
this.isActive = isActive;
}
public List<EntityType> getTypes() {
return types;
}
public void setTypes(List<EntityType> types) {
this.types = types;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setExcludedIds(List<UUID> excludedIds) {
this.excludedIds = excludedIds;
}
public List<String> getDois() {
return dois;
}
public void setDois(List<String> dois) {
this.dois = dois;
}
public EntityDoiQuery enrich(QueryFactory queryFactory) {
EntityDoiQuery query = queryFactory.query(EntityDoiQuery.class);
if (this.isActive != null)

View File

@ -51,6 +51,22 @@ public class TenantConfigurationLookup extends Lookup {
this.types = types;
}
public List<UUID> getTenantIds() {
return tenantIds;
}
public void setTenantIds(List<UUID> 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);

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;

View File

@ -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));
}

View File

@ -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);

View File

@ -86,9 +86,6 @@ public class TenantController {
List<TenantEntity> data = query.collectAs(lookup.getProject());
List<Tenant> 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<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)