user credential changes

This commit is contained in:
Efstratios Giannopoulos 2024-01-15 18:03:12 +02:00
parent f6b7b6e00d
commit 04381aec20
23 changed files with 357 additions and 54 deletions

View File

@ -9,7 +9,7 @@ import java.util.UUID;
@XmlRootElement(name = "remove-credential-confirmation") @XmlRootElement(name = "remove-credential-confirmation")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class RemoveCredentialConfirmationEntity { public class RemoveCredentialRequestEntity {
@XmlAttribute(name = "credential-id") @XmlAttribute(name = "credential-id")
private UUID credentialId; private UUID credentialId;

View File

@ -0,0 +1,24 @@
package eu.eudat.commons.types.usercredential;
import java.util.List;
public class UserCredentialDataEntity {
private List<String> providers;
private String email;
public List<String> getProviders() {
return providers;
}
public void setProviders(List<String> providers) {
this.providers = providers;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

View File

@ -20,7 +20,11 @@ public class UserCredentialEntity extends TenantScopedBaseEntity {
@Column(name = "\"user\"", columnDefinition = "uuid", nullable = false) @Column(name = "\"user\"", columnDefinition = "uuid", nullable = false)
private UUID userId; 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) @Column(name = "\"external_id\"", length = UserCredentialEntity._externalIdLength, nullable = false)
private String externalId; private String externalId;
@ -63,4 +67,12 @@ public class UserCredentialEntity extends TenantScopedBaseEntity {
public void setCreatedAt(Instant createdAt) { public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt; this.createdAt = createdAt;
} }
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
} }

View File

@ -4,7 +4,10 @@ import eu.eudat.commons.enums.ActionConfirmationStatus;
import eu.eudat.commons.enums.ActionConfirmationType; import eu.eudat.commons.enums.ActionConfirmationType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.model.actionconfirmation.DmpInvitation; 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.time.Instant;
import java.util.UUID; import java.util.UUID;
@ -19,9 +22,13 @@ public class ActionConfirmation {
private ActionConfirmationStatus status; private ActionConfirmationStatus status;
public static final String _status = "status"; public static final String _status = "status";
private MergeAccountConfirmation mergeAccountConfirmation;
private EmailConfirmation emailConfirmation; public static final String _mergeAccountConfirmation = "mergeAccountConfirmation";
public static final String _emailConfirmation = "emailConfirmation";
private RemoveCredentialRequest removeCredentialRequest;
public static final String _removeCredentialRequest = "removeCredentialRequest";
private DmpInvitation dmpInvitation; private DmpInvitation dmpInvitation;
public static final String _dmpInvitation = "dmpInvitation"; public static final String _dmpInvitation = "dmpInvitation";
@ -72,14 +79,6 @@ public class ActionConfirmation {
this.status = status; this.status = status;
} }
public EmailConfirmation getEmailConfirmation() {
return emailConfirmation;
}
public void setEmailConfirmation(EmailConfirmation emailConfirmation) {
this.emailConfirmation = emailConfirmation;
}
public DmpInvitation getDmpInvitation() { public DmpInvitation getDmpInvitation() {
return dmpInvitation; return dmpInvitation;
} }
@ -143,4 +142,20 @@ public class ActionConfirmation {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = 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;
}
} }

View File

