diff --git a/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateAdapter.java b/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateAdapter.java index aabc51278038cfe3f5c98cb9177f120c1e0e6ab8..f9ae375ccdda7db946e4039281d356f58afa0260 100644 --- a/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateAdapter.java +++ b/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateAdapter.java @@ -16,22 +16,19 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. * #END_LICENSE# */ - -/** - * Purpose of the class it to provide OffsetDateTime to string and string to OffsetDateTime conversion - * - * @author Joze Rihtarsic - * @since 2.0 - */ - package eu.europa.ec.smp.spi.utils.xml; - import eu.europa.ec.smp.spi.utils.DatatypeConverter; import javax.xml.bind.annotation.adapters.XmlAdapter; import java.time.OffsetDateTime; +/** + * Purpose of the class it to provide OffsetDateTime to string and string to OffsetDateTime conversion + * + * @author Joze Rihtarsic + * @since 2.0 + */ public class OffsetDateAdapter extends XmlAdapter<String, OffsetDateTime> { diff --git a/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateTimeAdapter.java b/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateTimeAdapter.java index 914d56c4b2bbf3062b2b214295bcd3550fd1b2e5..8a6c2e0e8477afc4bf2958e0c8a87c0eb6660d4b 100644 --- a/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateTimeAdapter.java +++ b/smp-resource-extensions/oasis-cppa3-spi/src/main/java/eu/europa/ec/smp/spi/utils/xml/OffsetDateTimeAdapter.java @@ -16,14 +16,6 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. * #END_LICENSE# */ - -/** - * Purpose of the class it to provide OffsetDateTime to string and string to OffsetDateTime conversion - * - * @author Joze Rihtarsic - * @since 2.0 - */ - package eu.europa.ec.smp.spi.utils.xml; import eu.europa.ec.smp.spi.utils.DatatypeConverter; @@ -31,6 +23,12 @@ import eu.europa.ec.smp.spi.utils.DatatypeConverter; import javax.xml.bind.annotation.adapters.XmlAdapter; import java.time.OffsetDateTime; +/** + * Purpose of the class it to provide OffsetDateTime to string and string to OffsetDateTime conversion + * + * @author Joze Rihtarsic + * @since 2.0 + */ public class OffsetDateTimeAdapter extends XmlAdapter<String, OffsetDateTime> { diff --git a/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/converter/DomUtils.java b/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/converter/DomUtils.java index 2136aa85006f0ea102db8a892059591f364c6233..3418b69cb8477c791d5423437553eaa447434140 100644 --- a/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/converter/DomUtils.java +++ b/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/converter/DomUtils.java @@ -79,10 +79,9 @@ public final class DomUtils { } - public static Document parse(byte[] subresourceXml) throws SAXException, IOException, ParserConfigurationException { + public static Document parse(byte[] subresourceXml) throws SAXException, IOException, ParserConfigurationException, ResourceException { if (subresourceXml == null) { - LOG.warn("ServiceMetadataXml bytearray is null!"); - return null; + throw new ResourceException(INVALID_RESOURCE, "Invalid serviceMetadataXml: null"); } LOG.debug("Parse document with size [{}]", subresourceXml.length); InputStream inputStream = new ByteArrayInputStream(subresourceXml); diff --git a/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10Handler.java b/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10Handler.java index 4fb7b1a066c32f85b35ac8fff72151f6a7c62c55..30cac4f87b768b153ddd9f9cc0c380a26d9147e9 100644 --- a/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10Handler.java +++ b/smp-resource-extensions/oasis-smp-spi/src/main/java/eu/europa/ec/smp/spi/handler/OasisSMPSubresource10Handler.java @@ -39,12 +39,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.util.StreamUtils; import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -131,7 +125,7 @@ public class OasisSMPSubresource10Handler extends AbstractOasisSMPHandler { Document docEnvelopedMetadata; try { byte[] bytearray = readFromInputStream(resourceData.getResourceInputStream()); - docEnvelopedMetadata = toSignedServiceMetadataDocument(bytearray); + docEnvelopedMetadata = DomUtils.toSignedSubresource10Document(bytearray); } catch (IOException e) { throw new ResourceException(PARSE_ERROR, "Can not marshal extension for service group: [" + resourceIdentifier + "]. Error: " + ExceptionUtils.getRootCauseMessage(e), e); @@ -200,28 +194,4 @@ public class OasisSMPSubresource10Handler extends AbstractOasisSMPHandler { serviceMetadataValidator.validate(identifier, documentIdentifier, subresource); } - public static Document toSignedServiceMetadataDocument(byte[] serviceMetadataXml) throws ResourceException { - try { - Document docServiceMetadata = parse(serviceMetadataXml); - Document root = parse(DOC_SIGNED_SERVICE_METADATA_EMPTY.getBytes()); - Node imported = root.importNode(docServiceMetadata.getDocumentElement(), true); - root.getDocumentElement().appendChild(imported); - return root; - } catch (ParserConfigurationException | SAXException | IOException ex) { - throw new ResourceException(INVALID_RESOURCE, "Invalid Signed serviceMetadataXml with error: " + ExceptionUtils.getRootCauseMessage(ex), ex); - } - } - - private static Document parse(byte[] serviceMetadataXml) throws SAXException, IOException, ParserConfigurationException { - InputStream inputStream = new ByteArrayInputStream(serviceMetadataXml); - return getDocumentBuilder().parse(inputStream); - } - - private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - dbf.setFeature(PARSER_DISALLOW_DTD_PARSING_FEATURE, true); - return dbf.newDocumentBuilder(); - } - } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPCertificateAuthentication.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPCertificateAuthentication.java index c4ddac918bf354bbc40e9b8fb116831681ec2e5a..99076281c5a3698c7ef54da47e356ad4302df622 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPCertificateAuthentication.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPCertificateAuthentication.java @@ -16,21 +16,6 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. * #END_LICENSE# */ -/** - * Copyright 2017 - European Commission | CEF eDelivery - * <p> - * Licensed under the EUPL, Version 1.2 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * \BDMSL\bdmsl-parent-pom\LICENSE-EUPL-v1.2.pdf or https://joinup.ec.europa.eu/sites/default/files/custom-page/attachment/eupl_v1.2_en.pdf - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ package eu.europa.ec.edelivery.smp.auth; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverter.java index f63e6c8e96a841ff7dc26d940d3790147b8c7896..143f8b181f9f6470d5b4f8ca2de8987d18066c4c 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/X509CertificateToCertificateROConverter.java @@ -49,6 +49,41 @@ import java.util.TimeZone; */ @Component public class X509CertificateToCertificateROConverter implements Converter<X509Certificate, CertificateRO> { + /** + * Current support for EdEC key is limited and some JCE providers retun OID + * instead of SunJCE key name (which was added in JDK 16+). + * This enum is used to map OID to key type. When JDK 16+ is required, this enum can be removed. + */ + enum KeyType { + ED25519("Ed25519", "1.3.101.112"), + ED448("Ed448", "1.3.101.113"); + + private final String jceKeyType; + private final String keyOid; + + KeyType(String keyType, String oid) { + this.jceKeyType = keyType; + this.keyOid = oid; + } + + public String getJceKeyType() { + return jceKeyType; + } + + public String getKeyOid() { + return keyOid; + } + + public static KeyType getKeyTypeByOid(String oid) { + for (KeyType kt : KeyType.values()) { + if (StringUtils.equals(kt.getKeyOid(), oid)) { + return kt; + } + } + return null; + } + } + private static final SMPLogger LOG = SMPLoggerFactory.getLogger(X509CertificateToCertificateROConverter.class); private static final String S_CLIENT_CERT_DATEFORMAT = "MMM dd HH:mm:ss yyyy"; @@ -134,12 +169,18 @@ public class X509CertificateToCertificateROConverter implements Converter<X509Ce } return ""; } + + /** + * Get key algorithm from key. Some JCE providers return OID instead of SunJCE key name. + * This method tries to map OID to key name. + * + * @param key + * @return JCE key algorithm name + */ public String getKeyAlgorithm(Key key) { - if (StringUtils.equals(key.getAlgorithm(), "1.3.101.112")) { - return "Ed25519"; - } - if (StringUtils.equals(key.getAlgorithm(), "1.3.101.113")) { - return "Ed448"; + KeyType kt = KeyType.getKeyTypeByOid(key.getAlgorithm()); + if (kt != null) { + return kt.getJceKeyType(); } return key.getAlgorithm(); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java index 9b07af0563a6aa2bba12555c2330bb78b762c7db..7104d8114518c86823a007fe33325f59ec196186 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DomainDao.java @@ -30,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.persistence.NoResultException; import javax.persistence.NonUniqueResultException; import javax.persistence.TypedQuery; -import java.util.Arrays; import java.util.List; import java.util.Optional; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDao.java index e6b647fa994607c4df13641adf9bf585e28c06dd..080399c55c8cf10a9947902fb98b4b62e6c816a5 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ExtensionDao.java @@ -64,7 +64,7 @@ public class ExtensionDao extends BaseDao<DBExtension> { * @throws IllegalStateException if no domain is not configured */ public Optional<DBExtension> getExtensionByIdentifier(String identifier) { - LOG.debug("Get extension [[]] all extension", identifier); + LOG.debug("Get extension [{}] all extension", identifier); try { TypedQuery<DBExtension> query = memEManager.createNamedQuery(QUERY_EXTENSION_BY_IDENTIFIER, DBExtension.class); query.setParameter(PARAM_IDENTIFIER, identifier); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBSubresource.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBSubresource.java index dfdec6baf0c0652de85433be3cb3886200855df0..02bc4f196f71e2fd38dad1546db874fbe72d085f 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBSubresource.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/doc/DBSubresource.java @@ -121,7 +121,6 @@ public class DBSubresource extends BaseEntity { } @Transient - public DBResource getResource() { return resource; } @@ -134,10 +133,6 @@ public class DBSubresource extends BaseEntity { return document; } - public byte[] getCurrentContent() { - return getCurrentContent(); - } - public void setDocument(DBDocument document) { this.document = document; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/security/ResourceGuard.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/security/ResourceGuard.java index ee917e48689e7a9e6e0ebfd33c75634187ca13ff..36c2444c4fb377c08c78be042558858105ef7e4e 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/security/ResourceGuard.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/security/ResourceGuard.java @@ -19,7 +19,6 @@ package eu.europa.ec.edelivery.smp.security; import eu.europa.ec.edelivery.smp.auth.SMPUserDetails; -import eu.europa.ec.edelivery.smp.conversion.IdentifierService; import eu.europa.ec.edelivery.smp.data.dao.DomainMemberDao; import eu.europa.ec.edelivery.smp.data.dao.GroupMemberDao; import eu.europa.ec.edelivery.smp.data.dao.ResourceMemberDao; @@ -47,13 +46,11 @@ public class ResourceGuard { DomainMemberDao domainMemberDao; GroupMemberDao groupMemberDao; ResourceMemberDao resourceMemberDao; - IdentifierService identifierService; - public ResourceGuard(DomainMemberDao domainMemberDao, GroupMemberDao groupMemberDao, ResourceMemberDao resourceMemberDao, IdentifierService identifierService) { + public ResourceGuard(DomainMemberDao domainMemberDao, GroupMemberDao groupMemberDao, ResourceMemberDao resourceMemberDao) { this.domainMemberDao = domainMemberDao; this.groupMemberDao = groupMemberDao; this.resourceMemberDao = resourceMemberDao; - this.identifierService = identifierService; } /** diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/CRLVerifierService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/CRLVerifierService.java index dc7517513113107ea75408d95c98d4db721784e9..eb12fc6626ad8800cf3d5ea702e3e466be212825 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/CRLVerifierService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/CRLVerifierService.java @@ -18,25 +18,6 @@ */ package eu.europa.ec.edelivery.smp.services; -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - import eu.europa.ec.edelivery.security.utils.X509CertificateUtils; import eu.europa.ec.edelivery.smp.exceptions.ErrorCode; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java index a3bf40b54c157e124fd353efc99d936056872434..1b8cced6dcaac963a69be3e56cd6d762b858f123 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/SMLIntegrationService.java @@ -29,7 +29,6 @@ import eu.europa.ec.edelivery.smp.logging.SMPLogger; import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory; import eu.europa.ec.edelivery.smp.sml.SmlConnector; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -53,17 +52,17 @@ public class SMLIntegrationService { private static final SMPLogger LOG = SMPLoggerFactory.getLogger(SMLIntegrationService.class); private static final String ERROR_MESSAGE_DNS_NOT_ENABLED = "SML integration is not enabled!"; - @Autowired - private ConfigurationService configurationService; + private final ConfigurationService configurationService; + private final SmlConnector smlConnector; + private final DomainDao domainDao; + private final IdentifierService identifierService; - @Autowired - private SmlConnector smlConnector; - - @Autowired - private DomainDao domainDao; - - @Autowired - private IdentifierService identifierService; + public SMLIntegrationService(ConfigurationService configurationService, SmlConnector smlConnector, DomainDao domainDao, IdentifierService identifierService) { + this.configurationService = configurationService; + this.smlConnector = smlConnector; + this.domainDao = domainDao; + this.identifierService = identifierService; + } /** * Checks whether the participant exists in SML or not. @@ -86,7 +85,7 @@ public class SMLIntegrationService { * Method in transaction update domain status and registers domain to SML. * If registration fails - transaction is rolled back * - * @param domain + * @param domain the domain entity to register */ @Transactional public void registerDomain(DBDomain domain) { @@ -116,7 +115,7 @@ public class SMLIntegrationService { * Method in transaction update domain status and registers domain to SML. * If registration fails - transaction is rolled back * - * @param domain + * @param domain the domain entity to un register from SML */ @Transactional public void unRegisterDomain(DBDomain domain) { @@ -134,8 +133,8 @@ public class SMLIntegrationService { * Method in transaction update resource status and registers it to SML. * If registration fails - transaction is rolled back * - * @param resource - * @param domain + * @param resource the resource entity to register + * @param domain the domain entity to for the resource */ @Transactional(propagation = Propagation.REQUIRES_NEW) @@ -143,8 +142,8 @@ public class SMLIntegrationService { LOG.businessDebug(BUS_SML_REGISTER_SERVICE_GROUP, resource.getIdentifierValue(), resource.getIdentifierScheme(), domain.getDomainCode()); if (!isSMLIntegrationEnabled()) { - String msg = "SML integration is not enabled!"; - LOG.businessWarn(BUS_SML_REGISTER_SERVICE_GROUP_FAILED, resource.getIdentifierValue(), resource.getIdentifierScheme(), domain.getDomainCode(), msg); + LOG.businessWarn(BUS_SML_REGISTER_SERVICE_GROUP_FAILED, resource.getIdentifierValue(), + resource.getIdentifierScheme(), domain.getDomainCode(), ERROR_MESSAGE_DNS_NOT_ENABLED); return; } Identifier normalizedParticipantId = identifierService @@ -177,7 +176,7 @@ public class SMLIntegrationService { if (map != null && map.containsKey(resDefIdentifier)) { return map.get(resDefIdentifier); } - LOG.info("return null because configuration does not have document type and document type [{}]", resource, resDefIdentifier); + LOG.info("return null because configuration does not have document type and document type [{}]", resDefIdentifier); return null; } @@ -187,16 +186,17 @@ public class SMLIntegrationService { * <p> * If registration fails - transaction is rolled back * - * @param resource - * @param domain + * @param resource resourceIdentifier to unregister from SML + * @param domain for which resource belongs to */ @Transactional(propagation = Propagation.REQUIRES_NEW) public void unregisterParticipant(DBResource resource, DBDomain domain) { LOG.businessDebug(BUS_SML_UNREGISTER_SERVICE_GROUP, resource.getIdentifierValue(), resource.getIdentifierScheme(), domain.getDomainCode()); if (!isSMLIntegrationEnabled()) { - String msg = "SML integration is not enabled!"; - LOG.businessWarn(BUS_SML_UNREGISTER_SERVICE_GROUP_FAILED, resource.getIdentifierValue(), resource.getIdentifierScheme(), domain.getDomainCode(), msg); + + LOG.businessWarn(BUS_SML_UNREGISTER_SERVICE_GROUP_FAILED, resource.getIdentifierValue(), resource.getIdentifierScheme(), + domain.getDomainCode(), ERROR_MESSAGE_DNS_NOT_ENABLED); return; } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/mail/MailTemplateService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/mail/MailTemplateService.java index 475af35c33786627e3fed8471635bfdc82e5007a..b823e573f0c3bae745b6dda4ce21e7ebff11095e 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/mail/MailTemplateService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/mail/MailTemplateService.java @@ -18,8 +18,11 @@ */ package eu.europa.ec.edelivery.smp.services.mail; +import eu.europa.ec.edelivery.smp.exceptions.ErrorCode; +import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import eu.europa.ec.edelivery.smp.utils.StringNamedSubstitutor; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; @@ -57,9 +60,8 @@ public class MailTemplateService { modelData.put(MAIL_CONTENT, getMailBody(model)); return StringNamedSubstitutor.resolve(templateIS, modelData); } catch (IOException e) { - e.printStackTrace(); + throw new SMPRuntimeException(ErrorCode.INTERNAL_ERROR, "Error reading mail template", ExceptionUtils.getRootCauseMessage(e)); } - return null; } public String getMailHeader(MailDataModel model) { @@ -78,12 +80,15 @@ public class MailTemplateService { return getMailData(model, "mail." + model.getMailType().getTemplate() + ".content"); } + public String getMailData(MailDataModel model, String key) { Properties translations = getMessageTranslations(model.getLanguage()); String dataTemplate = translations.getProperty(key); return StringUtils.isBlank(dataTemplate) ? dataTemplate : StringNamedSubstitutor.resolve(dataTemplate, model.getModel()); } + + @Cacheable("mail-templates-translations") public Properties getMessageTranslations(String language) { Properties translations = loadTranslations(language); @@ -93,8 +98,7 @@ public class MailTemplateService { return loadTranslations(DEFAULT_LANGUAGE); } - @Cacheable("mail-templates-translations") - public Properties loadTranslations(String language) { + protected Properties loadTranslations(String language) { String langResource = "/mail-messages/mail-messages_" + language + ".properties"; InputStream isLanguage = MailTemplateService.class.getResourceAsStream(langResource); if (isLanguage != null) { @@ -103,9 +107,9 @@ public class MailTemplateService { translations.load(isLanguage); return translations; } catch (IOException e) { - throw new RuntimeException(e); + throw new SMPRuntimeException(ErrorCode.INTERNAL_ERROR, "Error reading mail template", ExceptionUtils.getRootCauseMessage(e)); } } - return null; + return new Properties(); } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyService.java index c9bf4fa3fc6138e5290165cd9a5959dcd2a61dfa..e6f0881fdfda26617c9cd507291576067f0f1a98 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIPropertyService.java @@ -125,7 +125,7 @@ public class UIPropertyService { property.setNewValue(changedProps.get(propertyType.getProperty()).getValue()); property.setUpdateDate(refreshPropertiesTrigger.getNextExecutionDate()); } else { - LOG.debug("Property [{}] has newer update time, but it has the same value as the current value!"); + LOG.debug("Property [{}] has newer update time, but it has the same value as the current value!", propertyType); } } return property; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreService.java index 88625ad60d25dccbec62a77f3e399fda6e838597..1d5e5bcf84a7ef9babaf391d03cc84aaebca8ad2 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UITruststoreService.java @@ -71,11 +71,6 @@ public class UITruststoreService extends BasicKeystoreService { private static final SMPLogger LOG = SMPLoggerFactory.getLogger(UITruststoreService.class); - - private static final ThreadLocal<DateFormat> dateFormatLocal = ThreadLocal.withInitial(() -> - new SimpleDateFormat("MMM d hh:mm:ss yyyy zzz", US) - ); - // dependent beans private final ConfigurationService configurationService; private final ConversionService conversionService; @@ -367,50 +362,6 @@ public class UITruststoreService extends BasicKeystoreService { } } - /** - * The legacy certificate validation. The validation is done only certificate metadata - * - * @param cert - * @throws CertificateException - * - public void checkFullCertificateValidityLegacy(CertificateRO cert) throws CertificateException { - // trust data in database - if (cert.getValidFrom() != null && OffsetDateTime.now().isBefore(cert.getValidFrom())) { - throw new CertificateNotYetValidException("Certificate: " + cert.getCertificateId() + " is valid from: " - + dateFormatLocal.get().format(cert.getValidFrom()) + "."); - - } - if (cert.getValidTo() != null && OffsetDateTime.now().isAfter(cert.getValidTo())) { - throw new CertificateExpiredException("Certificate: " + cert.getCertificateId() + " was valid to: " - + dateFormatLocal.get().format(cert.getValidTo()) + "."); - } - // if trusted list is not empty and exists issuer or subject then validate - if (!normalizedTrustedList.isEmpty() && ( - !StringUtils.isBlank(cert.getIssuer()) || !StringUtils.isBlank(cert.getSubject()))) { - - if (!isSubjectOnTrustedList(cert.getIssuer()) && !isSubjectOnTrustedList(cert.getSubject())) { - throw new CertificateNotTrustedException(CERT_ERROR_MSG_NOT_TRUSTED); - } - } - - // Check crl list - String url = cert.getCrlUrl(); - if (!StringUtils.isBlank(url) && !StringUtils.isBlank(cert.getSerialNumber())) { - try { - crlVerifierService.verifyCertificateCRLs(cert.getSerialNumber(), url); - } catch (CertificateRevokedException ex) { - String msg = "Certificate: '" + cert.getCertificateId() + "'" + - " is revoked!"; - LOG.securityWarn(SEC_USER_CERT_INVALID, cert.getCertificateId(), msg, ex); - throw new CertificateException(msg); - } catch (Throwable th) { - String msg = "Error occurred while validating CRL for certificate!"; - LOG.error(SMPLogger.SECURITY_MARKER, msg + "Err: " + ExceptionUtils.getRootCauseMessage(th), th); - throw new CertificateException(msg); - } - } - } -*/ boolean isTruststoreChanged() { File file = getTruststoreFile(); return !Objects.equals(lastUpdateTrustStoreFile, file) || diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIUserService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIUserService.java index fb3d3b72e1972d9ac9b5743c460d167768bc227c..2e35bc7461d14a67f3f564ed4cbb482fe2fb947c 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIUserService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ui/UIUserService.java @@ -67,6 +67,7 @@ import java.util.stream.Collectors; public class UIUserService extends UIServiceBase<DBUser, UserRO> { private static final SMPLogger LOG = SMPLoggerFactory.getLogger(UIUserService.class); + private static final String USER_ID_REQUEST_TYPE = "UserId"; private final UserDao userDao; CredentialDao credentialDao; @@ -107,8 +108,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { @Transactional @Override public ServiceResult<UserRO> getTableList(int page, int pageSize, String sortField, String sortOrder, Object filter) { - ServiceResult<UserRO> resUsers = super.getTableList(page, pageSize, sortField, sortOrder, filter); - return resUsers; + return super.getTableList(page, pageSize, sortField, sortOrder, filter); } public AccessTokenRO createAccessTokenForUser(Long userId, CredentialRO credInit) { @@ -116,11 +116,10 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { DBUser dbUser = userDao.find(userId); if (dbUser == null) { LOG.error("Can not update user password because authorized user with id [{}] does not exist!", userId); - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UserId", "Can not find user id!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, USER_ID_REQUEST_TYPE, "Can not find user id!"); } - Boolean testMode = SMPEnvironmentProperties.getInstance().isSMPStartupInDevMode(); - + boolean testMode = SMPEnvironmentProperties.getInstance().isSMPStartupInDevMode(); AccessTokenRO token = generateAccessToken(testMode); OffsetDateTime generatedTime = token.getGeneratedOn(); OffsetDateTime expireOnTime = generatedTime.plusDays(configurationService.getAccessTokenPolicyValidDays()); @@ -160,7 +159,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { DBUser dbUser = userDao.find(userId); if (dbUser == null) { LOG.error("Can not update user password because authorized user with id [{}] does not exist!", userId); - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UserId", "Can not find user id!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, USER_ID_REQUEST_TYPE, "Can not find user id!"); } CertificateRO certificate = credential.getCertificate(); if (certificate == null || StringUtils.isBlank(certificate.getCertificateId())) { @@ -211,7 +210,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { } Optional<DBCredential> dbCredential = credentialDao.findUsernamePasswordCredentialForUserIdAndUI(authorizedUserId); DBCredential dbAuthorizedCredentials = dbCredential.orElseThrow(() -> - new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UserId", "Can not find user id")); + new SMPRuntimeException(ErrorCode.INVALID_REQUEST, USER_ID_REQUEST_TYPE, "Can not find user id")); DBUser authorizedUser = dbAuthorizedCredentials.getUser(); @@ -280,7 +279,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { DBUser dbUserToUpdate = userDao.find(userID); if (dbUserToUpdate == null) { LOG.error("Can not update user password because user,[{}] does not exist!", userID); - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UserId", "Can not find user id to update!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, USER_ID_REQUEST_TYPE, "Can not find user id to update!"); } DBCredential credential = new DBCredential(); credential.setUser(dbUserToUpdate); @@ -316,7 +315,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { DBUser dbUser = userDao.find(userId); if (dbUser == null) { LOG.error("Can not update user because user for id [{}] does not exist!", userId); - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UserId", "Can not find user id!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, USER_ID_REQUEST_TYPE, "Can not find user id!"); } LOG.debug("Update user [{}]: email [{}], fullName [{}], smp theme [{}]", user.getUsername(), user.getEmailAddress(), user.getFullName(), user.getSmpTheme()); // update user profile data on managed db entity. (For now Just email, name and theme) @@ -331,7 +330,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { DBUser dbUser = userDao.find(userId); if (dbUser == null) { LOG.error("Can not update user because user for id [{}] does not exist!", userId); - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UserId", "Can not find user id!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, USER_ID_REQUEST_TYPE, "Can not find user id!"); } LOG.debug("Update user [{}]: email [{}], fullName [{}], smp theme [{}]", user.getUsername(), user.getEmailAddress(), user.getFullName(), user.getSmpTheme()); // update user data by admin @@ -377,7 +376,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { DBUser dbUser = userDao.find(userId); if (dbUser == null) { LOG.error("Can not delete user because user for id [{}] does not exist!", userId); - throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, "UserId", "Can not find user id!"); + throw new SMPRuntimeException(ErrorCode.INVALID_REQUEST, USER_ID_REQUEST_TYPE, "Can not find user id!"); } userDao.remove(dbUser); return conversionService.convert(dbUser, UserRO.class); @@ -398,9 +397,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { @Transactional(readOnly = true) public UserRO getUserById(Long userId) { DBUser user = userDao.findUser(userId).orElseThrow(() -> new SMPRuntimeException(ErrorCode.USER_NOT_EXISTS)); - UserRO result = convertToRo(user); - - return result; + return convertToRo(user); } public List<CredentialRO> getUserCredentials(Long userId, @@ -411,9 +408,8 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { List<DBCredential> credentialROs = credentialDao .findUserCredentialForByUserIdTypeAndTarget(userId, credentialType, credentialTargetType); - List<CredentialRO> credentialROList = credentialROs.stream().map(this::convertAndValidateCertificateCredential) + return credentialROs.stream().map(this::convertAndValidateCertificateCredential) .collect(Collectors.toList()); - return credentialROList; } public CredentialRO convertAndValidateCertificateCredential(DBCredential credential) { @@ -464,7 +460,7 @@ public class UIUserService extends UIServiceBase<DBUser, UserRO> { protected void validateCredentials(DBCredential credential, Long userId, CredentialType credentialType, CredentialTargetType credentialTargetType) { if (credential == null) { - LOG.warn("Can not delete credential for ID [{}], because it does not exists!"); + LOG.warn("Can not delete credential for ID [{}], because it does not exists!", userId); throw new BadRequestException(ErrorBusinessCode.UNAUTHORIZED, "Credential does not exist!"); } // validate data diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java index fbcdd429a374afb02efa1968e2b50199c5d7c852..ca69079daa321924682bc641103c463b963af322 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -52,7 +52,6 @@ import org.busdox.servicemetadata.locator._1.PublisherEndpointType; import org.busdox.servicemetadata.locator._1.ServiceMetadataPublisherServiceForParticipantType; import org.busdox.servicemetadata.locator._1.ServiceMetadataPublisherServiceType; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; @@ -79,24 +78,27 @@ public class SmlConnector implements ApplicationContextAware { private static final String SERVICE_METADATA_CONTEXT = "manageservicemetadata"; private static final String IDENTIFIER_VALUE_CONTEXT = "manageparticipantidentifier"; - private static final String BDMSL_CUSTOM_SERVICES_CONTEXT = "bdmslservice"; - private static final String CLIENT_CERT_HEADER_KEY = "Client-Cert"; - @Autowired - ConfigurationService configurationService; - @Autowired - UIKeystoreService keystoreService; - - @Autowired - UITruststoreService truststoreService; + private final ConfigurationService configurationService; + private final UIKeystoreService keystoreService; + private final UITruststoreService truststoreService; + private final IdentifierService identifierService; + private ApplicationContext ctx; - @Autowired - IdentifierService identifierService; + public SmlConnector(ConfigurationService configurationService, UIKeystoreService keystoreService, UITruststoreService truststoreService, IdentifierService identifierService) { + this.configurationService = configurationService; + this.keystoreService = keystoreService; + this.truststoreService = truststoreService; + this.identifierService = identifierService; + } - private ApplicationContext ctx; + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + ctx = applicationContext; + } public boolean registerInDns(Identifier normalizedParticipantId, DBDomain domain, String customNaptrService) { if (!configurationService.isSMLIntegrationEnabled()) { @@ -116,14 +118,12 @@ public class SmlConnector implements ApplicationContextAware { LOG.info("Set regular DNS record for Participant: [{}] and domain: [{}].", normalizedParticipantId, domain.getDomainCode()); } else { createCustomServiceNaptrDNSRecord(normalizedParticipantId, domain, customNaptrService); - LOG.info("Set custom naptr service [{}] DNS record for Participant: [{}] and domain: [{}].", customNaptrService, normalizedParticipantId, domain.getDomainCode()); + LOG.info("Set custom naptr service [{}] DNS record for Participant: [{}] and domain: [{}].", customNaptrService, normalizedParticipantId, domain.getDomainCode()); } return true; - } catch (BadRequestFault e) { - return processSMLErrorMessage(e, normalizedParticipantId); - } catch (NotFoundFault e) { + } catch (BadRequestFault | NotFoundFault e) { return processSMLErrorMessage(e, normalizedParticipantId); - } catch (Exception e) { + } catch (InternalErrorFault | UnauthorizedFault e) { LOG.error(e.getClass().getName() + e.getMessage(), e); throw new SMPRuntimeException(ErrorCode.SML_INTEGRATION_EXCEPTION, e, ExceptionUtils.getRootCauseMessage(e)); } @@ -134,7 +134,7 @@ public class SmlConnector implements ApplicationContextAware { * disabled, it returns {@code false}. * * @param normalizedParticipantId the participant ID - * @param domain the domain entity + * @param domain the domain entity * @return {@code true} if the participant exists; otherwise, {@code false} (also when SML integration is disabled). */ public boolean participantExists(Identifier normalizedParticipantId, DBDomain domain) { @@ -195,7 +195,7 @@ public class SmlConnector implements ApplicationContextAware { return false; } String exp = String.format(ERR_PARTICIPANT_ALREADY_EXISTS, patId.getValue(), patId.getScheme()); - String exp2 = String.format(ERR_PARTICIPANT_NOT_EXISTS, patId.getValue(), patId.getScheme()); + String exp2 = ERR_PARTICIPANT_NOT_EXISTS; return errorMessage.startsWith(exp) || errorMessage.startsWith(exp2); } @@ -304,9 +304,7 @@ public class SmlConnector implements ApplicationContextAware { getParticipantWSClient(domain).delete(smlRequest); LOG.info("Participant: {} removed domain: {}.", normalizedParticipantString, domain.getDomainCode()); return true; - } catch (BadRequestFault e) { - return processSMLErrorMessage(e, normalizedParticipantId); - } catch (NotFoundFault e) { + } catch (BadRequestFault | NotFoundFault e) { return processSMLErrorMessage(e, normalizedParticipantId); } catch (Exception e) { LOG.error(e.getClass().getName() + e.getMessage(), e); @@ -321,9 +319,7 @@ public class SmlConnector implements ApplicationContextAware { LOG.info("Removing SMP id (Domain) from BDMSL: {} ", domain.getDomainCode()); try { getSMPManagerWSClient(domain).delete(domain.getSmlSmpId()); - } catch (BadRequestFault e) { - processSMLErrorMessage(e, domain); - } catch (NotFoundFault e) { + } catch (BadRequestFault | NotFoundFault e) { processSMLErrorMessage(e, domain); } catch (Exception e) { LOG.error(e.getClass().getName() + e.getMessage(), e); @@ -357,11 +353,6 @@ public class SmlConnector implements ApplicationContextAware { return iManageServiceMetadataWS; } - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - ctx = applicationContext; - } - protected String getSmlClientKeyAliasForDomain(DBDomain domain) { String alias = domain.getSmlClientKeyAlias(); if (!domain.isSmlClientCertAuth() && StringUtils.isBlank(alias)) { @@ -428,7 +419,7 @@ public class SmlConnector implements ApplicationContextAware { public void configureClientAuthentication(HTTPConduit httpConduit, Map<String, Object> requestContext, CertificateRO certificateRO, boolean clientCertAuthentication, boolean useTLS) { LOG.info("Connect to SML (smlClientAuthentication: [{}] use Client-CertHeader: [{}])", certificateRO, clientCertAuthentication); - if (certificateRO==null) { + if (certificateRO == null) { throw new IllegalStateException("SML integration is wrongly configured, at least one authentication option is required: 2-way-SSL or Client-Cert header"); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/PropertyUtils.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/PropertyUtils.java index 05085c9a8b6156d79db3591ffd1023ea63495bc8..2a120237dfec8b8009aec787aed890aff23c9d11 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/PropertyUtils.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/PropertyUtils.java @@ -49,8 +49,9 @@ public class PropertyUtils { private static final String REG_EXP_VALUE_SEPARATOR = "\\|"; private static final String REG_EXP_MAP_SEPARATOR = ":"; - private static final UrlValidator urlValidator = new UrlValidator(new String[]{"http", "https"}, UrlValidator.ALLOW_LOCAL_URLS); - + private PropertyUtils() { + // private constructor + } public static Object parseProperty(SMPPropertyEnum prop, String value, File rootFolder) { if (StringUtils.isBlank(value)) { @@ -91,7 +92,7 @@ public class PropertyUtils { parsePropertyType(type, value, confFolder); return true; } catch (SMPRuntimeException ex) { - LOG.debug("Invalid property value [{}] for type [{}]. Error: ", value, type, ExceptionUtils.getRootCauseMessage(ex)); + LOG.debug("Invalid property value [{}] for type [{}]. Error: [{}]", value, type, ExceptionUtils.getRootCauseMessage(ex)); return false; } } @@ -130,7 +131,7 @@ public class PropertyUtils { return Arrays.asList(value.split(REG_EXP_VALUE_SEPARATOR)); } case MAP_STRING: { - if (!value.contains(value)) { + if (!value.contains(":")) { throw new SMPRuntimeException(ErrorCode.CONFIGURATION_ERROR, "Invalid map: [" + value + "]. Error: Map must have at least one key:value entry!"); } @@ -202,8 +203,8 @@ public class PropertyUtils { /** * Method returns 'masked' value for sensitive property data * - * @param property - * @param value + * @param property - property name + * @param value - property value * @return masked value for sensitive properties. Else it returns value! */ public static String getMaskedData(String property, String value) { diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/StringNamedSubstitutor.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/StringNamedSubstitutor.java index 5bf45e845b14b740e8ba3b9cd0243766fbd555e6..a1e2973feeb08733a310fa62de6fb59d2e8f36ab 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/StringNamedSubstitutor.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/utils/StringNamedSubstitutor.java @@ -36,6 +36,10 @@ public class StringNamedSubstitutor { private static final String START_NAME = "${"; private static final char END_NAME = '}'; + private StringNamedSubstitutor() { + // private constructor + } + /** * Substitute named variables in the string with key value pairs from the map. * The variables are in the form of ${name} and are case-insensitive and can contain only letters, digits, _ and . @@ -53,7 +57,8 @@ public class StringNamedSubstitutor { int read; while ((read = template.read()) != -1) { if (read == START_NAME.charAt(0) && isStartSequence(template)) { - template.skip(START_NAME.length() - 1); + //skip (START_NAME.length() - 1L) which is 1L + template.skip(1L); String name = readName(template, END_NAME); if (name == null) { builder.append(START_NAME); diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java index 3a3fd186035191fc571c45ebe6cc09019e79c85a..8e34fb83547d983012a0de15b61d24d8111818e3 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDAOImplTest.java @@ -16,23 +16,6 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. * #END_LICENSE# */ -/** - * Copyright 2017 - European Commission | CEF eDelivery - * <p> - * Licensed under the EUPL, Version 1.2 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * \BDMSL\bdmsl-parent-pom\LICENSE-EUPL-v1.2.pdf or https://joinup.ec.europa.eu/sites/default/files/custom-page/attachment/eupl_v1.2_en.pdf - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * <p> - * * @author Flávio W. R. Santos - CEF-EDELIVERY-SUPPORT@ec.europa.eu - **/ package eu.europa.ec.edelivery.smp.data.dao; @@ -318,7 +301,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { } @Test - void encryptDefaultError() throws IOException { + void encryptDefaultError() { // given File f = new File("no.key"); String password = "TEST11002password1@!." + System.currentTimeMillis(); @@ -528,7 +511,7 @@ public class ConfigurationDAOImplTest extends AbstractBaseDao { configurationDao.update(dbProp); } - public static File generateRandomPrivateKey() throws IOException { + public static File generateRandomPrivateKey() { File resource = Paths.get("target", UUID.randomUUID() + ".key").toFile(); SecurityUtils.generatePrivateSymmetricKey(resource, true); return resource; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResourceFilterTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResourceFilterTest.java index 773ac44fbe606ee2c4e22d0bd64c59a16da85ed1..052eac415e1ae68af3a5955f072e20ad4d165de9 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResourceFilterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/data/model/doc/DBResourceFilterTest.java @@ -18,7 +18,6 @@ */ package eu.europa.ec.edelivery.smp.data.model.doc; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -27,10 +26,10 @@ import static org.junit.jupiter.api.Assertions.*; * @author Sebastian-Ion TINCU * @since 5.1 */ -public class DBResourceFilterTest { +class DBResourceFilterTest { @Test - public void wrapsFilterValueHavingPercentageCharacters() { + void wrapsFilterValueHavingPercentageCharacters() { // GIVEN DBResourceFilter filter = DBResourceFilter .createBuilder() @@ -41,6 +40,6 @@ public class DBResourceFilterTest { String result = filter.getIdentifierFilter(); // THEN - Assertions.assertEquals("%\\%%", result, "Should have wrapped the escaped '%' character around with two extra '%' characters"); + assertEquals("%\\%%", result, "Should have wrapped the escaped '%' character around with two extra '%' characters"); } -} \ No newline at end of file +} diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/security/ResourceGuardTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/security/ResourceGuardTest.java index 087b848c3beced66568c0cba70dd3b5c07ab0c09..82ac2257fbe82d43e468fdecfcdf923b82ca34f8 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/security/ResourceGuardTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/security/ResourceGuardTest.java @@ -22,7 +22,6 @@ import eu.europa.ec.edelivery.smp.auth.SMPUserDetails; import eu.europa.ec.edelivery.smp.data.dao.AbstractJunit5BaseDao; import eu.europa.ec.edelivery.smp.data.enums.VisibilityType; import eu.europa.ec.edelivery.smp.servlet.ResourceAction; -import eu.europa.ec.edelivery.smp.servlet.ResourceRequest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java index 728ccc4bce9cf727a41ac7e1460a409765697daa..7ed34a2a955081e55af927869b6d06fc03f9c535 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ConfigurationServiceAllGetMethodsTest.java @@ -23,7 +23,6 @@ import eu.europa.ec.edelivery.smp.data.dao.ConfigurationDao; import eu.europa.ec.edelivery.smp.data.ui.enums.AlertLevelEnum; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.reflect.MethodUtils; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java index 57f6e8722d1579eee4c314dae5579cb9d0cda6e6..46974aad6a9314ffb3261bcb07725ff911f91749 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/ui/UIGroupPublicServiceTest.java @@ -39,8 +39,6 @@ import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - class UIGroupPublicServiceTest extends AbstractJunit5BaseDao { diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java index 55094a219f21ea6f134e9983cd793c5ba4b2ad94..cd6593bb9a485de0b7552d09da81b6c7ed6870fa 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorParticipantTest.java @@ -44,8 +44,7 @@ import static eu.europa.ec.edelivery.smp.sml.SmlConnectorTestConstants.*; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; /** @@ -251,7 +250,7 @@ class SmlConnectorParticipantTest extends AbstractServiceIntegrationTest { NotFoundFault ex = new NotFoundFault(ERROR_PI_NO_EXISTS); //when - testInstance.processSMLErrorMessage(ex, PARTICIPANT_ID); + assertDoesNotThrow(() -> testInstance.processSMLErrorMessage(ex, PARTICIPANT_ID)); } @Test diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java index 0ba735ddc75a2b95ecac37b1944b08b29aca991c..31f41d66c4b2e4727d4b77fb26d7c0705f835dcc 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/HttpForwardedHeadersTest.java @@ -18,7 +18,6 @@ */ package eu.europa.ec.edelivery.smp.utils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java index 498026b6ee0a7f1802324cfdba49e1b727e69d6b..c89ad451c4090f826867aaf5599bf03c03d5a305 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/utils/X509CertificateUtilsTest.java @@ -16,21 +16,6 @@ * See the Licence for the specific language governing permissions and limitations under the Licence. * #END_LICENSE# */ -/** - * Copyright 2017 - European Commission | CEF eDelivery - * <p> - * Licensed under the EUPL, Version 1.2 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p> - * \BDMSL\bdmsl-parent-pom\LICENSE-EUPL-v1.2.pdf or https://joinup.ec.europa.eu/sites/default/files/custom-page/attachment/eupl_v1.2_en.pdf - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ package eu.europa.ec.edelivery.smp.utils; @@ -66,7 +51,7 @@ public class X509CertificateUtilsTest { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); } - private static final Object[] crlTestListCases() { + private static Object[] crlTestListCases() { return new Object[][]{ {"smp-crl-test-all.pem", "https://localhost/clr,http://localhost/clr,ldap://localhost/clr"}, {"smp-crl-test-https.pem", "https://localhost/clr"}, @@ -75,7 +60,7 @@ public class X509CertificateUtilsTest { }; } - private static final Object[] crlExtractHTTPSTestListCases() { + private static Object[] crlExtractHTTPSTestListCases() { return new Object[][]{ {"ldap://localhost/clr,https://localhost/clr,http://localhost/clr", "https://localhost/clr"}, {"https://localhost/clr", "https://localhost/clr"}, @@ -85,7 +70,7 @@ public class X509CertificateUtilsTest { }; } - private static final Object[] parseTestCases() { + private static Object[] parseTestCases() { return new Object[][]{ {"certificate-pem-with-header.cer"}, {"PeppolTestSMP-DER-encoded.crt"}, @@ -116,9 +101,7 @@ public class X509CertificateUtilsTest { List<String> lstValues = X509CertificateUtils.getCrlDistributionPoints(certificate); // then assertEquals(lstExpected.size(), lstValues.size()); - lstValues.forEach(crl -> { - lstExpected.contains(crl); - }); + lstValues.forEach(crl -> lstExpected.contains(crl)); } @ParameterizedTest @@ -135,12 +118,11 @@ public class X509CertificateUtilsTest { public static X509Certificate loadCertificate(String filename) throws CertificateException { CertificateFactory fact = CertificateFactory.getInstance("X.509"); - X509Certificate cer = (X509Certificate) - fact.generateCertificate(X509CertificateUtilsTest.class.getResourceAsStream("/certificates/" + filename)); - return cer; + return (X509Certificate) fact.generateCertificate( + X509CertificateUtilsTest.class.getResourceAsStream("/certificates/" + filename)); } - public static byte[] getBytes(String filename) throws CertificateException, IOException { + public static byte[] getBytes(String filename) throws IOException { return IOUtils.toByteArray(X509CertificateUtilsTest.class.getResourceAsStream("/certificates/" + filename)); } } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java index 9c0455d3657461fa03a21a8e66d108aa89b7dd77..608ef8a0a8807a816359aac9580ed44434398211 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/SMPAuthorizationService.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -102,19 +102,19 @@ public class SMPAuthorizationService { public boolean isGroupAdministrator(String groupEncId) { SMPUserDetails userDetails = getAndValidateUserDetails(); - Long groupId = getIdFromEncryptedString(groupEncId, false); + Long groupId = getIdFromEncryptedString(groupEncId, false); return groupMemberDao.isUserGroupMemberWithRole(userDetails.getUser().getId(), Collections.singletonList(groupId), MembershipRoleType.ADMIN); } public boolean isResourceAdministrator(String resourceEncId) { SMPUserDetails userDetails = getAndValidateUserDetails(); - Long resourceId = getIdFromEncryptedString(resourceEncId, false); + Long resourceId = getIdFromEncryptedString(resourceEncId, false); return resourceMemberDao.isUserResourceMemberWithRole(userDetails.getUser().getId(), resourceId, MembershipRoleType.ADMIN); } public boolean isResourceMember(String resourceEncId) { SMPUserDetails userDetails = getAndValidateUserDetails(); - Long resourceId = getIdFromEncryptedString(resourceEncId, false); + Long resourceId = getIdFromEncryptedString(resourceEncId, false); return resourceMemberDao.isUserResourceMember(userDetails.getUser().getId(), resourceId); } @@ -130,6 +130,7 @@ public class SMPAuthorizationService { /** * Returns true if logged user is administrator for any of the domain group + * * @param domainEncId * @return true if logged user is group administrator in domain */ @@ -141,6 +142,7 @@ public class SMPAuthorizationService { /** * Returns true if logged user is administrator for any of the resources on group + * * @param groupEncId * @return true if logged user is resource administrator in the group */ @@ -216,7 +218,7 @@ public class SMPAuthorizationService { public UserRO getUserData(DBUser user) { UserRO userRO = conversionService.convert(user, UserRO.class); - return getUpdatedUserData(userRO); + return userRO == null ? null : getUpdatedUserData(userRO); } /** diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasUserService.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasUserService.java index 9d12b48212761ec76ecf13fd0081124e7998463d..b9324ab00db8f38daf5db52867496a01905952cb 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasUserService.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/auth/cas/SMPCasUserService.java @@ -124,7 +124,7 @@ public class SMPCasUserService implements AuthenticationUserDetailsService<CasAs return dbUser; } - public String getValueFromCasPrincipal(MappingData data, Map<String, Object> attributes, Map<String,String> mapping){ + protected String getValueFromCasPrincipal(MappingData data, Map<String, Object> attributes, Map<String,String> mapping){ String template = mapping.getOrDefault(data.name(), data.getDefaultValue()); return StringNamedSubstitutor.resolve(template, attributes); } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SMPWebAppConfig.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SMPWebAppConfig.java index 4dd672e7fd85c9d0f38d15d69ff3e8a76507d213..583866f42b1cb961181cbb208c609545cef3462f 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SMPWebAppConfig.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/SMPWebAppConfig.java @@ -41,8 +41,6 @@ import java.text.SimpleDateFormat; import java.util.List; import java.util.TimeZone; -import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE; - /** * This is the entry point of the DomiSMP application (beans)configuration/setup. * <p> @@ -94,8 +92,8 @@ import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE; @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = SMPWebAppConfig.class)}) @PropertySource(value = "classpath:/application.properties", ignoreResourceNotFound = true) public class SMPWebAppConfig implements WebMvcConfigurer { - private static final Logger LOG = LoggerFactory.getLogger(SMPWebAppConfig.class); + private static final int HIGHEST_ORDER= Integer. MAX_VALUE; @Override public void addCorsMappings(CorsRegistry registry) { @@ -106,12 +104,12 @@ public class SMPWebAppConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.setOrder(HIGHEST_PRECEDENCE) + registry.setOrder(HIGHEST_ORDER) .addResourceHandler("/index.html", "/favicon.png", "/favicon.ico").addResourceLocations("/html/"); - registry.setOrder(HIGHEST_PRECEDENCE - 2) + registry.setOrder(HIGHEST_ORDER - 2) .addResourceHandler("/ui/rest/").addResourceLocations("/"); // ui rest resources - registry.setOrder(HIGHEST_PRECEDENCE - 3) + registry.setOrder(HIGHEST_ORDER - 3) .addResourceHandler("/ui/**").addResourceLocations("/ui/"); // angular pages } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/properties/SMPIdentifierServicePropertyUpdateListener.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/properties/SMPIdentifierServicePropertyUpdateListener.java index 093c76d6872a04bc9047e1aa7e12467e660cdfff..227923b86c69bd72fd887c0dcce07ad85efa1461 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/properties/SMPIdentifierServicePropertyUpdateListener.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/config/properties/SMPIdentifierServicePropertyUpdateListener.java @@ -33,7 +33,15 @@ import java.util.regex.Pattern; import static eu.europa.ec.edelivery.smp.config.enums.SMPPropertyEnum.*; /** - * Class update mail sender configuration on property update event + * It is used to update identifier configuration if properties are changed. + * It listens for changes in the following properties: + * <ul> + * <li>{@link SMPPropertyEnum#PARTC_SCH_SPLIT_REGEXP}</li> + * <li>{@link SMPPropertyEnum#PARTC_SCH_VALIDATION_REGEXP}</li> + * <li>{@link SMPPropertyEnum#PARTC_SCH_MANDATORY}</li> + * <li>{@link SMPPropertyEnum#CS_PARTICIPANTS}</li> + * <li>{@link SMPPropertyEnum#CS_DOCUMENTS}</li> + * </ul> * * @author Joze Rihtarsic * @since 5.0 diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/RootController.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/RootController.java index 3aca656e3ff600ac69407aece98c145d0e3eb1ae..80552e471044dcf8a92a99d354bf50a71222f997 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/RootController.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/RootController.java @@ -72,10 +72,10 @@ public class RootController { return IOUtils.readBytesFromStream(RootController.class.getResourceAsStream("/html/index.html")); } - if (value != null && value.endsWith("favicon.png")) { + if (value.endsWith("favicon.png")) { httpRes.setContentType(MediaType.IMAGE_PNG_VALUE); return IOUtils.readBytesFromStream(RootController.class.getResourceAsStream("/html/favicon.png")); - } else if (value != null && value.endsWith("favicon.ico")) { + } else if (value.endsWith("favicon.ico")) { httpRes.setContentType("image/x-ico"); return IOUtils.readBytesFromStream(RootController.class.getResourceAsStream("/html/favicon.ico")); } diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandler.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandler.java index 1ac9bb414b2e4dcd649627c597dc6368d36baabd..72f11a8cdab9ebe18bec2d80d7715b778709d5db 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandler.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/SMPSecurityExceptionHandler.java @@ -92,7 +92,7 @@ public class SMPSecurityExceptionHandler extends BasicAuthenticationEntryPoint i .build(); String errorUniqueId = ((ErrorResponse) response.getBody()).getErrorUniqueId(); - String logMsg = format("Error unique ID: %s", errorUniqueId); + String logMsg = errorUniqueId == null ? "Null Error ID" : format("UI Error unique ID: %s", errorUniqueId); LOG.warn("Security error:[{}] with [{}].", errorMsg, logMsg); LOG.debug(logMsg, exception); return response; diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdvice.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdvice.java index 0528b6aa0816ae56a2f14012df3313242c211bb8..651239887adcca1b7d8da86ad0622d01e1424041 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdvice.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdvice.java @@ -43,6 +43,7 @@ import static org.springframework.http.HttpStatus.UNAUTHORIZED; @RestControllerAdvice({"eu.europa.ec.edelivery.smp.controllers"}) public class ServiceErrorControllerAdvice extends AbstractErrorControllerAdvice { + @Override @ExceptionHandler({RuntimeException.class, SMPRuntimeException.class, SMPResponseStatusException.class, AuthenticationException.class,}) public ResponseEntity handleRuntimeException(RuntimeException ex) { return super.handleRuntimeException(ex); @@ -71,7 +72,7 @@ public class ServiceErrorControllerAdvice extends AbstractErrorControllerAdvice .build(); String errorUniqueId = ((ErrorResponse) response.getBody()).getErrorUniqueId(); - String logMsg = format("Error unique ID: %s", errorUniqueId); + String logMsg = errorUniqueId == null ? "Null Error ID" : format("UI Error unique ID: %s", errorUniqueId); LOG.warn(logMsg, exception); return response; diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/UIErrorControllerAdvice.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/UIErrorControllerAdvice.java index b75b90dd6db4321673ad694a1cdb42ebed9debcd..d9e2e692b89f50ff5e956e501e9b372dfc195644 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/UIErrorControllerAdvice.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/UIErrorControllerAdvice.java @@ -8,9 +8,9 @@ * versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: - * + * * [PROJECT_HOME]\license\eupl-1.2\license.txt or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 - * + * * Unless required by applicable law or agreed to in writing, software distributed under the Licence is * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and limitations under the Licence. @@ -62,7 +62,7 @@ public class UIErrorControllerAdvice extends AbstractErrorControllerAdvice { .buildJSon(); String errorUniqueId = ((ErrorResponseRO) response.getBody()).getErrorUniqueId(); - String logMsg = format("UI Error unique ID: %s", errorUniqueId); + String logMsg = errorUniqueId == null ? "Null Error ID" : format("UI Error unique ID: %s", errorUniqueId); LOG.warn(logMsg, exception); return response; }