Add expirimental logic for userMerge (+ some updates for DB)
This commit is contained in:
parent
d4ca651411
commit
e1212383ff
|
@ -0,0 +1,6 @@
|
||||||
|
package eu.eudat.data.dao.criteria;
|
||||||
|
|
||||||
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
|
|
||||||
|
public class EmailConfirmationCriteria extends Criteria<EmailConfirmation>{
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
package eu.eudat.data.dao.criteria;
|
|
||||||
|
|
||||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
|
||||||
|
|
||||||
public class LoginConfirmationEmailCriteria extends Criteria<LoginConfirmationEmail>{
|
|
||||||
}
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package eu.eudat.data.dao.entities;
|
||||||
|
|
||||||
|
import eu.eudat.data.dao.DatabaseAccessLayer;
|
||||||
|
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
|
||||||
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface EmailConfirmationDao extends DatabaseAccessLayer<EmailConfirmation, UUID> {
|
||||||
|
|
||||||
|
QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria);
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package eu.eudat.data.dao.entities;
|
||||||
|
|
||||||
|
import eu.eudat.data.dao.DatabaseAccess;
|
||||||
|
import eu.eudat.data.dao.criteria.EmailConfirmationCriteria;
|
||||||
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||||
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Service("LoginConfirmationEmailDao")
|
||||||
|
public class EmailConfirmationDaoImpl extends DatabaseAccess<EmailConfirmation> implements EmailConfirmationDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public EmailConfirmationDaoImpl(DatabaseService<EmailConfirmation> databaseService) {
|
||||||
|
super(databaseService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryableList<EmailConfirmation> getWithCriteria(EmailConfirmationCriteria criteria) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmailConfirmation createOrUpdate(EmailConfirmation item) {
|
||||||
|
return this.getDatabaseService().createOrUpdate(item, EmailConfirmation.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<EmailConfirmation> createOrUpdateAsync(EmailConfirmation item) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmailConfirmation find(UUID id) {
|
||||||
|
return this.getDatabaseService().getQueryable(EmailConfirmation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EmailConfirmation find(UUID id, String hint) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(EmailConfirmation item) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryableList<EmailConfirmation> asQueryable() {
|
||||||
|
return this.getDatabaseService().getQueryable(EmailConfirmation.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +0,0 @@
|
||||||
package eu.eudat.data.dao.entities;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.DatabaseAccessLayer;
|
|
||||||
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
|
|
||||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
|
||||||
import eu.eudat.queryable.QueryableList;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface LoginConfirmationEmailDao extends DatabaseAccessLayer<LoginConfirmationEmail, UUID> {
|
|
||||||
|
|
||||||
QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria);
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package eu.eudat.data.dao.entities;
|
|
||||||
|
|
||||||
import eu.eudat.data.dao.DatabaseAccess;
|
|
||||||
import eu.eudat.data.dao.criteria.LoginConfirmationEmailCriteria;
|
|
||||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
|
||||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
|
||||||
import eu.eudat.queryable.QueryableList;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Service("LoginConfirmationEmailDao")
|
|
||||||
public class LoginConfirmationEmailDaoImpl extends DatabaseAccess<LoginConfirmationEmail> implements LoginConfirmationEmailDao {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public LoginConfirmationEmailDaoImpl(DatabaseService<LoginConfirmationEmail> databaseService) {
|
|
||||||
super(databaseService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryableList<LoginConfirmationEmail> getWithCriteria(LoginConfirmationEmailCriteria criteria) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LoginConfirmationEmail createOrUpdate(LoginConfirmationEmail item) {
|
|
||||||
return this.getDatabaseService().createOrUpdate(item, LoginConfirmationEmail.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<LoginConfirmationEmail> createOrUpdateAsync(LoginConfirmationEmail item) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LoginConfirmationEmail find(UUID id) {
|
|
||||||
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LoginConfirmationEmail find(UUID id, String hint) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(LoginConfirmationEmail item) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public QueryableList<LoginConfirmationEmail> asQueryable() {
|
|
||||||
return this.getDatabaseService().getQueryable(LoginConfirmationEmail.class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -34,6 +34,8 @@ public class Credential implements DataEntity<Credential, UUID> {
|
||||||
private Integer provider;
|
private Integer provider;
|
||||||
@Column(name = "\"Public\"", nullable = false)
|
@Column(name = "\"Public\"", nullable = false)
|
||||||
private String publicValue;
|
private String publicValue;
|
||||||
|
@Column(name = "\"Email\"", nullable = false)
|
||||||
|
private String email;
|
||||||
@Column(name = "\"Secret\"", nullable = false)
|
@Column(name = "\"Secret\"", nullable = false)
|
||||||
private String secret;
|
private String secret;
|
||||||
|
|
||||||
|
@ -88,6 +90,14 @@ public class Credential implements DataEntity<Credential, UUID> {
|
||||||
this.publicValue = publicValue;
|
this.publicValue = publicValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSecret() {
|
public String getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
@ -139,6 +149,7 @@ public class Credential implements DataEntity<Credential, UUID> {
|
||||||
public void update(Credential entity) {
|
public void update(Credential entity) {
|
||||||
this.status = entity.status;
|
this.status = entity.status;
|
||||||
this.publicValue = entity.getPublicValue();
|
this.publicValue = entity.getPublicValue();
|
||||||
|
this.email = entity.getEmail();
|
||||||
this.secret = entity.getSecret();
|
this.secret = entity.getSecret();
|
||||||
this.lastUpdateTime = new Date();
|
this.lastUpdateTime = new Date();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"LoginConfirmationEmail\"")
|
@Table(name = "\"EmailConfirmation\"")
|
||||||
public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail, UUID> {
|
public class EmailConfirmation implements DataEntity<EmailConfirmation, UUID> {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@ -31,6 +31,9 @@ public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail
|
||||||
@Column(name = "\"userId\"", nullable = false)
|
@Column(name = "\"userId\"", nullable = false)
|
||||||
private UUID userId;
|
private UUID userId;
|
||||||
|
|
||||||
|
@Column(name = "\"data\"", nullable = false)
|
||||||
|
private String data;
|
||||||
|
|
||||||
@Column(name = "\"expiresAt\"", nullable = false)
|
@Column(name = "\"expiresAt\"", nullable = false)
|
||||||
@Convert(converter = DateToUTCConverter.class)
|
@Convert(converter = DateToUTCConverter.class)
|
||||||
private Date expiresAt;
|
private Date expiresAt;
|
||||||
|
@ -77,9 +80,14 @@ public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail
|
||||||
this.expiresAt = expiresAt;
|
this.expiresAt = expiresAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
public void setData(String data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void update(LoginConfirmationEmail entity) {
|
public void update(EmailConfirmation entity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,7 +96,7 @@ public class LoginConfirmationEmail implements DataEntity<LoginConfirmationEmail
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginConfirmationEmail buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
public EmailConfirmation buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package eu.eudat.controllers;
|
||||||
|
|
||||||
|
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||||
|
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
||||||
|
import eu.eudat.logic.managers.EmailConfirmationManager;
|
||||||
|
import eu.eudat.logic.managers.MergeEmailConfirmationManager;
|
||||||
|
import eu.eudat.logic.security.CustomAuthenticationProvider;
|
||||||
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.models.data.userinfo.UserMergeRequestModel;
|
||||||
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
@RequestMapping(value = "api/emailMergeConfirmation")
|
||||||
|
public class EmailMergeConfirmation {
|
||||||
|
|
||||||
|
private MergeEmailConfirmationManager emailConfirmationManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public EmailMergeConfirmation(MergeEmailConfirmationManager emailConfirmationManager) {
|
||||||
|
this.emailConfirmationManager = emailConfirmationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"/{emailToken}"})
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem> emailConfirmation(@PathVariable(value = "emailToken") String token) {
|
||||||
|
try {
|
||||||
|
this.emailConfirmationManager.confirmEmail(token);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
|
} catch
|
||||||
|
(HasConfirmedEmailException | TokenExpiredException ex) {
|
||||||
|
if (ex instanceof TokenExpiredException) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity sendConfirmatioEmail(@RequestBody UserMergeRequestModel requestModel, Principal principal) {
|
||||||
|
try {
|
||||||
|
this.emailConfirmationManager.sendConfirmationEmail(requestModel.getEmail(), principal, requestModel.getUserId());
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (ex instanceof HasConfirmedEmailException) {
|
||||||
|
return ResponseEntity.status(HttpStatus.FOUND).body(new ResponseItem().status(ApiMessageCode.WARN_MESSAGE));
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import eu.eudat.models.data.doi.DOIRequest;
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.models.data.userinfo.UserCredential;
|
||||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||||
import eu.eudat.models.data.userinfo.UserProfile;
|
import eu.eudat.models.data.userinfo.UserProfile;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
import eu.eudat.types.ApiMessageCode;
|
||||||
|
@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -63,6 +65,14 @@ public class Users extends BaseController {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(user).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UserProfile>().payload(user).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"/{id}/emails"}, produces = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem<List<UserCredential>>> getEmails(@PathVariable String id, Principal principal) throws Exception {
|
||||||
|
UUID userId = id.equals("me") ? principal.getId() : UUID.fromString(id);
|
||||||
|
List<UserCredential> user = userManager.getCredentials(userId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<UserCredential>>().payload(user).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/settings"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/settings"}, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import eu.eudat.data.entities.Credential;
|
import eu.eudat.data.entities.Credential;
|
||||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.data.entities.UserToken;
|
import eu.eudat.data.entities.UserToken;
|
||||||
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||||
|
@ -30,7 +30,7 @@ public class EmailConfirmationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
|
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
|
||||||
LoginConfirmationEmail loginConfirmationEmail = apiContext.getOperationsContext()
|
EmailConfirmation loginConfirmationEmail = apiContext.getOperationsContext()
|
||||||
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
||||||
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
|
import eu.eudat.data.entities.Credential;
|
||||||
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
|
import eu.eudat.data.entities.UserDMP;
|
||||||
|
import eu.eudat.data.entities.UserInfo;
|
||||||
|
import eu.eudat.data.entities.UserToken;
|
||||||
|
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
|
||||||
|
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
|
||||||
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
import eu.eudat.queryable.jpa.predicates.OrderByPredicate;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MergeEmailConfirmationManager {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(MergeEmailConfirmationManager.class);
|
||||||
|
private ApiContext apiContext;
|
||||||
|
private DatabaseRepository databaseRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public MergeEmailConfirmationManager(ApiContext apiContext) {
|
||||||
|
this.apiContext = apiContext;
|
||||||
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void confirmEmail(String token) throws TokenExpiredException, HasConfirmedEmailException {
|
||||||
|
EmailConfirmation loginConfirmationEmail = apiContext.getOperationsContext()
|
||||||
|
.getDatabaseRepository().getLoginConfirmationEmailDao().asQueryable()
|
||||||
|
.where((builder, root) -> builder.equal(root.get("token"), UUID.fromString(token))).getSingle();
|
||||||
|
|
||||||
|
if (loginConfirmationEmail.getExpiresAt().compareTo(new Date()) < 0)
|
||||||
|
throw new TokenExpiredException("Token has expired.");
|
||||||
|
|
||||||
|
UserInfo userToBeMerged = databaseRepository.getUserInfoDao().asQueryable()
|
||||||
|
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
||||||
|
|
||||||
|
try {
|
||||||
|
UUID otherUserId = new ObjectMapper().readValue(loginConfirmationEmail.getData(), UUID.class);
|
||||||
|
UserInfo user = databaseRepository.getUserInfoDao().asQueryable()
|
||||||
|
.where((builder, root) -> builder.equal(root.get("id"), loginConfirmationEmail.getUserId())).getSingle();
|
||||||
|
|
||||||
|
// Checks if mail is used by another user. If it is, merges the new the old.
|
||||||
|
mergeNewUserToOld(user, userToBeMerged);
|
||||||
|
expireUserToken(user);
|
||||||
|
loginConfirmationEmail.setIsConfirmed(true);
|
||||||
|
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendConfirmationEmail(String email, Principal principal, UUID userId) throws HasConfirmedEmailException {
|
||||||
|
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||||
|
|
||||||
|
apiContext.getUtilitiesService().getConfirmationEmailService().createConfirmationEmail(
|
||||||
|
databaseRepository.getLoginConfirmationEmailDao(),
|
||||||
|
apiContext.getUtilitiesService().getMailService(),
|
||||||
|
email,
|
||||||
|
userId,
|
||||||
|
principal.getId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeNewUserToOld(UserInfo newUser, UserInfo oldUser) {
|
||||||
|
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), oldUser)).getSingle();
|
||||||
|
credential.setUserInfo(newUser);
|
||||||
|
databaseRepository.getCredentialDao().createOrUpdate(credential);
|
||||||
|
List<UserDMP> userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList();
|
||||||
|
userDmps.forEach(userDmp -> {
|
||||||
|
userDmp.setUser(newUser);
|
||||||
|
databaseRepository.getUserDmpDao().createOrUpdate(userDmp);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expireUserToken(UserInfo user) {
|
||||||
|
UserToken userToken = databaseRepository.getUserTokenDao().asQueryable()
|
||||||
|
.where((builder, root) -> builder.equal(root.get("user"), user))
|
||||||
|
.orderBy((builder, root) -> builder.desc(root.get("issuedAt")))
|
||||||
|
.take(1)
|
||||||
|
.getSingle();
|
||||||
|
userToken.setExpiresAt(new Date());
|
||||||
|
databaseRepository.getUserTokenDao().createOrUpdate(userToken);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
||||||
import eu.eudat.data.dao.entities.UserInfoDao;
|
import eu.eudat.data.dao.entities.UserInfoDao;
|
||||||
|
import eu.eudat.data.entities.Credential;
|
||||||
import eu.eudat.data.entities.DMP;
|
import eu.eudat.data.entities.DMP;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.data.entities.UserRole;
|
import eu.eudat.data.entities.UserRole;
|
||||||
|
@ -26,6 +27,7 @@ import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.login.Credentials;
|
import eu.eudat.models.data.login.Credentials;
|
||||||
import eu.eudat.models.data.principal.PrincipalModel;
|
import eu.eudat.models.data.principal.PrincipalModel;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import eu.eudat.models.data.userinfo.UserCredential;
|
||||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||||
import eu.eudat.models.data.userinfo.UserProfile;
|
import eu.eudat.models.data.userinfo.UserProfile;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
@ -89,6 +91,19 @@ public class UserManager {
|
||||||
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
|
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<UserCredential> getCredentials(UUID userId) {
|
||||||
|
List<UserCredential> results = new ArrayList<>();
|
||||||
|
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
||||||
|
List<Credential> credentials = apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo").get("id"), userId)).toList();
|
||||||
|
credentials.forEach(credential -> {
|
||||||
|
UserCredential userCredential = new UserCredential();
|
||||||
|
userCredential.setEmail(credential.getEmail());
|
||||||
|
userCredential.setProvider(credential.getProvider());
|
||||||
|
results.add(userCredential);
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
public UserProfile getSingle(UUID userId) throws Exception {
|
public UserProfile getSingle(UUID userId) throws Exception {
|
||||||
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
||||||
UserProfile profile = new UserProfile().fromDataModel(user);
|
UserProfile profile = new UserProfile().fromDataModel(user);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public interface DatabaseRepository {
|
||||||
|
|
||||||
DatasetServiceDao getDatasetServiceDao();
|
DatasetServiceDao getDatasetServiceDao();
|
||||||
|
|
||||||
LoginConfirmationEmailDao getLoginConfirmationEmailDao();
|
EmailConfirmationDao getLoginConfirmationEmailDao();
|
||||||
|
|
||||||
ProjectDao getProjectDao();
|
ProjectDao getProjectDao();
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
||||||
private DMPProfileDao dmpProfileDao;
|
private DMPProfileDao dmpProfileDao;
|
||||||
private DatasetExternalDatasetDao datasetExternalDatasetDao;
|
private DatasetExternalDatasetDao datasetExternalDatasetDao;
|
||||||
private DatasetServiceDao datasetServiceDao;
|
private DatasetServiceDao datasetServiceDao;
|
||||||
private LoginConfirmationEmailDao loginConfirmationEmailDao;
|
private EmailConfirmationDao loginConfirmationEmailDao;
|
||||||
private ProjectDao projectDao;
|
private ProjectDao projectDao;
|
||||||
private FunderDao funderDao;
|
private FunderDao funderDao;
|
||||||
private LockDao lockDao;
|
private LockDao lockDao;
|
||||||
|
@ -247,12 +247,12 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginConfirmationEmailDao getLoginConfirmationEmailDao() {
|
public EmailConfirmationDao getLoginConfirmationEmailDao() {
|
||||||
return loginConfirmationEmailDao;
|
return loginConfirmationEmailDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setLoginConfirmationEmailDao(LoginConfirmationEmailDao loginConfirmationEmailDao) {
|
public void setLoginConfirmationEmailDao(EmailConfirmationDao loginConfirmationEmailDao) {
|
||||||
this.loginConfirmationEmailDao = loginConfirmationEmailDao;
|
this.loginConfirmationEmailDao = loginConfirmationEmailDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,7 @@ public abstract class AbstractAuthenticationService implements AuthenticationSer
|
||||||
|
|
||||||
userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
|
userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().createOrUpdate(userInfo);
|
||||||
credential.setPublicValue(userInfo.getName());
|
credential.setPublicValue(userInfo.getName());
|
||||||
|
credential.setEmail(userInfo.getEmail());
|
||||||
credential.setUserInfo(userInfo);
|
credential.setUserInfo(userInfo);
|
||||||
apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().createOrUpdate(credential);
|
apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().createOrUpdate(credential);
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package eu.eudat.logic.services.utilities;
|
package eu.eudat.logic.services.utilities;
|
||||||
|
|
||||||
import eu.eudat.data.dao.entities.LoginConfirmationEmailDao;
|
import eu.eudat.data.dao.entities.EmailConfirmationDao;
|
||||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public interface ConfirmationEmailService {
|
public interface ConfirmationEmailService {
|
||||||
public void createConfirmationEmail(LoginConfirmationEmailDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId);
|
public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId);
|
||||||
|
|
||||||
public CompletableFuture sentConfirmationEmail(LoginConfirmationEmail confirmationEmail, MailService mailService);
|
public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, UUID anotheruserId);
|
||||||
|
|
||||||
|
public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService);
|
||||||
}
|
}
|
|
@ -1,13 +1,16 @@
|
||||||
package eu.eudat.logic.services.utilities;
|
package eu.eudat.logic.services.utilities;
|
||||||
|
|
||||||
import eu.eudat.data.dao.entities.LoginConfirmationEmailDao;
|
import eu.eudat.data.dao.entities.EmailConfirmationDao;
|
||||||
import eu.eudat.data.entities.LoginConfirmationEmail;
|
import eu.eudat.data.entities.EmailConfirmation;
|
||||||
import eu.eudat.models.data.mail.SimpleMail;
|
import eu.eudat.models.data.mail.SimpleMail;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
@ -24,8 +27,8 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createConfirmationEmail(LoginConfirmationEmailDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId) {
|
public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId) {
|
||||||
LoginConfirmationEmail confirmationEmail = new LoginConfirmationEmail();
|
EmailConfirmation confirmationEmail = new EmailConfirmation();
|
||||||
confirmationEmail.setEmail(email);
|
confirmationEmail.setEmail(email);
|
||||||
confirmationEmail.setExpiresAt(Date
|
confirmationEmail.setExpiresAt(Date
|
||||||
.from(new Date()
|
.from(new Date()
|
||||||
|
@ -41,7 +44,7 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture sentConfirmationEmail(LoginConfirmationEmail confirmationEmail, MailService mailService) {
|
public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService) {
|
||||||
return CompletableFuture.runAsync(() -> {
|
return CompletableFuture.runAsync(() -> {
|
||||||
SimpleMail mail = new SimpleMail();
|
SimpleMail mail = new SimpleMail();
|
||||||
mail.setSubject(environment.getProperty("conf_email.subject"));
|
mail.setSubject(environment.getProperty("conf_email.subject"));
|
||||||
|
@ -71,4 +74,28 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
|
||||||
hour = hour / 60;
|
hour = hour / 60;
|
||||||
return (hour + ":" + min + ":" + sec);
|
return (hour + ":" + min + ":" + sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService,
|
||||||
|
String email, UUID userId, UUID anotheruserId) {
|
||||||
|
EmailConfirmation confirmationEmail = new EmailConfirmation();
|
||||||
|
confirmationEmail.setEmail(email);
|
||||||
|
confirmationEmail.setExpiresAt(Date
|
||||||
|
.from(new Date()
|
||||||
|
.toInstant()
|
||||||
|
.plusSeconds(Long.parseLong(this.environment.getProperty("conf_email.expiration_time_seconds")))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
confirmationEmail.setUserId(userId);
|
||||||
|
try {
|
||||||
|
confirmationEmail.setData(new ObjectMapper().writeValueAsString(anotheruserId));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
confirmationEmail.setIsConfirmed(false);
|
||||||
|
confirmationEmail.setToken(UUID.randomUUID());
|
||||||
|
confirmationEmail = loginConfirmationEmailDao.createOrUpdate(confirmationEmail);
|
||||||
|
sentConfirmationEmail(confirmationEmail, mailService);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package eu.eudat.models.data.userinfo;
|
||||||
|
|
||||||
|
public class UserCredential {
|
||||||
|
private String email;
|
||||||
|
private Integer provider;
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
public Integer getProvider() {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
public void setProvider(Integer provider) {
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package eu.eudat.models.data.userinfo;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UserMergeRequestModel {
|
||||||
|
private UUID userId;
|
||||||
|
private String email;
|
||||||
|
public UUID getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
public void setUserId(UUID userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE public."Credential" ADD COLUMN email character varying;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE public."LoginConfirmationEmail" RENAME TO "EmailConfirmation";
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE public."EmailConfirmation" ADD COLUMN data text;
|
Loading…
Reference in New Issue