@ -1,5 +1,7 @@
package eu.eudat.model; package eu.eudat.model;
import eu.eudat.model.usercredential.UserCredentialData;
import java.time.Instant; import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@ -16,6 +18,8 @@ public class UserCredential {
private Instant createdAt; private Instant createdAt;
public static final String _createdAt = "createdAt"; public static final String _createdAt = "createdAt";
private UserCredentialData data;
public static final String _data = "data";
public UUID getId() { public UUID getId() {
return id; return id;
@ -48,4 +52,12 @@ public class UserCredential {
public void setCreatedAt(Instant createdAt) { public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt; this.createdAt = createdAt;
} }
public UserCredentialData getData() {
return data;
}
public void setData(UserCredentialData data) {
this.data = data;
}
} }

View File

@ -1,7 +1,7 @@
package eu.eudat.model.actionconfirmation; package eu.eudat.model.actionconfirmation;
public class EmailConfirmation { public class MergeAccountConfirmation {
private String email; private String email;
public static final String _email = "email"; public static final String _email = "email";

View File

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

View File

@ -5,13 +5,15 @@ import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.ActionConfirmationType; import eu.eudat.commons.enums.ActionConfirmationType;
import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity; import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity;
import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity; import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity;
import eu.eudat.commons.types.actionconfirmation.RemoveCredentialRequestEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.ActionConfirmationEntity; import eu.eudat.data.ActionConfirmationEntity;
import eu.eudat.model.ActionConfirmation; import eu.eudat.model.ActionConfirmation;
import eu.eudat.model.Tenant; import eu.eudat.model.Tenant;
import eu.eudat.model.User; import eu.eudat.model.User;
import eu.eudat.model.builder.actionconfirmation.DmpInvitationBuilder; 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.TenantQuery;
import eu.eudat.query.UserQuery; import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
@ -56,7 +58,8 @@ public class ActionConfirmationBuilder extends BaseBuilder<ActionConfirmation, A
this.logger.trace(new DataLogEntry("requested fields",fields)); this.logger.trace(new DataLogEntry("requested fields",fields));
if(fields == null || data == null || fields.isEmpty()) return new ArrayList<>(); if(fields == null || data == null || fields.isEmpty()) return new ArrayList<>();
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 dmpInvitationFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._dmpInvitation));
FieldSet userFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._createdBy)); FieldSet userFields = fields.extractPrefixed(this.asPrefix(ActionConfirmation._createdBy));
@ -73,13 +76,22 @@ public class ActionConfirmationBuilder extends BaseBuilder<ActionConfirmation, A
if(fields.hasField(this.asIndexer(ActionConfirmation._status))) m.setStatus(d.getStatus()); if(fields.hasField(this.asIndexer(ActionConfirmation._status))) m.setStatus(d.getStatus());
if(fields.hasField(this.asIndexer(ActionConfirmation._isActive))) m.setIsActive(d.getIsActive()); if(fields.hasField(this.asIndexer(ActionConfirmation._isActive))) m.setIsActive(d.getIsActive());
if(fields.hasField(this.asIndexer(ActionConfirmation._expiresAt))) m.setExpiresAt(d.getExpiresAt()); if(fields.hasField(this.asIndexer(ActionConfirmation._expiresAt))) m.setExpiresAt(d.getExpiresAt());
if (!emailConfirmationFields.isEmpty() && d.getData() != null){ if (!removeCredentialRequestFields.isEmpty() && d.getData() != null){
if (d.getType().equals(ActionConfirmationType.MergeAccount) || d.getType().equals(ActionConfirmationType.RemoveCredential)){ switch (d.getType())
MergeAccountConfirmationEntity emailConfirmation = this.xmlHandlingService.fromXmlSafe(MergeAccountConfirmationEntity.class, d.getData()); {
m.setEmailConfirmation(this.builderFactory.builder(EmailConfirmationBuilder.class).authorize(this.authorize).build(emailConfirmationFields, emailConfirmation)); case MergeAccount -> {
}else{ MergeAccountConfirmationEntity emailConfirmation = this.xmlHandlingService.fromXmlSafe(MergeAccountConfirmationEntity.class, d.getData());
DmpInvitationEntity dmpInvitation = this.xmlHandlingService.fromXmlSafe(DmpInvitationEntity.class, d.getData()); m.setMergeAccountConfirmation(this.builderFactory.builder(MergeAccountConfirmationBuilder.class).authorize(this.authorize).build(mergeAccountConfirmationFields, emailConfirmation));
m.setDmpInvitation(this.builderFactory.builder(DmpInvitationBuilder.class).authorize(this.authorize).build(dmpInvitationFields, dmpInvitation)); }
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());
} }
} }

View File

