Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 2fbe27c1 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Merge pull request #153 in EDELIVERY/smp from...

Merge pull request #153 in EDELIVERY/smp from bugfix/EDELIVERY-4442-error-adding-user-2 to development

* commit '69306cdcc0058c36b8716c8f3f9d2b4d1be68da1':
  add Username as certificate ID  for users without username.
parents 3660a0cc fe82a3ce
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ package eu.europa.ec.edelivery.smp.conversion;
import eu.europa.ec.edelivery.smp.data.model.DBUser;
import eu.europa.ec.edelivery.smp.data.ui.CertificateRO;
import eu.europa.ec.edelivery.smp.data.ui.UserRO;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
......@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author Sebastian-Ion TINCU
*/
......@@ -33,6 +34,12 @@ public class DBUserToUserROConverter implements Converter<DBUser, UserRO> {
if (source.getCertificate() != null) {
CertificateRO certificateRO = conversionService.convert(source.getCertificate(), CertificateRO.class);
target.setCertificate(certificateRO);
if(StringUtils.equalsIgnoreCase(source.getCertificate().getCertificateId(), source.getUsername())) {
// clear username if is the same as certificate id.
// username as cert id is set to database to force unique users
// and to fix issue with mysql - where null value is also unique...
target.setUsername(null);
}
}
return target;
}
......
......@@ -3,11 +3,14 @@ package eu.europa.ec.edelivery.smp.conversion;
import eu.europa.ec.edelivery.smp.data.model.DBCertificate;
import eu.europa.ec.edelivery.smp.data.model.DBUser;
import eu.europa.ec.edelivery.smp.data.ui.UserRO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* @author Sebastian-Ion TINCU
*/
......@@ -29,6 +32,13 @@ public class UserROToDBUserConverter implements Converter<UserRO, DBUser> {
if (source.getCertificate() != null) {
DBCertificate certData = conversionService.convert(source.getCertificate(), DBCertificate.class);
target.setCertificate(certData);
if(StringUtils.isBlank(source.getUsername())) {
// set username with certificate id.
// username as cert id is set to database to force unique users
// and to fix issue with mysql - where null value is also unique...
target.setUsername(certData.getCertificateId());
}
}
return target;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment