diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/actionconfirmation/RemoveCredentialConfirmationEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/actionconfirmation/RemoveCredentialRequestEntity.java similarity index 92% rename from dmp-backend/core/src/main/java/eu/eudat/commons/types/actionconfirmation/RemoveCredentialConfirmationEntity.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/actionconfirmation/RemoveCredentialRequestEntity.java index a7e58c98e..773c9aacc 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/actionconfirmation/RemoveCredentialConfirmationEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/actionconfirmation/RemoveCredentialRequestEntity.java @@ -9,7 +9,7 @@ import java.util.UUID; @XmlRootElement(name = "remove-credential-confirmation") @XmlAccessorType(XmlAccessType.FIELD) -public class RemoveCredentialConfirmationEntity { +public class RemoveCredentialRequestEntity { @XmlAttribute(name = "credential-id") private UUID credentialId; diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/usercredential/UserCredentialDataEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/usercredential/UserCredentialDataEntity.java new file mode 100644 index 000000000..22bdca050 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/usercredential/UserCredentialDataEntity.java @@ -0,0 +1,24 @@ +package eu.eudat.commons.types.usercredential; + +import java.util.List; + +public class UserCredentialDataEntity { + private List providers; + private String email; + + public List getProviders() { + return providers; + } + + public void setProviders(List providers) { + this.providers = providers; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/UserCredentialEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/UserCredentialEntity.java index 98cd557da..2cad41cf5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/UserCredentialEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/UserCredentialEntity.java @@ -20,7 +20,11 @@ public class UserCredentialEntity extends TenantScopedBaseEntity { @Column(name = "\"user\"", columnDefinition = "uuid", nullable = false) private UUID userId; - public final static String _userId = "userId"; + public final static String _userId = "userId"; + + @Column(name = "data", nullable = true) + private String data; + public final static String _data = "data"; @Column(name = "\"external_id\"", length = UserCredentialEntity._externalIdLength, nullable = false) private String externalId; @@ -63,4 +67,12 @@ public class UserCredentialEntity extends TenantScopedBaseEntity { public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/ActionConfirmation.java b/dmp-backend/core/src/main/java/eu/eudat/model/ActionConfirmation.java index a26bb22d0..39c9a0bad 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/ActionConfirmation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/ActionConfirmation.java @@ -4,7 +4,10 @@ import eu.eudat.commons.enums.ActionConfirmationStatus; import eu.eudat.commons.enums.ActionConfirmationType; import eu.eudat.commons.enums.IsActive; import eu.eudat.model.actionconfirmation.DmpInvitation; -import eu.eudat.model.actionconfirmation.EmailConfirmation; +import eu.eudat.model.actionconfirmation.MergeAccountConfirmation; +import eu.eudat.model.actionconfirmation.RemoveCredentialRequest; +import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist; +import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist; import java.time.Instant; import java.util.UUID; @@ -19,9 +22,13 @@ public class ActionConfirmation { private ActionConfirmationStatus status; public static final String _status = "status"; + private MergeAccountConfirmation mergeAccountConfirmation; - private EmailConfirmation emailConfirmation; - public static final String _emailConfirmation = "emailConfirmation"; + public static final String _mergeAccountConfirmation = "mergeAccountConfirmation"; + + private RemoveCredentialRequest removeCredentialRequest; + + public static final String _removeCredentialRequest = "removeCredentialRequest"; private DmpInvitation dmpInvitation; public static final String _dmpInvitation = "dmpInvitation"; @@ -72,14 +79,6 @@ public class ActionConfirmation { this.status = status; } - public EmailConfirmation getEmailConfirmation() { - return emailConfirmation; - } - - public void setEmailConfirmation(EmailConfirmation emailConfirmation) { - this.emailConfirmation = emailConfirmation; - } - public DmpInvitation getDmpInvitation() { return dmpInvitation; } @@ -143,4 +142,20 @@ public class ActionConfirmation { public void setHash(String hash) { this.hash = hash; } + + public MergeAccountConfirmation getMergeAccountConfirmation() { + return mergeAccountConfirmation; + } + + public void setMergeAccountConfirmation(MergeAccountConfirmation mergeAccountConfirmation) { + this.mergeAccountConfirmation = mergeAccountConfirmation; + } + + public RemoveCredentialRequest getRemoveCredentialRequest() { + return removeCredentialRequest; + } + + public void setRemoveCredentialRequest(RemoveCredentialRequest removeCredentialRequest) { + this.removeCredentialRequest = removeCredentialRequest; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/UserCredential.java b/dmp-backend/core/src/main/java/eu/eudat/model/UserCredential.java index 94adbe697..ff54198df 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/UserCredential.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/UserCredential.java @@ -1,5 +1,7 @@ package eu.eudat.model; +import eu.eudat.model.usercredential.UserCredentialData; + import java.time.Instant; import java.util.UUID; @@ -16,6 +18,8 @@ public class UserCredential { private Instant createdAt; public static final String _createdAt = "createdAt"; + private UserCredentialData data; + public static final String _data = "data"; public UUID getId() { return id; @@ -48,4 +52,12 @@ public class UserCredential { public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; } + + public UserCredentialData getData() { + return data; + } + + public void setData(UserCredentialData data) { + this.data = data; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/EmailConfirmation.java b/dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/MergeAccountConfirmation.java similarity index 86% rename from dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/EmailConfirmation.java rename to dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/MergeAccountConfirmation.java index 08586edd5..3944c5742 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/EmailConfirmation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/MergeAccountConfirmation.java @@ -1,7 +1,7 @@ package eu.eudat.model.actionconfirmation; -public class EmailConfirmation { +public class MergeAccountConfirmation { private String email; public static final String _email = "email"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/RemoveCredentialRequest.java b/dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/RemoveCredentialRequest.java new file mode 100644 index 000000000..fbd630358 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/actionconfirmation/RemoveCredentialRequest.java @@ -0,0 +1,31 @@ +package eu.eudat.model.actionconfirmation; + +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.commons.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +public class RemoveCredentialRequest { + + private UUID credentialId; + public static final String _credentialId = "credentialId"; + + public UUID getCredentialId() { + return credentialId; + } + + public void setCredentialId(UUID credentialId) { + this.credentialId = credentialId; + } + +} + diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ActionConfirmationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ActionConfirmationBuilder.java index 8a7fe7e2e..02eb98d40 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ActionConfirmationBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ActionConfirmationBuilder.java @@ -5,13 +5,15 @@ import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.ActionConfirmationType; import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity; import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity; +import eu.eudat.commons.types.actionconfirmation.RemoveCredentialRequestEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.ActionConfirmationEntity; import eu.eudat.model.ActionConfirmation; import eu.eudat.model.Tenant; import eu.eudat.model.User; import eu.eudat.model.builder.actionconfirmation.DmpInvitationBuilder; -import eu.eudat.model.builder.actionconfirmation.EmailConfirmationBuilder; +import eu.eudat.model.builder.actionconfirmation.MergeAccountConfirmationBuilder; +import eu.eudat.model.builder.actionconfirmation.RemoveCredentialRequestBuilder; import eu.eudat.query.TenantQuery; import eu.eudat.query.UserQuery; import gr.cite.tools.data.builder.BuilderFactory; @@ -56,7 +58,8 @@ public class ActionConfirmationBuilder extends BaseBuilder(); - FieldSet emailConfirmationFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._emailConfirmation)); + FieldSet mergeAccountConfirmationFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._mergeAccountConfirmation)); + FieldSet removeCredentialRequestFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._removeCredentialRequest)); FieldSet dmpInvitationFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._dmpInvitation)); FieldSet userFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._createdBy)); @@ -73,13 +76,22 @@ public class ActionConfirmationBuilder extends BaseBuilder { + MergeAccountConfirmationEntity emailConfirmation = this.xmlHandlingService.fromXmlSafe(MergeAccountConfirmationEntity.class, d.getData()); + m.setMergeAccountConfirmation(this.builderFactory.builder(MergeAccountConfirmationBuilder.class).authorize(this.authorize).build(mergeAccountConfirmationFields, emailConfirmation)); + } + case DmpInvitation -> { + DmpInvitationEntity dmpInvitation = this.xmlHandlingService.fromXmlSafe(DmpInvitationEntity.class, d.getData()); + m.setDmpInvitation(this.builderFactory.builder(DmpInvitationBuilder.class).authorize(this.authorize).build(dmpInvitationFields, dmpInvitation)); + } + case RemoveCredential -> { + RemoveCredentialRequestEntity emailConfirmation = this.xmlHandlingService.fromXmlSafe(RemoveCredentialRequestEntity.class, d.getData()); + m.setRemoveCredentialRequest(this.builderFactory.builder(RemoveCredentialRequestBuilder.class).authorize(this.authorize).build(removeCredentialRequestFields, emailConfirmation)); + } + default -> throw new InternalError("unknown type: " + d.getType()); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/UserCredentialBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/UserCredentialBuilder.java index c32a85c0b..242f4ca89 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/UserCredentialBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/UserCredentialBuilder.java @@ -1,10 +1,16 @@ package eu.eudat.model.builder; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.JsonHandlingService; +import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.commons.types.usercredential.UserCredentialDataEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.UserCredentialEntity; +import eu.eudat.model.Description; import eu.eudat.model.User; import eu.eudat.model.UserCredential; +import eu.eudat.model.builder.descriptionpropertiesdefinition.PropertyDefinitionBuilder; +import eu.eudat.model.builder.usercredential.UserCredentialDataBuilder; import eu.eudat.query.UserQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; @@ -29,16 +35,18 @@ public class UserCredentialBuilder extends BaseBuilder authorize = EnumSet.of(AuthorizationFlags.None); @Autowired public UserCredentialBuilder( - ConventionService conventionService, - BuilderFactory builderFactory, QueryFactory queryFactory) { + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory, JsonHandlingService jsonHandlingService) { super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCredentialBuilder.class))); this.builderFactory = builderFactory; this.queryFactory = queryFactory; + this.jsonHandlingService = jsonHandlingService; } public UserCredentialBuilder authorize(EnumSet values) { @@ -55,6 +63,8 @@ public class UserCredentialBuilder extends BaseBuilder userItemsMap = this.collectUsers(userFields, data); + + FieldSet definitionPropertiesFields = fields.extractPrefixed(this.asPrefix(UserCredential._data)); List models = new ArrayList<>(); @@ -64,7 +74,10 @@ public class UserCredentialBuilder extends BaseBuilder { +public class MergeAccountConfirmationBuilder extends BaseBuilder { - private final BuilderFactory builderFactory; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public EmailConfirmationBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(EmailConfirmationBuilder.class))); - this.builderFactory = builderFactory; + public MergeAccountConfirmationBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(MergeAccountConfirmationBuilder.class))); } - public EmailConfirmationBuilder authorize(EnumSet values) { + public MergeAccountConfirmationBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - public List build(FieldSet fields, List data) throws MyApplicationException { + public List build(FieldSet fields, List data) throws MyApplicationException { this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); this.logger.trace(new DataLogEntry("requested fields", fields)); if (fields == null || data == null || fields.isEmpty()) return new ArrayList<>(); - List models = new ArrayList<>(); + List models = new ArrayList<>(); for (MergeAccountConfirmationEntity d : data) { - EmailConfirmation m = new EmailConfirmation(); - if (fields.hasField(this.asIndexer(EmailConfirmation._email))) m.setEmail(d.getEmail()); + MergeAccountConfirmation m = new MergeAccountConfirmation(); + if (fields.hasField(this.asIndexer(MergeAccountConfirmation._email))) m.setEmail(d.getEmail()); models.add(m); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/actionconfirmation/RemoveCredentialRequestBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/actionconfirmation/RemoveCredentialRequestBuilder.java new file mode 100644 index 000000000..8d058974e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/actionconfirmation/RemoveCredentialRequestBuilder.java @@ -0,0 +1,55 @@ +package eu.eudat.model.builder.actionconfirmation; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.actionconfirmation.RemoveCredentialRequestEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.actionconfirmation.RemoveCredentialRequest; +import eu.eudat.model.builder.BaseBuilder; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class RemoveCredentialRequestBuilder extends BaseBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public RemoveCredentialRequestBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(RemoveCredentialRequestBuilder.class))); + } + + public RemoveCredentialRequestBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + + List models = new ArrayList<>(); + for (RemoveCredentialRequestEntity d : data) { + RemoveCredentialRequest m = new RemoveCredentialRequest(); + if (fields.hasField(this.asIndexer(RemoveCredentialRequest._credentialId))) m.setCredentialId(d.getCredentialId()); + + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/usercredential/UserCredentialDataBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/usercredential/UserCredentialDataBuilder.java new file mode 100644 index 000000000..03fad3c98 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/usercredential/UserCredentialDataBuilder.java @@ -0,0 +1,56 @@ +package eu.eudat.model.builder.usercredential; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.usercredential.UserCredentialDataEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.usercredential.UserCredentialData; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component() +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class UserCredentialDataBuilder extends BaseBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public UserCredentialDataBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCredentialDataBuilder.class))); + } + + public UserCredentialDataBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + //Not Bulk Build because is XML no interaction with db + + List models = new ArrayList<>(); + for (UserCredentialDataEntity d : data) { + UserCredentialData m = new UserCredentialData(); + if (fields.hasField(this.asIndexer(UserCredentialData._email))) m.setEmail(d.getEmail()); + if (fields.hasField(this.asIndexer(UserCredentialData._providers))) m.setProviders(d.getProviders()); + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCredentialCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCredentialCensor.java index f3a9e2984..fb4c539e3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCredentialCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserCredentialCensor.java @@ -4,6 +4,7 @@ import eu.eudat.authorization.OwnedResource; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; import eu.eudat.model.UserCredential; +import eu.eudat.model.censorship.usercredential.UserCredentialDataCensor; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -41,6 +42,9 @@ public class UserCredentialCensor extends BaseCensor { FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserCredential._user)); this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId); + + FieldSet dataFields = fields.extractPrefixed(this.asIndexerPrefix(UserCredential._data)); + this.censorFactory.censor(UserCredentialDataCensor.class).censor(dataFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/usercredential/UserCredentialDataCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/usercredential/UserCredentialDataCensor.java new file mode 100644 index 000000000..a505b9854 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/usercredential/UserCredentialDataCensor.java @@ -0,0 +1,44 @@ +package eu.eudat.model.censorship.usercredential; + +import eu.eudat.authorization.OwnedResource; +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.censorship.BaseCensor; +import eu.eudat.model.censorship.DescriptionReferenceCensor; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class UserCredentialDataCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserCredentialDataCensor.class)); + + protected final AuthorizationService authService; + + protected final CensorFactory censorFactory; + + public UserCredentialDataCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) { + super(conventionService); + this.authService = authService; + this.censorFactory = censorFactory; + } + + public void censor(FieldSet fields, UUID userId) { + 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); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java index 7877940a8..2c3a4c831 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/ActionConfirmationPersist.java @@ -9,6 +9,7 @@ import eu.eudat.convention.ConventionService; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist; import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist; +import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/RemoveCredentialRequestPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/RemoveCredentialRequestPersist.java similarity index 97% rename from dmp-backend/core/src/main/java/eu/eudat/model/persist/RemoveCredentialRequestPersist.java rename to dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/RemoveCredentialRequestPersist.java index 51ff4893d..ba4dbb4af 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/RemoveCredentialRequestPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/actionconfirmation/RemoveCredentialRequestPersist.java @@ -1,4 +1,4 @@ -package eu.eudat.model.persist; +package eu.eudat.model.persist.actionconfirmation; import eu.eudat.commons.validation.BaseValidator; import eu.eudat.commons.validation.specification.Specification; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/usercredential/UserCredentialData.java b/dmp-backend/core/src/main/java/eu/eudat/model/usercredential/UserCredentialData.java new file mode 100644 index 000000000..8d819ddfc --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/usercredential/UserCredentialData.java @@ -0,0 +1,26 @@ +package eu.eudat.model.usercredential; + +import java.util.List; + +public class UserCredentialData { + private List providers; + public static final String _providers = "providers"; + private String email; + public static final String _email = "email"; + + public List getProviders() { + return providers; + } + + public void setProviders(List providers) { + this.providers = providers; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/ActionConfirmationQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/ActionConfirmationQuery.java index 6fc7c985d..bf15f3ff7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/ActionConfirmationQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/ActionConfirmationQuery.java @@ -239,7 +239,8 @@ public class ActionConfirmationQuery extends QueryBase else if (item.match(ActionConfirmation._status)) return ActionConfirmationEntity._status; else if (item.match(ActionConfirmationEntity._token)) return ActionConfirmationEntity._token; else if (item.match(ActionConfirmation._expiresAt)) return ActionConfirmationEntity._expiresAt; - else if (item.prefix(ActionConfirmation._emailConfirmation)) return ActionConfirmationEntity._data; + else if (item.prefix(ActionConfirmation._mergeAccountConfirmation)) return ActionConfirmationEntity._data; + else if (item.prefix(ActionConfirmation._removeCredentialRequest)) return ActionConfirmationEntity._data; else if (item.prefix(ActionConfirmation._dmpInvitation)) return ActionConfirmationEntity._data; else if (item.prefix(ActionConfirmation._createdBy)) return ActionConfirmationEntity._createdById; else if (item.match(ActionConfirmation._createdBy)) return ActionConfirmationEntity._createdById; diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/actionconfirmation/ActionConfirmationServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/actionconfirmation/ActionConfirmationServiceImpl.java index 4119cc442..d87bea565 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/actionconfirmation/ActionConfirmationServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/actionconfirmation/ActionConfirmationServiceImpl.java @@ -7,18 +7,16 @@ import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity; import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity; -import eu.eudat.commons.types.actionconfirmation.RemoveCredentialConfirmationEntity; +import eu.eudat.commons.types.actionconfirmation.RemoveCredentialRequestEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.ActionConfirmationEntity; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.ActionConfirmation; -import eu.eudat.model.Dmp; import eu.eudat.model.ReferenceType; import eu.eudat.model.builder.ActionConfirmationBuilder; -import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.deleter.ActionConfirmationDeleter; import eu.eudat.model.persist.ActionConfirmationPersist; -import eu.eudat.model.persist.RemoveCredentialRequestPersist; +import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist; import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist; import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist; import eu.eudat.service.dmpblueprint.DmpBlueprintServiceImpl; @@ -138,8 +136,8 @@ public class ActionConfirmationServiceImpl implements ActionConfirmationService return data; } - private @NotNull RemoveCredentialConfirmationEntity buildMergeAccountConfirmationEntity(RemoveCredentialRequestPersist persist){ - RemoveCredentialConfirmationEntity data = new RemoveCredentialConfirmationEntity(); + private @NotNull RemoveCredentialRequestEntity buildMergeAccountConfirmationEntity(RemoveCredentialRequestPersist persist){ + RemoveCredentialRequestEntity data = new RemoveCredentialRequestEntity(); if (persist == null) return data; data.setCredentialId(persist.getCredentialId()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserService.java b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserService.java index 09517cc7d..31f24f840 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserService.java @@ -2,7 +2,7 @@ package eu.eudat.service.user; import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.model.User; -import eu.eudat.model.persist.RemoveCredentialRequestPersist; +import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist; import eu.eudat.model.persist.UserMergeRequestPersist; import eu.eudat.model.persist.UserPersist; import eu.eudat.model.persist.UserRolePatchPersist; 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 2bd5dec5f..ad6763d3e 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 @@ -13,7 +13,7 @@ import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.notification.NotificationContactType; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity; -import eu.eudat.commons.types.actionconfirmation.RemoveCredentialConfirmationEntity; +import eu.eudat.commons.types.actionconfirmation.RemoveCredentialRequestEntity; import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.user.AdditionalInfoEntity; import eu.eudat.commons.validation.ValidatorFactory; @@ -35,6 +35,7 @@ import eu.eudat.model.deleter.UserRoleDeleter; import eu.eudat.model.deleter.UserSettingsSettingsDeleter; import eu.eudat.model.persist.*; import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist; +import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist; import eu.eudat.query.*; import eu.eudat.service.actionconfirmation.ActionConfirmationService; import eu.eudat.service.elastic.ElasticService; @@ -586,11 +587,11 @@ public class UserServiceImpl implements UserService { this.checkActionState(action); - RemoveCredentialConfirmationEntity removeCredentialConfirmationEntity = this.xmlHandlingService.fromXmlSafe(RemoveCredentialConfirmationEntity.class, action.getData()); - if (removeCredentialConfirmationEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{removeCredentialConfirmationEntity, RemoveCredentialConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); + RemoveCredentialRequestEntity removeCredentialRequestEntity = this.xmlHandlingService.fromXmlSafe(RemoveCredentialRequestEntity.class, action.getData()); + if (removeCredentialRequestEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{removeCredentialRequestEntity, RemoveCredentialRequestEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); - UserCredentialEntity userCredentialEntity = this.queryFactory.query(UserCredentialQuery.class).ids(removeCredentialConfirmationEntity.getCredentialId()).first(); - if (userCredentialEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{removeCredentialConfirmationEntity.getCredentialId(), UserCredential.class.getSimpleName()}, LocaleContextHolder.getLocale())); + UserCredentialEntity userCredentialEntity = this.queryFactory.query(UserCredentialQuery.class).ids(removeCredentialRequestEntity.getCredentialId()).first(); + if (userCredentialEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{removeCredentialRequestEntity.getCredentialId(), UserCredential.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (!this.userScope.getUserIdSafe().equals(userCredentialEntity.getId())) throw new MyForbiddenException("Only requested user can approve"); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/UserController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/UserController.java index fdee9959a..9b4f976e3 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/UserController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/UserController.java @@ -14,7 +14,7 @@ import eu.eudat.model.builder.DmpAssociatedUserBuilder; import eu.eudat.model.builder.UserBuilder; import eu.eudat.model.censorship.DmpAssociatedUserCensor; import eu.eudat.model.censorship.UserCensor; -import eu.eudat.model.persist.RemoveCredentialRequestPersist; +import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist; import eu.eudat.model.persist.UserMergeRequestPersist; import eu.eudat.model.persist.UserPersist; import eu.eudat.model.persist.UserRolePatchPersist; diff --git a/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptorCacheService.java b/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptorCacheService.java index d2cbb225f..b3d80ec2d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptorCacheService.java +++ b/dmp-backend/web/src/main/java/eu/eudat/interceptors/UserInterceptorCacheService.java @@ -23,7 +23,6 @@ public class UserInterceptorCacheService extends CacheService roles; private List emails;