@ -1,10 +1,16 @@
package eu.eudat.model.builder; package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags; 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.convention.ConventionService;
import eu.eudat.data.UserCredentialEntity; import eu.eudat.data.UserCredentialEntity;
import eu.eudat.model.Description;
import eu.eudat.model.User; import eu.eudat.model.User;
import eu.eudat.model.UserCredential; 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 eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
@ -29,16 +35,18 @@ public class UserCredentialBuilder extends BaseBuilder<UserCredential, UserCrede
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final QueryFactory queryFactory; private final QueryFactory queryFactory;
private final JsonHandlingService jsonHandlingService;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public UserCredentialBuilder( public UserCredentialBuilder(
ConventionService conventionService, ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) { BuilderFactory builderFactory, QueryFactory queryFactory, JsonHandlingService jsonHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCredentialBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCredentialBuilder.class)));
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.jsonHandlingService = jsonHandlingService;
} }
public UserCredentialBuilder authorize(EnumSet<AuthorizationFlags> values) { public UserCredentialBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -55,6 +63,8 @@ public class UserCredentialBuilder extends BaseBuilder<UserCredential, UserCrede
FieldSet userFields = fields.extractPrefixed(this.asPrefix(UserCredential._user)); FieldSet userFields = fields.extractPrefixed(this.asPrefix(UserCredential._user));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data); Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
FieldSet definitionPropertiesFields = fields.extractPrefixed(this.asPrefix(UserCredential._data));
List<UserCredential> models = new ArrayList<>(); List<UserCredential> models = new ArrayList<>();
@ -64,7 +74,10 @@ public class UserCredentialBuilder extends BaseBuilder<UserCredential, UserCrede
if (fields.hasField(this.asIndexer(UserCredential._createdAt))) m.setCreatedAt(d.getCreatedAt()); if (fields.hasField(this.asIndexer(UserCredential._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(UserCredential._externalId))) m.setExternalId(d.getExternalId()); if (fields.hasField(this.asIndexer(UserCredential._externalId))) m.setExternalId(d.getExternalId());
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId())); if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
if (!definitionPropertiesFields.isEmpty() && d.getData() != null){
UserCredentialDataEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(UserCredentialDataEntity.class, d.getData());
m.setData(this.builderFactory.builder(UserCredentialDataBuilder.class).authorize(this.authorize).build(definitionPropertiesFields, propertyDefinition));
}
models.add(m); models.add(m);
} }

View File

@ -3,7 +3,7 @@ package eu.eudat.model.builder.actionconfirmation;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity; import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.actionconfirmation.EmailConfirmation; import eu.eudat.model.actionconfirmation.MergeAccountConfirmation;
import eu.eudat.model.builder.BaseBuilder; import eu.eudat.model.builder.BaseBuilder;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -20,35 +20,33 @@ import java.util.*;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class EmailConfirmationBuilder extends BaseBuilder<EmailConfirmation, MergeAccountConfirmationEntity> { public class MergeAccountConfirmationBuilder extends BaseBuilder<MergeAccountConfirmation, MergeAccountConfirmationEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public EmailConfirmationBuilder( public MergeAccountConfirmationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) { ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(EmailConfirmationBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(MergeAccountConfirmationBuilder.class)));
this.builderFactory = builderFactory;
} }
public EmailConfirmationBuilder authorize(EnumSet<AuthorizationFlags> values) { public MergeAccountConfirmationBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
} }
@Override @Override
public List<EmailConfirmation> build(FieldSet fields, List<MergeAccountConfirmationEntity> data) throws MyApplicationException { public List<MergeAccountConfirmation> build(FieldSet fields, List<MergeAccountConfirmationEntity> 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.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)); this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
List<EmailConfirmation> models = new ArrayList<>(); List<MergeAccountConfirmation> models = new ArrayList<>();
for (MergeAccountConfirmationEntity d : data) { for (MergeAccountConfirmationEntity d : data) {
EmailConfirmation m = new EmailConfirmation(); MergeAccountConfirmation m = new MergeAccountConfirmation();
if (fields.hasField(this.asIndexer(EmailConfirmation._email))) m.setEmail(d.getEmail()); if (fields.hasField(this.asIndexer(MergeAccountConfirmation._email))) m.setEmail(d.getEmail());
models.add(m); models.add(m);
} }

View File

@ -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<RemoveCredentialRequest, RemoveCredentialRequestEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public RemoveCredentialRequestBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(RemoveCredentialRequestBuilder.class)));
}
public RemoveCredentialRequestBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<RemoveCredentialRequest> build(FieldSet fields, List<RemoveCredentialRequestEntity> 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<RemoveCredentialRequest> 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;
}
}

