Code development platform for open source projects from the European Union institutions

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

Add regular expression feature for splitting the party identifiers

parent 73c9eeb7
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ eDelivery SMP 5.0
smp.keystore.type: Keystore type as JKS/PKCS12
document.restriction.allowed.certificate.types: Allowed key algorithms for certificates to be used in service metadata.Empty value means no restrictions, for other values see the java KeyFactory Algorithms as examples: as example RSA|EC|Ed25519|Ed448;
smp.certificate.validation.allowed.certificate.type: Allowed user certificate JCE types. Empty value means no restrictions, for other values see the java KeyFactory Algorithms as examples: as example RSA|EC|Ed25519|Ed448;
identifiersBehaviour.splitPattern: Regular expression with groups scheme and identifier for splitting the URN identifiers to scheme and identifier part!
eDelivery SMP 4.2
- added new properties:
......
......@@ -27,7 +27,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Factory and utility methods for API classes generated from OASIS XSD.
* <p>
* Created by gutowpa on 12/01/2017.
* @author gutowpa
* @since 3.0
*/
public class Identifiers {
private static final Logger LOG = LoggerFactory.getLogger(Identifiers.class);
......
......@@ -13,6 +13,8 @@
package eu.europa.ec.edelivery.smp.conversion;
import eu.europa.ec.edelivery.smp.logging.SMPLogger;
import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory;
import eu.europa.ec.edelivery.smp.services.ConfigurationService;
import org.apache.commons.lang3.StringUtils;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier;
......@@ -20,15 +22,19 @@ import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static eu.europa.ec.smp.api.Identifiers.asParticipantId;
import static eu.europa.ec.smp.api.Identifiers.asString;
import static org.apache.commons.lang3.StringUtils.*;
/**
* Created by gutowpa on 23/02/2017.
*/
@Component
public class CaseSensitivityNormalizer {
private static final SMPLogger LOG = SMPLoggerFactory.getLogger(CaseSensitivityNormalizer.class);
protected static ConfigurationService configurationService;
......@@ -36,13 +42,32 @@ public class CaseSensitivityNormalizer {
this.configurationService = configurationService;
}
public ParticipantIdentifierType normalizeParticipantIdentifier(String scheme, String value) {
public ParticipantIdentifierType normalizeParticipantIdentifier(final String scheme, final String partyId) {
List<String> caseSensitiveParticipantSchemes = configurationService.getCaseSensitiveParticipantScheme();
if (scheme==null || caseSensitiveParticipantSchemes == null || !caseSensitiveParticipantSchemes.stream().anyMatch(scheme::equalsIgnoreCase)) {
scheme = StringUtils.lowerCase(scheme);
value = StringUtils.lowerCase(value);
String pScheme = trim(scheme);
String pPartyId = trim(partyId);
if (isEmpty(pScheme) && !isEmpty(pPartyId)) {
Pattern pattern = configurationService.getParticipantIdentifierSplitRexExp();
Matcher matcher = pattern.matcher(pPartyId);
if (matcher.matches()) {
pScheme = matcher.group("scheme");
pPartyId = matcher.group("identifier");
LOG.debug("Party identifier [{}] match the regular expression to split to scheme [{}]] and identifier [{}]]",
partyId, pScheme, pPartyId);
} else {
LOG.info("Party identifier [{}] does not match urn regular expression [{}]", partyId, pattern.pattern());
}
}
// set to lower case
if (pScheme == null
|| caseSensitiveParticipantSchemes == null
|| !caseSensitiveParticipantSchemes.stream().anyMatch(pScheme::equalsIgnoreCase)) {
pScheme = lowerCase(pScheme);
pPartyId = lowerCase(pPartyId);
}
return new ParticipantIdentifierType(value, scheme);
return new ParticipantIdentifierType(pPartyId, pScheme);
}
public ParticipantIdentifierType normalize(final ParticipantIdentifierType participantIdentifier, boolean schemeMandatory) {
......@@ -54,7 +79,7 @@ public class CaseSensitivityNormalizer {
}
public ParticipantIdentifierType normalize(final ParticipantIdentifierType participantIdentifier) {
return normalize(participantIdentifier, configurationService.getParticipantSchemeMandatory());
return normalize(participantIdentifier, configurationService.getParticipantSchemeMandatory());
}
public DocumentIdentifier normalize(final DocumentIdentifier documentIdentifier) {
......@@ -65,9 +90,9 @@ public class CaseSensitivityNormalizer {
public DocumentIdentifier normalizeDocumentIdentifier(String scheme, String value) {
List<String> caseSensitiveDocumentSchemes = configurationService.getCaseSensitiveDocumentScheme();
if (scheme==null || caseSensitiveDocumentSchemes == null || !caseSensitiveDocumentSchemes.stream().anyMatch(scheme::equalsIgnoreCase)) {
scheme = StringUtils.lowerCase(scheme);
value = StringUtils.lowerCase(value);
if (scheme == null || caseSensitiveDocumentSchemes == null || !caseSensitiveDocumentSchemes.stream().anyMatch(scheme::equalsIgnoreCase)) {
scheme = lowerCase(scheme);
value = lowerCase(value);
}
return new DocumentIdentifier(value, scheme);
}
......
......@@ -43,6 +43,8 @@ public enum SMPPropertyEnum {
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, STRING),
PARTC_SCH_MANDATORY("identifiersBehaviour.scheme.mandatory", "true", "Scheme for participant identifier is mandatory",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, BOOLEAN),
PARTY_IDENTIFIER_PATTERN("identifiersBehaviour.splitPattern", "^(?i)\\s*?(?<scheme>urn:oasis:names:tc:ebcore:partyid-type:(iso6523:[0-9]{4}|unregistered(:[^:]+)?))::?(?<identifier>.+)?\\s*$",
"Regular expression with groups scheme and identifier for splitting the identifiers to scheme and identifier part!", OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, REGEXP),
PARTC_EBCOREPARTYID_CONCATENATE("identifiersBehaviour.ParticipantIdentifierScheme.ebCoreId.concatenate", "false",
"Concatenate ebCore party id in XML responses <ParticipantIdentifier>urn:oasis:names:tc:ebcore:partyid-type:unregistered:test-ebcore-id</ParticipantIdentifier>",
......@@ -53,6 +55,9 @@ public enum SMPPropertyEnum {
CS_DOCUMENTS("identifiersBehaviour.caseSensitive.DocumentIdentifierSchemes", "casesensitive-doc-scheme1|casesensitive-doc-scheme2", "Specifies schemes of document identifiers that must be considered CASE-SENSITIVE.",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, LIST_STRING),
DOCUMENT_RESTRICTION_CERT_TYPES("document.restriction.allowed.certificate.types", "", "Allowed certificate types registered when composing service metadata. Empty value means no restrictions, for other values see the java KeyFactory Algorithms for example RSA|EC|Ed25519|Ed448",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, LIST_STRING),
// SML integration!
SML_ENABLED("bdmsl.integration.enabled", "false", "BDMSL (SML) integration ON/OFF switch",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, BOOLEAN),
......@@ -357,11 +362,10 @@ public enum SMPPropertyEnum {
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, INTEGER),
SMP_ALERT_MAIL_FROM("smp.alert.mail.from", "test@alert-send-mail.eu", "Alert send mail",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, EMAIL),
// deprecated properties
CLIENT_CERT_HEADER_ENABLED_DEPRECATED("authentication.blueCoat.enabled", "false", "Property was replaced by property: smp.automation.authentication.external.tls.clientCert.enabled",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, BOOLEAN),
DOCUMENT_RESTRICTION_CERT_TYPES("document.restriction.allowed.certificate.types", "", "Allowed certificate types registered when composing service metadata. Empty value means no restrictions, for other values see the java KeyFactory Algorithms as examples: as example RSA|EC|Ed25519|Ed448",
OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, LIST_STRING),
;
String property;
......
......@@ -158,6 +158,10 @@ public class ConfigurationService {
return value != null && value;
}
public Pattern getParticipantIdentifierSplitRexExp() {
return configurationDAO.getCachedPropertyValue(PARTY_IDENTIFIER_PATTERN);
}
public boolean isProxyEnabled() {
String proxyHost = configurationDAO.getCachedProperty(HTTP_PROXY_HOST);
return !StringUtils.isBlank(proxyHost);
......
......@@ -276,6 +276,7 @@ public class UITruststoreService {
LOG.debug("No certificate key types configured. Skip certificate key validation.");
return;
}
PublicKey certKey = x509Certificate.getPublicKey();
if (!StringUtils.equalsAnyIgnoreCase(certKey.getAlgorithm(), allowedCertificateKeyTypes.toArray(new String[]{}))) {
throw new CertificateException("Certificate does not have allowed key algorithm type! Key type ["
......
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