From cfbd3233ec8235eeeaf926e7bbf7e333a1e4099e Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 12 Mar 2024 18:27:16 +0200 Subject: [PATCH] authz changes --- .../authorization/AuthorizationFlags.java | 2 +- .../eu/eudat/authorization/Permission.java | 8 ++- .../java/eu/eudat/data/ReferenceEntity.java | 2 +- .../model/censorship/DescriptionCensor.java | 2 +- .../eu/eudat/model/censorship/DmpCensor.java | 2 +- .../DmpDescriptionTemplateCensor.java | 2 +- .../model/censorship/DmpReferenceCensor.java | 2 +- .../eudat/model/censorship/DmpUserCensor.java | 2 +- .../model/censorship/EntityDoiCensor.java | 2 +- .../model/censorship/ReferenceTypeCensor.java | 2 +- .../eu/eudat/model/censorship/UserCensor.java | 2 +- .../java/eu/eudat/query/DmpUserQuery.java | 7 ++- .../java/eu/eudat/query/EntityDoiQuery.java | 38 +++++++++++-- .../java/eu/eudat/query/ReferenceQuery.java | 50 ++++++++++++++++- .../main/java/eu/eudat/query/UserQuery.java | 17 ++++-- .../dashborad/DashboardServiceImpl.java | 13 ++--- .../service/deposit/DepositServiceImpl.java | 10 +--- .../description/DescriptionServiceImpl.java | 7 ++- .../DescriptionTemplateServiceImpl.java | 8 +-- .../DescriptionTemplateTypeServiceImpl.java | 2 +- .../eu/eudat/service/dmp/DmpServiceImpl.java | 9 ++-- .../dmpblueprint/DmpBlueprintServiceImpl.java | 8 +-- .../entitydoi/EntityDoiServiceImpl.java | 2 +- .../service/language/LanguageServiceImpl.java | 5 +- .../eudat/service/lock/LockServiceImpl.java | 9 ++-- .../PrefillingSourceServiceImpl.java | 4 +- .../reference/ReferenceServiceImpl.java | 8 +-- .../ReferenceTypeServiceImpl.java | 2 +- .../storage/StorageFileServiceImpl.java | 7 ++- .../SupportiveMaterialServiceImpl.java | 13 +---- .../eu/eudat/service/tag/TagServiceImpl.java | 2 +- .../service/tenant/TenantServiceImpl.java | 2 +- .../FileTransformerServiceImpl.java | 8 +-- .../eudat/service/user/UserServiceImpl.java | 4 +- .../settings/UserSettingsServiceImpl.java | 2 +- .../controllers/DescriptionController.java | 13 ++--- .../DescriptionTemplateController.java | 8 +-- .../DescriptionTemplateTypeController.java | 9 ++-- .../controllers/DmpBlueprintController.java | 8 +-- .../eu/eudat/controllers/DmpController.java | 11 ++-- .../controllers/EntityDoiController.java | 8 +-- .../eudat/controllers/LanguageController.java | 24 ++++----- .../eu/eudat/controllers/LockController.java | 12 ++--- .../PrefillingSourceController.java | 8 +-- .../controllers/ReferenceController.java | 8 +-- .../controllers/ReferenceTypeController.java | 13 +++-- .../SupportiveMaterialController.java | 13 ++--- .../eu/eudat/controllers/TagController.java | 9 ++-- .../eudat/controllers/TenantController.java | 8 +-- .../eu/eudat/controllers/UserController.java | 18 +++---- .../controllers/UserSettingsController.java | 8 +-- .../src/main/resources/config/permissions.yml | 53 +++++++++---------- .../app/core/common/enum/permission.enum.ts | 1 + 53 files changed, 266 insertions(+), 231 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/authorization/AuthorizationFlags.java b/dmp-backend/core/src/main/java/eu/eudat/authorization/AuthorizationFlags.java index afb9654b0..0a0255495 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/authorization/AuthorizationFlags.java +++ b/dmp-backend/core/src/main/java/eu/eudat/authorization/AuthorizationFlags.java @@ -4,5 +4,5 @@ import java.util.EnumSet; public enum AuthorizationFlags { None, Permission, DmpAssociated, Public, Owner; - public static final EnumSet OwnerOrDmpAssociatedOrPermissionOrPublic = EnumSet.of(DmpAssociated, Permission, Public, Owner); + public static final EnumSet OwnerOrDmpAssociatedOrPermission = EnumSet.of(DmpAssociated, Permission, Owner); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java index 02bd52676..fc8374251 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java +++ b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java @@ -3,15 +3,11 @@ package eu.eudat.authorization; public final class Permission { /////// Should Remove after Refactor - public static String AnonymousRole = "AnonymousRole"; public static String AdminRole = "AdminRole"; - public static String ManagerRole = "ManagerRole"; - public static String UserRole = "UserRole"; public static String AuthenticatedRole = "AuthenticatedRole"; - public static String PublicRole = "PublicRole"; - public static String DatasetProfileManagerRole = "DatasetProfileManagerRole"; ///// + public static String DeferredAffiliation = "DeferredAffiliation"; //Public public static String PublicBrowseDescription = "PublicBrowseDescription"; @@ -73,6 +69,8 @@ public final class Permission { //Dmp public static String BrowseDmp = "BrowseDmp"; public static String EditDmp = "EditDmp"; + public static String NewDmp = "NewDmp"; + public static String DeleteDmp = "DeleteDmp"; public static String CloneDmp = "CloneDmp"; public static String CreateNewVersionDmp = "CreateNewVersionDmp"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java index 3c5cafb37..07896263f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java @@ -98,7 +98,7 @@ public class ReferenceEntity extends TenantScopedBaseEntity { @Column(name = "created_by", columnDefinition = "uuid") private UUID createdById; - public static final String _createdById = "createdBy"; + public static final String _createdById = "createdById"; public UUID getId() { return id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java index 62adac6d8..bb8d7f4f3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java @@ -37,7 +37,7 @@ public class DescriptionCensor extends BaseCensor { if (fields == null || fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseDescription); + this.authService.authorizeForce(Permission.BrowseDescription, Permission.DeferredAffiliation); FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(Description._descriptionReferences)); this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java index 9f0002c17..a58bc4078 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java @@ -39,7 +39,7 @@ public class DmpCensor extends BaseCensor { if (fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseDmp); + this.authService.authorizeForce(Permission.BrowseDmp, Permission.DeferredAffiliation); FieldSet dmpUsersFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpUsers)); this.censorFactory.censor(DmpUserCensor.class).censor(dmpUsersFields, userId); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java index a731055d5..177f38813 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java @@ -39,7 +39,7 @@ public class DmpDescriptionTemplateCensor extends BaseCensor{ if (fields == null || fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseDescription); + this.authService.authorizeForce(Permission.BrowseDescription, Permission.DeferredAffiliation); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); FieldSet descriptionTemplatesFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplates)); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpReferenceCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpReferenceCensor.java index 02a286b01..c93caa46c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpReferenceCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpReferenceCensor.java @@ -38,7 +38,7 @@ public class DmpReferenceCensor extends BaseCensor { if (fields == null || fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseDmpDescriptionTemplate); + this.authService.authorizeForce(Permission.BrowseDmpDescriptionTemplate, Permission.DeferredAffiliation); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); FieldSet templateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._reference)); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpUserCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpUserCensor.java index 24a59c07c..907b6fb28 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpUserCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpUserCensor.java @@ -37,7 +37,7 @@ public class DmpUserCensor extends BaseCensor { if (fields == null || fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseDmpUser); + this.authService.authorizeForce(Permission.BrowseDmpUser, Permission.DeferredAffiliation); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpUser._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(DmpUser._user)); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/EntityDoiCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/EntityDoiCensor.java index 9edbb60f2..96482c729 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/EntityDoiCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/EntityDoiCensor.java @@ -31,6 +31,6 @@ public class EntityDoiCensor extends BaseCensor{ if (fields == null || fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseEntityDoi); + this.authService.authorizeForce(Permission.BrowseEntityDoi, Permission.DeferredAffiliation); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ReferenceTypeCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ReferenceTypeCensor.java index 42987894d..bec5e8c0a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ReferenceTypeCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ReferenceTypeCensor.java @@ -38,7 +38,7 @@ public class ReferenceTypeCensor extends BaseCensor { if (fields == null || fields.isEmpty()) return; - this.authService.authorizeForce(Permission.BrowseReferenceType); + this.authService.authorizeForce(Permission.BrowseReferenceType, Permission.DeferredAffiliation); FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceType._definition)); this.censorFactory.censor(ReferenceTypeDefinitionCensor.class).censor(definitionFields, userId); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCensor.java index 86038e84f..8ebd75ecf 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCensor.java @@ -37,7 +37,7 @@ public class UserCensor extends BaseCensor { logger.debug(new DataLogEntry("censoring fields", fields)); if (fields == null || fields.isEmpty()) return; - this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser); + this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser, Permission.DeferredAffiliation); FieldSet rolesFields = fields.extractPrefixed(this.asIndexerPrefix(User._roles)); this.censorFactory.censor(UserRoleCensor.class).censor(rolesFields, userId); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java index da63138e4..3c90783ad 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java @@ -5,9 +5,12 @@ import eu.eudat.authorization.Permission; import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpReferenceEntity; import eu.eudat.data.DmpUserEntity; +import eu.eudat.data.ReferenceEntity; import eu.eudat.model.DmpUser; import eu.eudat.model.PublicDmpUser; +import eu.eudat.query.utils.BuildSubQueryInput; import eu.eudat.query.utils.QueryUtilsService; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; @@ -173,7 +176,7 @@ public class DmpUserQuery extends QueryBase { if (userId != null || usePublic ) { predicates.add(queryContext.CriteriaBuilder.or( usePublic ? queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmpId)).value(queryUtilsService.buildPublicDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, usePublic)) : queryContext.CriteriaBuilder.or(), //Creates a false query - userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpUserEntity._userId), userId) : queryContext.CriteriaBuilder.or() //Creates a false query + userId != null ? queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmpId)).value(queryUtilsService.buildDmpUserAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId)) : queryContext.CriteriaBuilder.or() //Creates a false query )); } if (!predicates.isEmpty()) { @@ -183,7 +186,7 @@ public class DmpUserQuery extends QueryBase { return queryContext.CriteriaBuilder.or(); //Creates a false query } } - + @Override protected Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java index da22a63a3..79517b349 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java @@ -1,13 +1,15 @@ package eu.eudat.query; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.authorization.Permission; import eu.eudat.commons.enums.EntityType; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; -import eu.eudat.data.DmpEntity; -import eu.eudat.data.EntityDoiEntity; +import eu.eudat.data.*; import eu.eudat.model.Dmp; import eu.eudat.model.EntityDoi; +import eu.eudat.query.utils.BuildSubQueryInput; +import eu.eudat.query.utils.QueryUtilsService; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; @@ -151,10 +153,19 @@ public class EntityDoiQuery extends QueryBase { return this; } + private final UserScope userScope; + + private final AuthorizationService authService; + + private final QueryUtilsService queryUtilsService; + public EntityDoiQuery( - ) { + UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) { + this.userScope = userScope; + this.authService = authService; + this.queryUtilsService = queryUtilsService; } @Override @@ -167,6 +178,27 @@ public class EntityDoiQuery extends QueryBase { return this.isEmpty(this.ids) || this.isEmpty(this.isActives)|| this.isEmpty(this.repositoryIds) || this.isEmpty(this.excludedIds) || this.isEmpty(this.types); } + @Override + protected Predicate applyAuthZ(QueryContext queryContext) { + if (this.authorize.contains(AuthorizationFlags.None)) return null; + if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseUser)) return null; + UUID userId; + if (this.authorize.contains(AuthorizationFlags.Owner)) userId = this.userScope.getUserIdSafe(); + else userId = null; + + List predicates = new ArrayList<>(); + boolean usePublic = this.authorize.contains(AuthorizationFlags.Public); + if (userId != null || usePublic) { + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(EntityDoiEntity._entityId)).value( queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)))); + } + if (!predicates.isEmpty()) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return queryContext.CriteriaBuilder.or(); //Creates a false query + } + } + @Override protected Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java index 76f220d97..c860321f8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java @@ -1,12 +1,21 @@ package eu.eudat.query; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.authorization.Permission; +import eu.eudat.commons.enums.DmpAccessType; +import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.ReferenceSourceType; +import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpReferenceEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.ReferenceEntity; import eu.eudat.model.PublicReference; import eu.eudat.model.Reference; +import eu.eudat.query.utils.BuildSubQueryInput; +import eu.eudat.query.utils.QueryUtilsService; +import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryContext; @@ -163,9 +172,16 @@ public class ReferenceQuery extends QueryBase { this.authorize = values; return this; } + private final UserScope userScope; + + private final AuthorizationService authService; + private final QueryUtilsService queryUtilsService; public ReferenceQuery( - ) { + UserScope userScope, AuthorizationService authService, QueryUtilsService queryUtilsService) { + this.userScope = userScope; + this.authService = authService; + this.queryUtilsService = queryUtilsService; } @Override @@ -178,6 +194,38 @@ public class ReferenceQuery extends QueryBase { return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.sources) ||this.isEmpty(this.excludedIds) || this.isEmpty(this.typeIds) || this.isEmpty(this.referenceSourceTypes)|| this.isFalseQuery(this.dmpReferenceQuery); } + @Override + protected Predicate applyAuthZ(QueryContext queryContext) { + if (this.authorize.contains(AuthorizationFlags.None)) return null; + if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseReference)) return null; + UUID userId; + boolean usePublic = this.authorize.contains(AuthorizationFlags.Public); + if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe(); + else userId = null; + + List predicates = new ArrayList<>(); + if (userId != null || usePublic ) { + predicates.add(queryContext.CriteriaBuilder.or( + queryContext.CriteriaBuilder.isNull(queryContext.Root.get(ReferenceEntity._createdById)), + userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(ReferenceEntity._createdById), userId) : queryContext.CriteriaBuilder.or(), //Creates a false query + userId != null ? queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)).value(queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpReferenceEntity.class, UUID.class) + .query(queryContext.Query) + .criteriaBuilder(queryContext.CriteriaBuilder) + .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpReferenceEntity._referenceId)) + .filterFunc((subQueryRoot, cb) -> + cb.in(subQueryRoot.get(DmpReferenceEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)) + ) + ))) : queryContext.CriteriaBuilder.or() //Creates a false query + )); + } + if (!predicates.isEmpty()) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return queryContext.CriteriaBuilder.or(); //Creates a false query + } + } + @Override protected Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/UserQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/UserQuery.java index dc9d107b6..6fb6d78b6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/UserQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/UserQuery.java @@ -155,10 +155,19 @@ public class UserQuery extends QueryBase { List predicates = new ArrayList<>(); boolean usePublic = this.authorize.contains(AuthorizationFlags.Public); - if (usePublic){ - predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._isActive)).value(IsActive.Active)); - }else if (userId != null) { - predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)).value(userId)); + if (userId != null || usePublic) { + UUID finalUserId = userId; + predicates.add(queryContext.CriteriaBuilder.or( + userId != null ? queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)).value(userId) : queryContext.CriteriaBuilder.or(), //Creates a false query + queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)).value(queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class) + .query(queryContext.Query) + .criteriaBuilder(queryContext.CriteriaBuilder) + .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._userId)) + .filterFunc((subQueryRoot, cb) -> + cb.in(subQueryRoot.get(DmpUserEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, finalUserId, usePublic)) + ) + ))) + )); } if (!predicates.isEmpty()) { Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dashborad/DashboardServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dashborad/DashboardServiceImpl.java index ae7dea1ec..89bcc9f67 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dashborad/DashboardServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dashborad/DashboardServiceImpl.java @@ -3,14 +3,10 @@ package eu.eudat.service.dashborad; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.OwnedResource; import eu.eudat.authorization.Permission; -import eu.eudat.commons.JsonHandlingService; -import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.*; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.dashborad.RecentActivityItemEntity; import eu.eudat.convention.ConventionService; -import eu.eudat.errorcode.ErrorThesaurusProperties; -import eu.eudat.event.EventBroker; import eu.eudat.model.*; import eu.eudat.model.builder.PublicReferenceTypeBuilder; import eu.eudat.model.builder.RecentActivityItemBuilder; @@ -21,15 +17,12 @@ import eu.eudat.query.lookup.DmpLookup; import eu.eudat.service.elastic.ElasticQueryHelperService; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import jakarta.persistence.EntityManager; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.MessageSource; import org.springframework.stereotype.Service; import javax.management.InvalidApplicationException; @@ -76,14 +69,14 @@ public class DashboardServiceImpl implements DashboardService { List recentActivityItemEntities = new ArrayList<>(); DescriptionLookup descriptionLookup = model.asDescriptionLookup(); descriptionLookup.getPage().setOffset(0); - QueryResult descriptions = this.elasticQueryHelperService.collect(descriptionLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic, new BaseFieldSet().ensure(Description._id).ensure(Description._updatedAt).ensure(Description._status).ensure(Description._label)); + QueryResult descriptions = this.elasticQueryHelperService.collect(descriptionLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermission, new BaseFieldSet().ensure(Description._id).ensure(Description._updatedAt).ensure(Description._status).ensure(Description._label)); if (!this.conventionService.isListNullOrEmpty(descriptions.getItems())) { for (Description description : descriptions.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Description, description.getId(), description.getUpdatedAt(), description.getLabel(), description.getStatus().getValue())); } DmpLookup dmpLookup = model.asDmpLookup(); dmpLookup.getPage().setOffset(0); - QueryResult dmps = this.elasticQueryHelperService.collect(dmpLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic, new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._updatedAt).ensure(Dmp._label).ensure(Dmp._status)); + QueryResult dmps = this.elasticQueryHelperService.collect(dmpLookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermission, new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._updatedAt).ensure(Dmp._label).ensure(Dmp._status)); if (!this.conventionService.isListNullOrEmpty(dmps.getItems())) { for (Dmp dmp : dmps.getItems()) recentActivityItemEntities.add(new RecentActivityItemEntity(RecentActivityItemType.Dmp, dmp.getId(), dmp.getUpdatedAt(), dmp.getLabel(), dmp.getStatus().getValue())); } @@ -102,7 +95,7 @@ public class DashboardServiceImpl implements DashboardService { if (model.getPage() != null){ recentActivityItemEntities = recentActivityItemEntities.stream().skip(model.getPage().getOffset()).limit(model.getPage().getSize()).toList(); } - return this.builderFactory.builder(RecentActivityItemBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(model.getProject()), recentActivityItemEntities); + return this.builderFactory.builder(RecentActivityItemBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(model.getProject()), recentActivityItemEntities); } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java index 5c0bd66b0..a609af160 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java @@ -3,20 +3,14 @@ package eu.eudat.service.deposit; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commonmodels.models.FileEnvelopeModel; -import eu.eudat.commonmodels.models.description.DescriptionModel; -import eu.eudat.commonmodels.models.description.FieldModel; -import eu.eudat.commonmodels.models.description.PropertyDefinitionFieldSetItemModel; -import eu.eudat.commonmodels.models.description.PropertyDefinitionFieldSetModel; import eu.eudat.commonmodels.models.dmp.DmpModel; import eu.eudat.commons.enums.StorageType; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.configurations.deposit.DepositProperties; import eu.eudat.convention.ConventionService; -import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DmpEntity; import eu.eudat.depositinterface.repository.DepositClient; import eu.eudat.depositinterface.repository.DepositConfiguration; -import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.EntityDoi; import eu.eudat.model.StorageFile; import eu.eudat.model.builder.commonmodels.DepositConfigurationBuilder; @@ -25,7 +19,6 @@ import eu.eudat.model.persist.StorageFilePersist; import eu.eudat.model.persist.deposit.DepositAuthenticateRequest; import eu.eudat.model.persist.deposit.DepositRequest; import eu.eudat.model.persist.EntityDoiPersist; -import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpQuery; import eu.eudat.service.entitydoi.EntityDoiService; import eu.eudat.service.storage.StorageFileProperties; @@ -55,7 +48,6 @@ import java.net.URI; import java.net.URLConnection; import java.time.Duration; import java.util.*; -import java.util.stream.Collectors; @Service public class DepositServiceImpl implements DepositService { @@ -182,7 +174,7 @@ public class DepositServiceImpl implements DepositService { } //GK: Fifth Transform them to the DepositModel - DmpModel depositModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(depositClient.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic) + DmpModel depositModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(depositClient.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission) .setRepositoryId(dmpDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).build(dmpEntity); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java index 0cc62e25a..25050e258 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java @@ -20,7 +20,6 @@ import eu.eudat.data.*; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.event.DescriptionTouchedEvent; import eu.eudat.event.EventBroker; -import eu.eudat.integrationevent.outbox.descriptiontouched.DescriptionTouchedIntegrationEvent; import eu.eudat.integrationevent.outbox.descriptiontouched.DescriptionTouchedIntegrationEventHandler; import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent; import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler; @@ -208,7 +207,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.descriptionTouchedIntegrationEventHandler.handle(DescriptionTouchedIntegrationEventHandler.buildEventFromPersistModel(model)); this.elasticService.persistDescription(data); - return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Description._id), data); + return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Description._id), data); } private void sendNotification(DescriptionEntity description) throws InvalidApplicationException { @@ -358,7 +357,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.elasticService.persistDescription(data); this.eventBroker.emit(new DescriptionTouchedEvent(data.getId())); } - return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Description._id), data); + return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Description._id), data); } private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(PropertyDefinitionPersist persist, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition, Map> fieldToReferenceMap){ @@ -746,7 +745,7 @@ public class DescriptionServiceImpl implements DescriptionService { public StorageFile uploadFieldFile(DescriptionFieldFilePersist model, MultipartFile file, FieldSet fields) throws IOException { this.authorizationService.authorizeForce(Permission.EditDescription); - DescriptionTemplateEntity descriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).ids(model.getDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).first(); + DescriptionTemplateEntity descriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).ids(model.getDescriptionTemplateId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).first(); if (descriptionTemplate == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplate.getDefinition()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index e4b6a4675..5a8db280d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -211,7 +211,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.entityManager.flush(); - return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data); + return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data); } private void updateVersionStatusAndSave(DescriptionTemplateEntity data, DescriptionTemplateStatus previousStatus, DescriptionTemplateStatus newStatus) { @@ -470,8 +470,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.authorizationService.authorizeForce(Permission.CloneDescriptionTemplate); - DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - DescriptionTemplate model = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fields, query.firstAs(fields)); + DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + DescriptionTemplate model = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fields, query.firstAs(fields)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -603,7 +603,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.entityManager.flush(); - return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data); + return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data); } //endregion diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java index b2d082b4b..de38afd60 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java @@ -106,7 +106,7 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy this.entityManager.flush(); this.eventBroker.emit(new DescriptionTemplateTypeTouchedEvent(data.getId())); - return this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, DescriptionTemplateType._id), data); + return this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, DescriptionTemplateType._id), data); } public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index c20ae6d3e..2a752368d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -75,7 +75,6 @@ import javax.management.InvalidApplicationException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.IOException; -import java.nio.file.Files; import java.time.Instant; import java.util.*; import java.util.stream.Collectors; @@ -200,7 +199,7 @@ public class DmpServiceImpl implements DmpService { this.inviteUsers(data.getId(), model.getUsers()); } - return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data); + return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data); } private void sendNotification(DmpEntity dmp) throws InvalidApplicationException { @@ -376,7 +375,7 @@ public class DmpServiceImpl implements DmpService { public Dmp buildClone(CloneDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, IOException, InvalidApplicationException { this.authorizationService.authorizeForce(Permission.CloneDmp); - DmpEntity existingDmpEntity = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(model.getId()).firstAs(fields); + DmpEntity existingDmpEntity = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(model.getId()).firstAs(fields); if (!this.conventionService.isValidGuid(model.getId()) || existingDmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -501,7 +500,7 @@ public class DmpServiceImpl implements DmpService { .collect(); this.elasticService.persistDmp(dmpEntity); - return this.builderFactory.builder(DmpUserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fieldSet, DmpUser._id, DmpUser._hash), persisted); + return this.builderFactory.builder(DmpUserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fieldSet, DmpUser._id, DmpUser._hash), persisted); } @Override @@ -522,7 +521,7 @@ public class DmpServiceImpl implements DmpService { if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); this.elasticService.persistDmp(dmpEntity); - return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data); + return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Dmp._id, Dmp._hash), data); } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java index 79cb450e1..fe192a8e2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java @@ -159,7 +159,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { this.entityManager.flush(); - return this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, DmpBlueprint._id), data); + return this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, DmpBlueprint._id), data); } private void updateVersionStatusAndSave(DmpBlueprintEntity data, DmpBlueprintStatus previousStatus, DmpBlueprintStatus newStatus) { @@ -336,8 +336,8 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { this.authorizationService.authorizeForce(Permission.CloneDmpBlueprint); - DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - DmpBlueprint model = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fields, query.firstAs(fields)); + DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + DmpBlueprint model = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fields, query.firstAs(fields)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -435,7 +435,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { this.entityManager.flush(); - return this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, DmpBlueprint._id), data); + return this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, DmpBlueprint._id), data); } //endregion diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java index ce469341a..8bbb126e5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java @@ -109,7 +109,7 @@ public class EntityDoiServiceImpl implements EntityDoiService { this.entityManager.flush(); this.eventBroker.emit(new EntityDoiTouchedEvent(data.getId())); - return this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, EntityDoi._id), data); + return this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, EntityDoi._id), data); } public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java index 1d99b8367..4be900a4d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/language/LanguageServiceImpl.java @@ -25,16 +25,13 @@ import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; import jakarta.persistence.EntityManager; import org.hibernate.FlushMode; -import org.hibernate.annotations.FlushModeType; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import javax.management.InvalidApplicationException; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.List; @@ -99,7 +96,7 @@ public class LanguageServiceImpl implements LanguageService { // // this.entityManager.flush(); - return this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Language._id), data); + return this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Language._id), data); } public String getPayload(String code) throws IOException { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/lock/LockServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/lock/LockServiceImpl.java index db83d6bad..779bf5316 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/lock/LockServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/lock/LockServiceImpl.java @@ -11,7 +11,6 @@ import eu.eudat.model.builder.LockBuilder; import eu.eudat.model.deleter.LockDeleter; import eu.eudat.model.persist.LockPersist; import eu.eudat.query.LockQuery; -import eu.eudat.query.lookup.LockLookup; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.deleter.DeleterFactory; @@ -104,11 +103,11 @@ public class LockServiceImpl implements LockService { this.entityManager.flush(); - return this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Lock._id), data); + return this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Lock._id), data); } public boolean isLocked(UUID target) throws InvalidApplicationException { - LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).targetIds(target); + LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).targetIds(target); if (query.count() == 1) { LockEntity lock = query.first(); if (lock.getLockedBy().equals(this.userScope.getUserId())) { @@ -128,7 +127,7 @@ public class LockServiceImpl implements LockService { private Long forceUnlock(UUID target) throws InvalidApplicationException { - LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).targetIds(target); + LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).targetIds(target); Long availableLocks = query.count(); long deletedLocks = 0L; if (availableLocks > 0) { @@ -154,7 +153,7 @@ public class LockServiceImpl implements LockService { public void unlock(UUID target) throws InvalidApplicationException { - LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).targetIds(target); + LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).targetIds(target); if (query.count() == 1) { LockEntity lock = query.first(); if (!lock.getLockedBy().equals(this.userScope.getUserId())) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java index a7562b085..aee9507a6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java @@ -144,7 +144,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { this.entityManager.flush(); - return this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, PrefillingSource._id), data); + return this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, PrefillingSource._id), data); } private @NotNull PrefillingSourceDefinitionEntity buildDefinitionEntity(PrefillingSourceDefinitionPersist persist) { @@ -361,7 +361,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { eu.eudat.commons.types.descriptiontemplate.DefinitionEntity descriptionTemplateDefinition = this.xmlHandlingService.fromXml(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); Description description = new Description(); - description.setDescriptionTemplate(this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, descriptionTemplateEntity)); + description.setDescriptionTemplate(this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, descriptionTemplateEntity)); return mapPrefilledEntityToDescription(description, descriptionTemplateDefinition, prefillingSourceDefinition, prefillingSourceEntity.getLabel(), externalData.getResults().getFirst());//TODO } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/reference/ReferenceServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/reference/ReferenceServiceImpl.java index cb651d17b..4fc5a90df 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/reference/ReferenceServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/reference/ReferenceServiceImpl.java @@ -122,7 +122,7 @@ public class ReferenceServiceImpl implements ReferenceService { this.entityManager.flush(); - return this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Reference._id), data); + return this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Reference._id), data); } private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist){ @@ -187,7 +187,7 @@ public class ReferenceServiceImpl implements ReferenceService { ReferenceEntity referenceEntity = buildReferenceEntityFromExternalData(result, data); referenceEntities.add(referenceEntity); } - externalModels = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), referenceEntities); + externalModels = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), referenceEntities); } List models = this.fetchReferenceFromDb(lookup); @@ -236,10 +236,10 @@ public class ReferenceServiceImpl implements ReferenceService { } private List fetchReferenceFromDb(ReferenceSearchLookup lookup){ - ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).sourceTypes(ReferenceSourceType.Internal).typeIds(lookup.getTypeId()); + ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).sourceTypes(ReferenceSourceType.Internal).typeIds(lookup.getTypeId()); List data = query.collectAs(lookup.getProject()); - return this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + return this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); } private ExternalDataResult getReferenceData(ReferenceTypeEntity referenceType, ExternalReferenceCriteria externalReferenceCriteria, String key) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java index 6469ac3fe..3f775bb96 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java @@ -102,7 +102,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { this.entityManager.flush(); - return this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, ReferenceType._id), data); + return this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, ReferenceType._id), data); } private @NotNull ReferenceTypeDefinitionEntity buildDefinitionEntity(ReferenceTypeDefinitionPersist persist){ diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/storage/StorageFileServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/storage/StorageFileServiceImpl.java index 9bb613023..78ac1b150 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/storage/StorageFileServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/storage/StorageFileServiceImpl.java @@ -7,7 +7,6 @@ import eu.eudat.commons.enums.StorageType; import eu.eudat.commons.enums.SupportiveMaterialFieldType; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.StorageFileEntity; -import eu.eudat.model.Description; import eu.eudat.model.StorageFile; import eu.eudat.model.builder.StorageFileBuilder; import eu.eudat.model.persist.StorageFilePersist; @@ -94,7 +93,7 @@ public class StorageFileServiceImpl implements StorageFileService { this.entityManager.persist(storageFile); this.entityManager.flush(); - return this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, StorageFile._id), storageFile); + return this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, StorageFile._id), storageFile); } @Override @@ -142,7 +141,7 @@ public class StorageFileServiceImpl implements StorageFileService { file.delete(); this.entityManager.merge(storageFile); - return this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, StorageFile._id), storageFile); + return this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, StorageFile._id), storageFile); } catch (Exception ex) { logger.warn("problem reading byte content of storage file " + fileId, ex); @@ -181,7 +180,7 @@ public class StorageFileServiceImpl implements StorageFileService { this.entityManager.persist(data); this.entityManager.merge(storageFile); - return this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, StorageFile._id), storageFile); + return this.builderFactory.builder(StorageFileBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, StorageFile._id), storageFile); } catch (Exception ex) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java index 208fed715..09f5163e4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/supportivematerial/SupportiveMaterialServiceImpl.java @@ -30,21 +30,12 @@ import jakarta.xml.bind.JAXBException; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import javax.management.InvalidApplicationException; -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Path; import java.time.Instant; import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; -import java.util.stream.Stream; @Service @@ -104,7 +95,7 @@ public class SupportiveMaterialServiceImpl implements SupportiveMaterialService{ if (d == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), SupportiveMaterial.class.getSimpleName()}, LocaleContextHolder.getLocale())); } else { - List data = this.queryFactory.query(SupportiveMaterialQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).languageCodes(model.getLanguageCode()).types(model.getType()).collect(); + List data = this.queryFactory.query(SupportiveMaterialQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).languageCodes(model.getLanguageCode()).types(model.getType()).collect(); if(data != null && !data.isEmpty()){ throw new MyApplicationException("Could not create a new Data with same type and lang code !"); @@ -126,7 +117,7 @@ public class SupportiveMaterialServiceImpl implements SupportiveMaterialService{ this.entityManager.flush(); - return this.builderFactory.builder(SupportiveMaterialBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, SupportiveMaterial._id), d); + return this.builderFactory.builder(SupportiveMaterialBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, SupportiveMaterial._id), d); } public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/tag/TagServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/tag/TagServiceImpl.java index d88ecc8a4..71debbb0e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/tag/TagServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/tag/TagServiceImpl.java @@ -112,7 +112,7 @@ public class TagServiceImpl implements TagService { this.entityManager.flush(); this.eventBroker.emit(new TagTouchedEvent(data.getId())); - return this.builderFactory.builder(TagBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Tag._id), data); + return this.builderFactory.builder(TagBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Tag._id), data); } public 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 b05211a6a..393495331 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 @@ -130,7 +130,7 @@ public class TenantServiceImpl implements TenantService { this.entityManager.flush(); - return this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Tenant._id), data); + return this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Tenant._id), data); } private @NotNull TenantConfigEntity buildConfigEntity(TenantConfigPersist persist) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java index 4fddcc3e4..a03851d47 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerServiceImpl.java @@ -134,8 +134,8 @@ public class FileTransformerServiceImpl implements FileTransformerService { TransformerRepository repository = getRepository(repositoryId); if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{repositoryId, TransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale())); //GK: Second get the Target Data Management Plan - DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(dmpId); - DmpModel dmpFileTransformerModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first()); + DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(dmpId); + DmpModel dmpFileTransformerModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(query.first()); if (dmpFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); FileEnvelopeModel fileEnvelope = repository.exportDmp(dmpFileTransformerModel, format); @@ -155,8 +155,8 @@ public class FileTransformerServiceImpl implements FileTransformerService { if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{format, TransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale())); //GK: Second get the Target Data Management Plan - DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(descriptionId); - DescriptionModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first()); + DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(descriptionId); + DescriptionModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(query.first()); if (descriptionFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); FileEnvelopeModel fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, format); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java index d49a4c553..ce9a20cc7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java @@ -178,7 +178,7 @@ public class UserServiceImpl implements UserService { this.eventBroker.emit(new UserTouchedEvent(data.getId())); this.userTouchedIntegrationEventHandler.handle(data.getId()); - return this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, User._id), data); + return this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, User._id), data); } private @NotNull AdditionalInfoEntity buildAdditionalInfoEntity(UserAdditionalInfoPersist persist){ @@ -276,7 +276,7 @@ public class UserServiceImpl implements UserService { this.eventBroker.emit(new UserTouchedEvent(data.getId())); this.userTouchedIntegrationEventHandler.handle(data.getId()); - return this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, User._id), data); + return this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, User._id), data); } //region mine diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/user/settings/UserSettingsServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/user/settings/UserSettingsServiceImpl.java index bedbee0d5..0406a2a58 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/user/settings/UserSettingsServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/user/settings/UserSettingsServiceImpl.java @@ -96,7 +96,7 @@ public class UserSettingsServiceImpl implements UserSettingsService { this.entityManager.flush(); - return this.builderFactory.builder(UserSettingsBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, UserSettings._id, UserSettings._key), data); + return this.builderFactory.builder(UserSettingsBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, UserSettings._id, UserSettings._key), data); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionController.java index 49853397f..d33850bb9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionController.java @@ -2,19 +2,15 @@ package eu.eudat.controllers; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.authorization.Permission; import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.IsActive; -import eu.eudat.commons.enums.StorageType; import eu.eudat.convention.ConventionService; import eu.eudat.data.StorageFileEntity; import eu.eudat.model.StorageFile; import eu.eudat.model.builder.PublicDescriptionBuilder; import eu.eudat.model.persist.DescriptionFieldFilePersist; -import eu.eudat.model.persist.StorageFilePersist; import eu.eudat.service.storage.StorageFileService; -import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.validation.ValidationFilterAnnotation; import eu.eudat.model.Description; import eu.eudat.model.Dmp; @@ -40,7 +36,6 @@ import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; -import org.apache.commons.io.FilenameUtils; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -54,8 +49,6 @@ import org.springframework.web.multipart.MultipartFile; import javax.management.InvalidApplicationException; import java.io.IOException; -import java.net.URLConnection; -import java.time.Duration; import java.util.*; import static eu.eudat.authorization.AuthorizationFlags.Public; @@ -138,7 +131,7 @@ public class DescriptionController { this.censorFactory.censor(DescriptionCensor.class).censor(lookup.getProject(), null); - QueryResult queryResult = this.elasticQueryHelperService.collect(lookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic, null); + QueryResult queryResult = this.elasticQueryHelperService.collect(lookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermission, null); this.auditService.track(AuditableAction.Description_Query, "lookup", lookup); @@ -152,8 +145,8 @@ public class DescriptionController { this.censorFactory.censor(DescriptionCensor.class).censor(fieldSet, null); - DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Description model = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + Description model = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java index 87eb1dbca..d6e85ac00 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateController.java @@ -85,10 +85,10 @@ public class DescriptionTemplateController { this.censorFactory.censor(DescriptionTemplateCensor.class).censor(lookup.getProject(), null); - DescriptionTemplateQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + DescriptionTemplateQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.DescriptionTemplate_Query, "lookup", lookup); @@ -102,8 +102,8 @@ public class DescriptionTemplateController { this.censorFactory.censor(DescriptionTemplateCensor.class).censor(fieldSet, null); - DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - DescriptionTemplate model = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + DescriptionTemplate model = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java index fe84db4d6..bee0ba547 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DescriptionTemplateTypeController.java @@ -23,7 +23,6 @@ import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.validation.ValidationFilterAnnotation; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.transaction.annotation.Transactional; @@ -69,10 +68,10 @@ public class DescriptionTemplateTypeController { this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject(), null); - DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup); @@ -87,8 +86,8 @@ public class DescriptionTemplateTypeController { this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(fieldSet, null); - DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - DescriptionTemplateType model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + DescriptionTemplateType model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpBlueprintController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpBlueprintController.java index 50d84caf0..8d2c61726 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpBlueprintController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpBlueprintController.java @@ -81,10 +81,10 @@ public class DmpBlueprintController { logger.debug("querying {}", DmpBlueprint.class.getSimpleName()); this.censorFactory.censor(DmpBlueprintCensor.class).censor(lookup.getProject(), null); - DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.DmpBlueprint_Query, "lookup", lookup); @@ -98,8 +98,8 @@ public class DmpBlueprintController { this.censorFactory.censor(DmpBlueprintCensor.class).censor(fieldSet, null); - DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - DmpBlueprint model = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + DmpBlueprint model = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpController.java index e6cfe2181..e31b0b3ef 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DmpController.java @@ -5,11 +5,7 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.IsActive; -import eu.eudat.model.builder.DescriptionBuilder; import eu.eudat.model.builder.PublicDmpBuilder; -import eu.eudat.model.censorship.PublicDescriptionCensor; -import eu.eudat.query.DescriptionQuery; -import eu.eudat.query.DmpDescriptionTemplateQuery; import gr.cite.tools.validation.ValidationFilterAnnotation; import eu.eudat.model.*; import eu.eudat.model.builder.DmpBuilder; @@ -123,8 +119,7 @@ public class DmpController { this.censorFactory.censor(DmpCensor.class).censor(lookup.getProject(), null); - - QueryResult queryResult = this.elasticQueryHelperService.collect(lookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic, null); + QueryResult queryResult = this.elasticQueryHelperService.collect(lookup, AuthorizationFlags.OwnerOrDmpAssociatedOrPermission, null); this.auditService.track(AuditableAction.Dmp_Query, "lookup", lookup); @@ -137,8 +132,8 @@ public class DmpController { this.censorFactory.censor(DmpCensor.class).censor(fieldSet, null); - DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Dmp model = this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + Dmp model = this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/EntityDoiController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/EntityDoiController.java index 4e8914dd4..86e2cfc10 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/EntityDoiController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/EntityDoiController.java @@ -75,10 +75,10 @@ public class EntityDoiController { this.censorFactory.censor(EntityDoiCensor.class).censor(lookup.getProject(), null); - EntityDoiQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + EntityDoiQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.EntityDoi_Query, "lookup", lookup); @@ -92,8 +92,8 @@ public class EntityDoiController { this.censorFactory.censor(EntityDoiCensor.class).censor(fieldSet, null); - EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - EntityDoi model = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + EntityDoi model = this.builderFactory.builder(EntityDoiBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, EntityDoi.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java index 7b81bb6df..c2427ce6c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java @@ -6,7 +6,6 @@ import eu.eudat.authorization.AuthorizationFlags; import gr.cite.tools.validation.ValidationFilterAnnotation; import eu.eudat.data.LanguageEntity; import eu.eudat.model.Language; -import eu.eudat.model.UserContactInfo; import eu.eudat.model.builder.LanguageBuilder; import eu.eudat.model.censorship.LanguageCensor; import eu.eudat.model.persist.LanguagePersist; @@ -35,12 +34,11 @@ import org.springframework.web.bind.annotation.*; import javax.management.InvalidApplicationException; import java.io.IOException; -import java.util.AbstractMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; +import static eu.eudat.authorization.AuthorizationFlags.Public; + @RestController @RequestMapping(path = {"api/language"}) public class LanguageController { @@ -81,9 +79,9 @@ public class LanguageController { this.censorFactory.censor(LanguageCensor.class).censor(lookup.getProject(), null); - LanguageQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + LanguageQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.Language_Query, "lookup", lookup); @@ -97,8 +95,8 @@ public class LanguageController { this.censorFactory.censor(LanguageCensor.class).censor(fieldSet, null); - LanguageQuery query = this.queryFactory.query(LanguageQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Language model = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + LanguageQuery query = this.queryFactory.query(LanguageQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + Language model = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Language.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -116,8 +114,8 @@ public class LanguageController { this.censorFactory.censor(LanguageCensor.class).censor(fieldSet, null); - LanguageQuery query = this.queryFactory.query(LanguageQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).codes(code); - Language model = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + LanguageQuery query = this.queryFactory.query(LanguageQuery.class).authorize(EnumSet.of(Public)).codes(code); + Language model = this.builderFactory.builder(LanguageBuilder.class).authorize(EnumSet.of(Public)).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{code, Language.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -139,10 +137,10 @@ public class LanguageController { this.censorFactory.censor(LanguageCensor.class).censor(lookup.getProject(), null); - LanguageQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + LanguageQuery query = lookup.enrich(this.queryFactory).authorize(EnumSet.of(Public)); query.setOrder(new Ordering().addAscending(Language._ordinal)); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(LanguageBuilder.class).authorize(EnumSet.of(Public)).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/LockController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/LockController.java index cd298d48f..1478f3cb2 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/LockController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/LockController.java @@ -85,9 +85,9 @@ public class LockController { this.censorFactory.censor(LockCensor.class).censor(lookup.getProject(), null); - LockQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + LockQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.Lock_Query, "lookup", lookup); @@ -101,8 +101,8 @@ public class LockController { this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); - LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Lock.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -137,8 +137,8 @@ public class LockController { this.censorFactory.censor(LockCensor.class).censor(fieldSet, null); - LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).targetIds(targetId); - Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + LockQuery query = this.queryFactory.query(LockQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).targetIds(targetId); + Lock model = this.builderFactory.builder(LockBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{targetId, Lock.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java index 070e3323e..fa55207df 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/PrefillingSourceController.java @@ -89,9 +89,9 @@ public class PrefillingSourceController { this.censorFactory.censor(PrefillingSourceCensor.class).censor(lookup.getProject(), null); - PrefillingSourceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + PrefillingSourceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.PrefillingSource_Query, "lookup", lookup); @@ -105,8 +105,8 @@ public class PrefillingSourceController { this.censorFactory.censor(PrefillingSourceCensor.class).censor(fieldSet, null); - PrefillingSourceQuery query = this.queryFactory.query(PrefillingSourceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - PrefillingSource model = this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + PrefillingSourceQuery query = this.queryFactory.query(PrefillingSourceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + PrefillingSource model = this.builderFactory.builder(PrefillingSourceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceController.java index 7bd8d3a80..524537af6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceController.java @@ -81,9 +81,9 @@ public class ReferenceController { this.censorFactory.censor(ReferenceCensor.class).censor(lookup.getProject(), null); - ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.Reference_Query, "lookup", lookup); @@ -111,8 +111,8 @@ public class ReferenceController { this.censorFactory.censor(ReferenceCensor.class).censor(fieldSet, null); - ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Reference model = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + Reference model = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Reference.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceTypeController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceTypeController.java index 40a56d931..9e536047d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceTypeController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/ReferenceTypeController.java @@ -5,7 +5,6 @@ import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; import gr.cite.tools.validation.ValidationFilterAnnotation; import eu.eudat.data.ReferenceTypeEntity; -import eu.eudat.model.Reference; import eu.eudat.model.ReferenceType; import eu.eudat.model.builder.ReferenceTypeBuilder; import eu.eudat.model.censorship.ReferenceTypeCensor; @@ -81,9 +80,9 @@ public class ReferenceTypeController{ this.censorFactory.censor(ReferenceTypeCensor.class).censor(lookup.getProject(), null); - ReferenceTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + ReferenceTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.ReferenceType_Query, "lookup", lookup); @@ -97,8 +96,8 @@ public class ReferenceTypeController{ this.censorFactory.censor(ReferenceTypeCensor.class).censor(fieldSet, null); - ReferenceTypeQuery query = this.queryFactory.query(ReferenceTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - ReferenceType model = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + ReferenceTypeQuery query = this.queryFactory.query(ReferenceTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + ReferenceType model = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -116,8 +115,8 @@ public class ReferenceTypeController{ this.censorFactory.censor(ReferenceTypeCensor.class).censor(fieldSet, null); - ReferenceTypeQuery query = this.queryFactory.query(ReferenceTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).codes(code); - ReferenceType model = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + ReferenceTypeQuery query = this.queryFactory.query(ReferenceTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).codes(code); + ReferenceType model = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{code, ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/SupportiveMaterialController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/SupportiveMaterialController.java index b99505c77..405670876 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/SupportiveMaterialController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/SupportiveMaterialController.java @@ -1,11 +1,9 @@ package eu.eudat.controllers; import com.fasterxml.jackson.core.JsonProcessingException; -import com.tdunning.math.stats.Sort; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.SupportiveMaterialFieldType; -import eu.eudat.service.storage.StorageFileService; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.validation.ValidationFilterAnnotation; import eu.eudat.data.SupportiveMaterialEntity; @@ -17,7 +15,6 @@ import eu.eudat.model.result.QueryResult; import eu.eudat.query.SupportiveMaterialQuery; import eu.eudat.query.lookup.SupportiveMaterialLookup; import eu.eudat.service.supportivematerial.SupportiveMaterialService; -import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.censor.CensorFactory; @@ -83,9 +80,9 @@ public class SupportiveMaterialController { this.censorFactory.censor(SupportiveMaterialCensor.class).censor(lookup.getProject(), null); - SupportiveMaterialQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + SupportiveMaterialQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(SupportiveMaterialBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(SupportiveMaterialBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.SupportiveMaterial_Query, "lookup", lookup); @@ -99,8 +96,8 @@ public class SupportiveMaterialController { this.censorFactory.censor(SupportiveMaterialCensor.class).censor(fieldSet, null); - SupportiveMaterialQuery query = this.queryFactory.query(SupportiveMaterialQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - SupportiveMaterial model = this.builderFactory.builder(SupportiveMaterialBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + SupportiveMaterialQuery query = this.queryFactory.query(SupportiveMaterialQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + SupportiveMaterial model = this.builderFactory.builder(SupportiveMaterialBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, SupportiveMaterial.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -117,7 +114,7 @@ public class SupportiveMaterialController { logger.debug("querying {}", SupportiveMaterial.class.getSimpleName()); - SupportiveMaterialQuery query = this.queryFactory.query(SupportiveMaterialQuery.class).types(SupportiveMaterialFieldType.of(type)).languageCodes(language).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + SupportiveMaterialQuery query = this.queryFactory.query(SupportiveMaterialQuery.class).types(SupportiveMaterialFieldType.of(type)).languageCodes(language).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(new BaseFieldSet().ensure(SupportiveMaterial._id).ensure(SupportiveMaterial._payload)); byte[] content; if (data.size() == 1) content = data.getFirst().getPayload().getBytes(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java index ef8a9b4d0..734d7bae6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java @@ -23,7 +23,6 @@ import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.transaction.annotation.Transactional; @@ -71,10 +70,10 @@ public class TagController { this.censorFactory.censor(TagCensor.class).censor(lookup.getProject(), null); - TagQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + TagQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(TagBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(TagBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.Tag_Query, "lookup", lookup); @@ -88,8 +87,8 @@ public class TagController { this.censorFactory.censor(TagCensor.class).censor(fieldSet, null); - TagQuery query = this.queryFactory.query(TagQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Tag model = this.builderFactory.builder(TagBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + TagQuery query = this.queryFactory.query(TagQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + Tag model = this.builderFactory.builder(TagBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Tag.class.getSimpleName()}, LocaleContextHolder.getLocale())); 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 1dcbd2be4..4eafcaf46 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 @@ -82,10 +82,10 @@ public class TenantController { logger.debug("querying {}", Tenant.class.getSimpleName()); this.censorFactory.censor(TenantCensor.class).censor(lookup.getProject(), null); - TenantQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + TenantQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + 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)); } @@ -102,8 +102,8 @@ public class TenantController { this.censorFactory.censor(TenantCensor.class).censor(fieldSet, null); - TenantQuery query = this.queryFactory.query(TenantQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - Tenant model = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + TenantQuery query = this.queryFactory.query(TenantQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + Tenant model = this.builderFactory.builder(TenantBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Tenant.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserController.java index 783758510..904feea1a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserController.java @@ -98,10 +98,10 @@ public class UserController { this.censorFactory.censor(UserCensor.class).censor(lookup.getProject(), null); - UserQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + UserQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.User_Query, "lookup", lookup); @@ -118,7 +118,7 @@ public class UserController { UserQuery query = lookup.enrich(this.queryFactory).dmpAssociated(true).isActive(IsActive.Active); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(DmpAssociatedUserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(DmpAssociatedUserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.User_DmpAssociatedQuery, "lookup", lookup); @@ -132,8 +132,8 @@ public class UserController { this.censorFactory.censor(UserCensor.class).censor(fieldSet, id); - UserQuery query = this.queryFactory.query(UserQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(id); - User model = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + UserQuery query = this.queryFactory.query(UserQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id); + User model = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, User.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -151,8 +151,8 @@ public class UserController { this.censorFactory.censor(UserCensor.class).censor(fieldSet, null); - UserQuery query = this.queryFactory.query(UserQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).emails(email); - User model = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + UserQuery query = this.queryFactory.query(UserQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).emails(email); + User model = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{email, User.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -183,8 +183,8 @@ public class UserController { this.censorFactory.censor(UserCensor.class).censor(fieldSet, this.userScope.getUserId()); - UserQuery query = this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); - User model = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + UserQuery query = this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); + User model = this.builderFactory.builder(UserBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{this.userScope.getUserId(), User.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserSettingsController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserSettingsController.java index fc6c83d97..8b62b77ef 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserSettingsController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserSettingsController.java @@ -73,9 +73,9 @@ public class UserSettingsController { public QueryResult Query(@RequestBody UserSettingsLookup lookup) throws MyApplicationException, MyForbiddenException { logger.debug("querying {}", UserSettings.class.getSimpleName()); this.censorFactory.censor(UserSettingsCensor.class).censor(lookup.getProject(), null); - UserSettingsQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic); + UserSettingsQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission); List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(UserSettingsBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data); + List models = this.builderFactory.builder(UserSettingsBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.User_Settings_Query, "lookup", lookup); @@ -98,8 +98,8 @@ public class UserSettingsController { UserSettings._updatedAt, UserSettings._type )); - UserSettingsQuery query = this.queryFactory.query(UserSettingsQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).keys(key); - UserSettings model = this.builderFactory.builder(UserSettingsBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet)); + UserSettingsQuery query = this.queryFactory.query(UserSettingsQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).keys(key); + UserSettings model = this.builderFactory.builder(UserSettingsBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); this.auditService.track(AuditableAction.User_Settings_Lookup, Map.ofEntries( new AbstractMap.SimpleEntry("key", key) diff --git a/dmp-backend/web/src/main/resources/config/permissions.yml b/dmp-backend/web/src/main/resources/config/permissions.yml index 553e0823f..1e3f21f34 100644 --- a/dmp-backend/web/src/main/resources/config/permissions.yml +++ b/dmp-backend/web/src/main/resources/config/permissions.yml @@ -2,48 +2,29 @@ permissions: extendedClaims: [ ] policies: ###### Should Remove after Refactor - PublicRole: - roles: [ ] - clients: [ ] - allowAnonymous: true - allowAuthenticated: true AdminRole: roles: - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false - DescriptionTemplateEditorRole: - roles: - - DescriptionTemplateEditor - clients: [ ] - allowAnonymous: false - allowAuthenticated: false - ManagerRole: - roles: - - Manager - clients: [ ] - allowAnonymous: false - allowAuthenticated: false - UserRole: - roles: - - User - clients: [ ] - allowAnonymous: false - allowAuthenticated: false AuthenticatedRole: roles: [] clients: [ ] allowAnonymous: false allowAuthenticated: true - AnonymousRole: - roles: [] - clients: [ ] - allowAnonymous: true - allowAuthenticated: true ###### - + # public + DeferredAffiliation: + roles: + - Admin + - User + - Manager + - DescriptionTemplateEditor + clients: [ ] + allowAnonymous: false + allowAuthenticated: false # public PublicBrowseDescription: roles: [ ] @@ -278,6 +259,8 @@ permissions: roles: - Admin - DescriptionTemplateEditor + - Manager + - User clients: [ ] allowAnonymous: false allowAuthenticated: false @@ -341,6 +324,15 @@ permissions: clients: [ ] allowAnonymous: false allowAuthenticated: false + NewDmp: + roles: + - Admin + - User + - Manager + - DescriptionTemplateEditor + clients: [ ] + allowAnonymous: false + allowAuthenticated: false DeleteDmp: roles: - Admin @@ -394,6 +386,9 @@ permissions: BrowseDmpBlueprint: roles: - Admin + - User + - Manager + - DescriptionTemplateEditor clients: [ ] allowAnonymous: false allowAuthenticated: false diff --git a/dmp-frontend/src/app/core/common/enum/permission.enum.ts b/dmp-frontend/src/app/core/common/enum/permission.enum.ts index c04f5e813..b537deeea 100644 --- a/dmp-frontend/src/app/core/common/enum/permission.enum.ts +++ b/dmp-frontend/src/app/core/common/enum/permission.enum.ts @@ -17,6 +17,7 @@ export enum AppPermission { //Dmp BrowseDmp = "BrowseDmp", EditDmp = "EditDmp", + NewDmp = "NewDmp", DeleteDmp= "DeleteDmp", CloneDmp = "CloneDmp", CreateNewVersionDmp = "CreateNewVersionDmp",