View File

@ -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<UserCredentialData, UserCredentialDataEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public UserCredentialDataBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCredentialDataBuilder.class)));
}
public UserCredentialDataBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<UserCredentialData> build(FieldSet fields, List<UserCredentialDataEntity> 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<UserCredentialData> 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;
}
}

View File

@ -4,6 +4,7 @@ import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.UserCredential; import eu.eudat.model.UserCredential;
import eu.eudat.model.censorship.usercredential.UserCredentialDataCensor;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
@ -41,6 +42,9 @@ public class UserCredentialCensor extends BaseCensor {
FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserCredential._user)); FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserCredential._user));
this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId); this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId);
FieldSet dataFields = fields.extractPrefixed(this.asIndexerPrefix(UserCredential._data));
this.censorFactory.censor(UserCredentialDataCensor.class).censor(dataFields, userId);
} }
} }

View File

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

View File

@ -9,6 +9,7 @@ import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist; import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist;
import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist; import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist;
import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;

View File

@ -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.BaseValidator;
import eu.eudat.commons.validation.specification.Specification; import eu.eudat.commons.validation.specification.Specification;

View File

@ -0,0 +1,26 @@
package eu.eudat.model.usercredential;
import java.util.List;
public class UserCredentialData {
private List<String> providers;
public static final String _providers = "providers";
private String email;
public static final String _email = "email";
public List<String> getProviders() {
return providers;
}
public void setProviders(List<String> providers) {
this.providers = providers;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

View File

@ -239,7 +239,8 @@ public class ActionConfirmationQuery extends QueryBase<ActionConfirmationEntity>
else if (item.match(ActionConfirmation._status)) return ActionConfirmationEntity._status; else if (item.match(ActionConfirmation._status)) return ActionConfirmationEntity._status;
else if (item.match(ActionConfirmationEntity._token)) return ActionConfirmationEntity._token; else if (item.match(ActionConfirmationEntity._token)) return ActionConfirmationEntity._token;
else if (item.match(ActionConfirmation._expiresAt)) return ActionConfirmationEntity._expiresAt; 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._dmpInvitation)) return ActionConfirmationEntity._data;
else if (item.prefix(ActionConfirmation._createdBy)) return ActionConfirmationEntity._createdById; else if (item.prefix(ActionConfirmation._createdBy)) return ActionConfirmationEntity._createdById;
else if (item.match(ActionConfirmation._createdBy)) return ActionConfirmationEntity._createdById; else if (item.match(ActionConfirmation._createdBy)) return ActionConfirmationEntity._createdById;

View File

