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 cdb26049 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Add property identifiersBehaviour.ParticipantIdentifierScheme.ebCoreId.concatenate

parent ef7358cd
No related branches found
No related tags found
No related merge requests found
Showing
with 84 additions and 37 deletions
......@@ -24,7 +24,7 @@ eDelivery SMP 4.2
smp.cluster.enabled: if smp is deployed on cluster. If property is not enabled then all properties are refreshed on SetProperty. Otherwise properties are refreshed by cron task for all nodes at the same time
authentication.blueCoat.enabled - deprecated and replaced with smp.automation.authentication.external.tls.clientCert.enabled
smp.automation.authentication.external.tls.SSLClientCert.enabled Authentication with external module as: reverse proxy. Authenticated certificate is send to application using 'SSLClientCert' HTTP header. Do not enable this feature without properly configured reverse-proxy!
identifiersBehaviour.ParticipantIdentifierScheme.ebCoreId.concatenate: Concatenate ebCore party id in XML responses <ParticipantIdentifier >urn:oasis:names:tc:ebcore:partyid-type:unregistered:test-ebcore-id</ParticipantIdentifier>
- removed deprecated properties
bdmsl.integration.keystore.password
......
......@@ -39,7 +39,7 @@ import java.util.List;
* Created by migueti on 13/02/2017.
*/
public class ExtensionConverter {
private static final SMPLogger LOG = SMPLoggerFactory.getLogger(ServiceGroupConverter.class);
private static final SMPLogger LOG = SMPLoggerFactory.getLogger(ExtensionConverter.class);
// private static final String WRAPPED_FORMAT = "<ExtensionsWrapper xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\">%s</ExtensionsWrapper>";
private static final byte[] WRAPPED_FORMAT_START = "<ExtensionsWrapper xmlns=\"http://docs.oasis-open.org/bdxr/ns/SMP/2016/05\">".getBytes();
private static final byte[] WRAPPED_FORMAT_END = "</ExtensionsWrapper>".getBytes();
......
......@@ -42,6 +42,7 @@ import java.util.ArrayList;
import java.util.List;
import static eu.europa.ec.edelivery.smp.exceptions.ErrorCode.INVALID_EXTENSION_FOR_SG;
import static eu.europa.ec.smp.api.Identifiers.EBCORE_IDENTIFIER_PREFIX;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
......@@ -101,8 +102,8 @@ public class ServiceGroupConverter {
if (serviceGroup!=null && serviceGroup.getParticipantIdentifier()!=null
&& StringUtils.isBlank(serviceGroup.getParticipantIdentifier().getScheme())
&& StringUtils.startsWithAny(serviceGroup.getParticipantIdentifier().getValue(),
Identifiers.EBCORE_IDENTIFIER_PREFIX,
"::"+Identifiers.EBCORE_IDENTIFIER_PREFIX)){
EBCORE_IDENTIFIER_PREFIX,
"::"+ EBCORE_IDENTIFIER_PREFIX)){
// normalize participant identifier
LOG.info("Normalize ebCore identifier: " + serviceGroup.getParticipantIdentifier().getValue());
ParticipantIdentifierType participantIdentifierType = Identifiers.asParticipantId(serviceGroup.getParticipantIdentifier().getValue());
......@@ -122,14 +123,20 @@ public class ServiceGroupConverter {
* @param dsg - database service group entity
* @return Oasis ServiceGroup entity or null if parameter is null
*/
public static ServiceGroup toServiceGroup(DBServiceGroup dsg){
public static ServiceGroup toServiceGroup(DBServiceGroup dsg, boolean concatenateEBCoreID){
if (dsg==null){
return null;
}
ServiceGroup serviceGroup = new ServiceGroup();
ParticipantIdentifierType identifier = new ParticipantIdentifierType(dsg.getParticipantIdentifier(), dsg.getParticipantScheme());
String schema = dsg.getParticipantScheme();
String value = dsg.getParticipantIdentifier();
if (concatenateEBCoreID && StringUtils.startsWithIgnoreCase(schema, EBCORE_IDENTIFIER_PREFIX) ){
value = schema + ":" + value;
schema = null;
}
ParticipantIdentifierType identifier = new ParticipantIdentifierType(value, schema);
serviceGroup.setParticipantIdentifier(identifier);
if (dsg.getExtension()!=null){
try {
......
......@@ -82,7 +82,7 @@ public class ServiceMetadataConverter {
* @param serviceMetadataXml
* @return w3d dom element
*/
public static Document toSignedServiceMetadatadaDocument(byte[] serviceMetadataXml) {
public static Document toSignedServiceMetadataDocument(byte[] serviceMetadataXml) {
try {
Document docServiceMetadata = parse(serviceMetadataXml);
Document root = parse(DOC_SIGNED_SERVICE_METADATA_EMPTY.getBytes());
......
......@@ -26,8 +26,12 @@ public enum SMPPropertyEnum {
PARTC_SCH_REGEXP("identifiersBehaviour.ParticipantIdentifierScheme.validationRegex", "^((?!^.{26})([a-z0-9]+-[a-z0-9]+-[a-z0-9]+)|urn:oasis:names:tc:ebcore:partyid-type:(iso6523|unregistered)(:.+)?$)", "Participant Identifier Schema of each PUT ServiceGroup request is validated against this schema.", false, false, false, REGEXP),
PARTC_SCH_REGEXP_MSG("identifiersBehaviour.ParticipantIdentifierScheme.validationRegexMessage",
"Participant scheme must start with:urn:oasis:names:tc:ebcore:partyid-type:(iso6523:|unregistered:) OR must be up to 25 characters long with form [domain]-[identifierArea]-[identifierType] (ex.: 'busdox-actorid-upis') and may only contain the following characters: [a-z0-9].", "Error message for UI", false, false, false, STRING),
PARTC_EBCOREPARTYID_CONCATENATE("identifiersBehaviour.ParticipantIdentifierScheme.ebCoreId.concatenate",
"true", "Concatenate ebCore party id in XML responses <ParticipantIdentifier >urn:oasis:names:tc:ebcore:partyid-type:unregistered:test-ebcore-id</ParticipantIdentifier>", false, false, false, BOOLEAN),
CS_PARTICIPANTS("identifiersBehaviour.caseSensitive.ParticipantIdentifierSchemes", "sensitive-participant-sc1|sensitive-participant-sc2", "Specifies schemes of participant identifiers that must be considered CASE-SENSITIVE.", false, false, false, LIST_STRING),
CS_DOCUMENTS("identifiersBehaviour.caseSensitive.DocumentIdentifierSchemes", "casesensitive-doc-scheme1|casesensitive-doc-scheme2", "Specifies schemes of document identifiers that must be considered CASE-SENSITIVE.", false, false, false, LIST_STRING),
// SML integration!
SML_ENABLED("bdmsl.integration.enabled", "false", "BDMSL (SML) integration ON/OFF switch", false, false, false, BOOLEAN),
SML_PARTICIPANT_MULTIDOMAIN("bdmsl.participant.multidomain.enabled", "false", "Set to true if SML support participant on multidomain", false, false, true, BOOLEAN),
......
......@@ -46,6 +46,10 @@ public class ConfigurationService {
public String getParticipantIdentifierSchemeRexExpMessage() {
return (String)configurationDAO.getCachedPropertyValue(PARTC_SCH_REGEXP_MSG);
}
public Boolean getForceConcatenateEBCorePartyId() {
return (Boolean)configurationDAO.getCachedPropertyValue(PARTC_EBCOREPARTYID_CONCATENATE);
}
public Pattern getPasswordPolicyRexExp() {
return (Pattern) configurationDAO.getCachedPropertyValue(PASSWORD_POLICY_REGULAR_EXPRESSION);
}
......
......@@ -67,6 +67,9 @@ public class ServiceGroupService {
@Autowired
private SmlConnector smlConnector;
@Autowired
private ConfigurationService configurationService;
/**
* Method returns ServiceGroup entity for participant with references. If domain is null/empty it returns ServiceMetadata
* for all domains else it returns metadata only for particular domain.
......@@ -80,18 +83,18 @@ public class ServiceGroupService {
ParticipantIdentifierType normalizedServiceGroupId = caseSensitivityNormalizer.normalize(participantId);
Optional<DBServiceGroup> sg = serviceGroupDao.findServiceGroup(normalizedServiceGroupId.getValue(),
normalizedServiceGroupId.getScheme());
if (!sg.isPresent()){
if (!sg.isPresent()) {
throw new SMPRuntimeException(SG_NOT_EXISTS, normalizedServiceGroupId.getValue(),
normalizedServiceGroupId.getScheme());
}
return ServiceGroupConverter.toServiceGroup(sg.get());
return ServiceGroupConverter.toServiceGroup(sg.get(), configurationService.getForceConcatenateEBCorePartyId());
}
/**
* Method save (or update if exists) serviceGroup for domain and servicegroup owner
*
* @param serviceGroup service group entity to be stored
* @param domain domain of service group
* @param serviceGroup service group entity to be stored
* @param domain domain of service group
* @param serviceGroupOwner owner of the service group
* @param authenticatedUser authenticated user who is trying to save service group
* @return return true if object was stored
......@@ -101,7 +104,7 @@ public class ServiceGroupService {
// normalize participant identifier
ParticipantIdentifierType normalizedParticipantId = caseSensitivityNormalizer.normalize(serviceGroup.getParticipantIdentifier());
LOG.businessDebug(SMPMessageCode.BUS_SAVE_SERVICE_GROUP,domain,normalizedParticipantId.getValue(), normalizedParticipantId.getScheme() );
LOG.businessDebug(SMPMessageCode.BUS_SAVE_SERVICE_GROUP, domain, normalizedParticipantId.getValue(), normalizedParticipantId.getScheme());
// normalize service group owner
......@@ -121,7 +124,7 @@ public class ServiceGroupService {
if (!newOwner.isPresent()) {
LOG.error("The owner [{}] does not exist! Save service group is rejected!", ownerName);
SMPRuntimeException ex = new SMPRuntimeException(USER_NOT_EXISTS);
LOG.businessError(SMPMessageCode.BUS_SAVE_SERVICE_GROUP_FAILED,domain,normalizedParticipantId.getValue(), normalizedParticipantId.getScheme(), ex.getMessage() );
LOG.businessError(SMPMessageCode.BUS_SAVE_SERVICE_GROUP_FAILED, domain, normalizedParticipantId.getValue(), normalizedParticipantId.getScheme(), ex.getMessage());
throw ex;
}
// get domain
......@@ -141,9 +144,9 @@ public class ServiceGroupService {
validateOwnership(ownerName, sg);
//check is domain exists
Optional<DBServiceGroupDomain> sgd = sg.getServiceGroupForDomain(dmn.getDomainCode());
if (!sgd.isPresent()){
SMPRuntimeException ex = new SMPRuntimeException(SG_NOT_REGISTRED_FOR_DOMAIN,domain,normalizedParticipantId.getValue(), normalizedParticipantId.getScheme());
LOG.businessError(SMPMessageCode.BUS_SAVE_SERVICE_GROUP_FAILED,domain,normalizedParticipantId.getValue(), normalizedParticipantId.getScheme(), ex.getMessage() );
if (!sgd.isPresent()) {
SMPRuntimeException ex = new SMPRuntimeException(SG_NOT_REGISTRED_FOR_DOMAIN, domain, normalizedParticipantId.getValue(), normalizedParticipantId.getScheme());
LOG.businessError(SMPMessageCode.BUS_SAVE_SERVICE_GROUP_FAILED, domain, normalizedParticipantId.getValue(), normalizedParticipantId.getScheme(), ex.getMessage());
throw ex;
}
//update extensions
......@@ -192,51 +195,54 @@ public class ServiceGroupService {
}
public static String[] splitSerialFromSubject(String certificateId) {
public static String[] splitSerialFromSubject(String certificateId) {
int idx = certificateId.lastIndexOf(":");
if (idx <= 0) {
throw new SMPRuntimeException(INVALID_OWNER, certificateId);
throw new SMPRuntimeException(INVALID_OWNER, certificateId);
}
return new String[]{certificateId.substring(0, idx), certificateId.substring(idx+1)};
return new String[]{certificateId.substring(0, idx), certificateId.substring(idx + 1)};
}
/**
* Method validates if user owner with identifier is owner of servicegroup
* @param ownerIdentifier
*
* @param ownerIdentifier
* @param dbsg
*/
protected void validateOwnership(String ownerIdentifier, DBServiceGroup dbsg){
protected void validateOwnership(String ownerIdentifier, DBServiceGroup dbsg) {
Optional<DBUser> own = userDao.findUserByIdentifier(ownerIdentifier);
if (!own.isPresent()){
throw new SMPRuntimeException(USER_NOT_EXISTS);
if (!own.isPresent()) {
throw new SMPRuntimeException(USER_NOT_EXISTS);
}
if (!dbsg.getUsers().contains(own.get())){
throw new SMPRuntimeException(USER_IS_NOT_OWNER,ownerIdentifier,
dbsg.getParticipantIdentifier(), dbsg.getParticipantScheme() );
if (!dbsg.getUsers().contains(own.get())) {
throw new SMPRuntimeException(USER_IS_NOT_OWNER, ownerIdentifier,
dbsg.getParticipantIdentifier(), dbsg.getParticipantScheme());
}
}
/**
* Method validates if user owner with identifier is owner of servicegroup
* @param userId
*
* @param userId
* @param serviceMetadataID
*/
@Transactional
public boolean isServiceGroupOwnerForMetadataID(long userId, long serviceMetadataID ){
public boolean isServiceGroupOwnerForMetadataID(long userId, long serviceMetadataID) {
return serviceGroupDao.findServiceGroupDomainForUserIdAndMetadataId(userId, serviceMetadataID).isPresent();
}
/**
* Method validates if user owner with identifier is owner of servicegroup
* @param ownerIdentifier
*
* @param ownerIdentifier
* @param serviceGroupIdentifier
*/
@Transactional
public boolean isServiceGroupOwner(String ownerIdentifier, String serviceGroupIdentifier ){
public boolean isServiceGroupOwner(String ownerIdentifier, String serviceGroupIdentifier) {
ParticipantIdentifierType pt = caseSensitivityNormalizer.normalizeParticipant(serviceGroupIdentifier);
Optional<DBServiceGroup> osg = serviceGroupDao.findServiceGroup(pt.getValue(), pt.getScheme());
Optional<DBUser> own = userDao.findUserByIdentifier(ownerIdentifier);
......@@ -258,7 +264,7 @@ public class ServiceGroupService {
DBServiceGroup dsg = dbServiceGroup.get();
// register to SML
// unergister all the domains
for (DBServiceGroupDomain sgdom: dsg.getServiceGroupDomains()) {
for (DBServiceGroupDomain sgdom : dsg.getServiceGroupDomains()) {
if (sgdom.isSmlRegistered()) {
smlConnector.unregisterFromDns(normalizedServiceGroupId, sgdom.getDomain());
}
......
......@@ -48,13 +48,39 @@ public class ServiceGroupConverterTest {
DBServiceGroup sg = TestDBUtils.createDBServiceGroup();
//when
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg);
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg, false);
assertNotNull(serviceGroup);
assertEquals(sg.getParticipantIdentifier(), serviceGroup.getParticipantIdentifier().getValue());
assertEquals(sg.getParticipantScheme(), serviceGroup.getParticipantIdentifier().getScheme());
assertEquals(1, serviceGroup.getExtensions().size());
}
@Test
public void toServiceGroupTestEBCorePartyIDNotContact() {
// set
DBServiceGroup sg = TestDBUtils.createDBServiceGroup("0088:123456789","urn:oasis:names:tc:ebcore:partyid-type:iso6523");
//when
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg, false);
assertNotNull(serviceGroup);
assertEquals(sg.getParticipantIdentifier(), serviceGroup.getParticipantIdentifier().getValue());
assertEquals(sg.getParticipantScheme(), serviceGroup.getParticipantIdentifier().getScheme());
assertEquals(1, serviceGroup.getExtensions().size());
}
@Test
public void toServiceGroupTestEBCorePartyIDContact() {
// set
DBServiceGroup sg = TestDBUtils.createDBServiceGroup("0088:123456789","urn:oasis:names:tc:ebcore:partyid-type:iso6523");
//when
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg, true);
assertNotNull(serviceGroup);
assertEquals(sg.getParticipantScheme() +":" + sg.getParticipantIdentifier(), serviceGroup.getParticipantIdentifier().getValue());
assertNull(serviceGroup.getParticipantIdentifier().getScheme());
assertEquals(1, serviceGroup.getExtensions().size());
}
@Test
public void toServiceGroupTestMultiExtensions() throws UnsupportedEncodingException, JAXBException, XMLStreamException {
// set
......@@ -62,7 +88,7 @@ public class ServiceGroupConverterTest {
sg.setExtension(ExtensionConverter.concatByteArrays(TestDBUtils.generateExtension(), TestDBUtils.generateExtension()));
//when-then
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg);
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg, false);
assertNotNull(serviceGroup);
assertEquals(sg.getParticipantIdentifier(), serviceGroup.getParticipantIdentifier().getValue());
assertEquals(sg.getParticipantScheme(), serviceGroup.getParticipantIdentifier().getScheme());
......@@ -73,7 +99,7 @@ public class ServiceGroupConverterTest {
public void toServiceGroupTestIsEmpty() {
// set
//when
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(null);
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(null, false);
assertNull(serviceGroup);
}
......@@ -87,7 +113,7 @@ public class ServiceGroupConverterTest {
expectedExeption.expectMessage(Matchers.startsWith("Invalid extension for service group"));
//when-then
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg);
ServiceGroup serviceGroup = ServiceGroupConverter.toServiceGroup(sg, false);
}
......
......@@ -131,7 +131,7 @@ public class ServiceMetadataConverterTest {
byte[] inputDoc = XmlTestUtils.loadDocumentAsByteArray(RES_PATH + "ServiceMetadataWithServiceInformation.xml");
//when
Document signedServiceMetadataDoc = ServiceMetadataConverter.toSignedServiceMetadatadaDocument(inputDoc);
Document signedServiceMetadataDoc = ServiceMetadataConverter.toSignedServiceMetadataDocument(inputDoc);
//then
Element root = signedServiceMetadataDoc.getDocumentElement();
......@@ -150,7 +150,7 @@ public class ServiceMetadataConverterTest {
expectedExeption.expect(SMPRuntimeException.class);
expectedExeption.expectMessage(Matchers.startsWith("Invalid service metada. Error:"));
//when
ServiceMetadataConverter.toSignedServiceMetadatadaDocument("this is malformed XML body".getBytes());
ServiceMetadataConverter.toSignedServiceMetadataDocument("this is malformed XML body".getBytes());
}
@Test
......
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