@ -7,18 +7,16 @@ import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity; import eu.eudat.commons.types.actionconfirmation.DmpInvitationEntity;
import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity; 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.convention.ConventionService;
import eu.eudat.data.ActionConfirmationEntity; import eu.eudat.data.ActionConfirmationEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.ActionConfirmation; import eu.eudat.model.ActionConfirmation;
import eu.eudat.model.Dmp;
import eu.eudat.model.ReferenceType; import eu.eudat.model.ReferenceType;
import eu.eudat.model.builder.ActionConfirmationBuilder; import eu.eudat.model.builder.ActionConfirmationBuilder;
import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.deleter.ActionConfirmationDeleter; import eu.eudat.model.deleter.ActionConfirmationDeleter;
import eu.eudat.model.persist.ActionConfirmationPersist; 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.DmpInvitationPersist;
import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist; import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist;
import eu.eudat.service.dmpblueprint.DmpBlueprintServiceImpl; import eu.eudat.service.dmpblueprint.DmpBlueprintServiceImpl;
@ -138,8 +136,8 @@ public class ActionConfirmationServiceImpl implements ActionConfirmationService
return data; return data;
} }
private @NotNull RemoveCredentialConfirmationEntity buildMergeAccountConfirmationEntity(RemoveCredentialRequestPersist persist){ private @NotNull RemoveCredentialRequestEntity buildMergeAccountConfirmationEntity(RemoveCredentialRequestPersist persist){
RemoveCredentialConfirmationEntity data = new RemoveCredentialConfirmationEntity(); RemoveCredentialRequestEntity data = new RemoveCredentialRequestEntity();
if (persist == null) return data; if (persist == null) return data;
data.setCredentialId(persist.getCredentialId()); data.setCredentialId(persist.getCredentialId());

View File

@ -2,7 +2,7 @@ package eu.eudat.service.user;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.model.User; 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.UserMergeRequestPersist;
import eu.eudat.model.persist.UserPersist; import eu.eudat.model.persist.UserPersist;
import eu.eudat.model.persist.UserRolePatchPersist; import eu.eudat.model.persist.UserRolePatchPersist;

View File

@ -13,7 +13,7 @@ import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.notification.NotificationContactType; import eu.eudat.commons.enums.notification.NotificationContactType;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.actionconfirmation.MergeAccountConfirmationEntity; 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.notification.*;
import eu.eudat.commons.types.user.AdditionalInfoEntity; import eu.eudat.commons.types.user.AdditionalInfoEntity;
import eu.eudat.commons.validation.ValidatorFactory; 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.deleter.UserSettingsSettingsDeleter;
import eu.eudat.model.persist.*; import eu.eudat.model.persist.*;
import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist; import eu.eudat.model.persist.actionconfirmation.MergeAccountConfirmationPersist;
import eu.eudat.model.persist.actionconfirmation.RemoveCredentialRequestPersist;
import eu.eudat.query.*; import eu.eudat.query.*;
import eu.eudat.service.actionconfirmation.ActionConfirmationService; import eu.eudat.service.actionconfirmation.ActionConfirmationService;
import eu.eudat.service.elastic.ElasticService; import eu.eudat.service.elastic.ElasticService;
@ -586,11 +587,11 @@ public class UserServiceImpl implements UserService {
this.checkActionState(action); this.checkActionState(action);
RemoveCredentialConfirmationEntity removeCredentialConfirmationEntity = this.xmlHandlingService.fromXmlSafe(RemoveCredentialConfirmationEntity.class, action.getData()); RemoveCredentialRequestEntity removeCredentialRequestEntity = this.xmlHandlingService.fromXmlSafe(RemoveCredentialRequestEntity.class, action.getData());
if (removeCredentialConfirmationEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{removeCredentialConfirmationEntity, RemoveCredentialConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); 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(); UserCredentialEntity userCredentialEntity = this.queryFactory.query(UserCredentialQuery.class).ids(removeCredentialRequestEntity.getCredentialId()).first();
if (userCredentialEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{removeCredentialConfirmationEntity.getCredentialId(), UserCredential.class.getSimpleName()}, LocaleContextHolder.getLocale())); 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"); if (!this.userScope.getUserIdSafe().equals(userCredentialEntity.getId())) throw new MyForbiddenException("Only requested user can approve");

View File

@ -14,7 +14,7 @@ import eu.eudat.model.builder.DmpAssociatedUserBuilder;
import eu.eudat.model.builder.UserBuilder; import eu.eudat.model.builder.UserBuilder;
import eu.eudat.model.censorship.DmpAssociatedUserCensor; import eu.eudat.model.censorship.DmpAssociatedUserCensor;
import eu.eudat.model.censorship.UserCensor; 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.UserMergeRequestPersist;
import eu.eudat.model.persist.UserPersist; import eu.eudat.model.persist.UserPersist;
import eu.eudat.model.persist.UserRolePatchPersist; import eu.eudat.model.persist.UserRolePatchPersist;

View File

@ -23,7 +23,6 @@ public class UserInterceptorCacheService extends CacheService<UserInterceptorCac
this.userId = userId; this.userId = userId;
} }
private String subjectId;
public String getSubjectId() { public String getSubjectId() {
return subjectId; return subjectId;
@ -33,6 +32,7 @@ public class UserInterceptorCacheService extends CacheService<UserInterceptorCac
this.subjectId = subjectId; this.subjectId = subjectId;
} }
private String subjectId;
private UUID userId; private UUID userId;
private List<String> roles; private List<String> roles;
private List<String> emails; private List<String> emails;