diff --git a/pom.xml b/pom.xml index 6f6b8dc4efdbf12a069a6b502b921994ee8ae8b8..449c642cd9c185ccc1fe97ea090a01f506f66e5e 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ </properties> <scm> - <developerConnection>scm:git:https://ec.europa.eu/cefdigital/code/scm/edelivery/smp.git</developerConnection> + <developerConnection>scm:git:https://ec.europa.eu/digital-building-blocks/code/scm/edelivery/smp.git</developerConnection> <tag>HEAD</tag> </scm> @@ -125,7 +125,7 @@ <repositories> <repository> <id>cefdigital-releases</id> - <url>https://ec.europa.eu/cefdigital/artifact/content/repositories/eDelivery/</url> + <url>https://ec.europa.eu/digital-building-blocks/artifact/content/repositories/eDelivery/</url> <releases> <enabled>true</enabled> </releases> @@ -135,7 +135,7 @@ </repository> <repository> <id>cefdigital-snapshots</id> - <url>https://ec.europa.eu/cefdigital/artifact/content/repositories/eDelivery-snapshots/</url> + <url>https://ec.europa.eu/digital-building-blocks/artifact/content/repositories/eDelivery-snapshots/</url> <releases> <enabled>false</enabled> </releases> @@ -145,18 +145,18 @@ </repository> <repository> <id>cefdigital-thirdparty</id> - <url>https://ec.europa.eu/cefdigital/artifact/content/repositories/eDelivery-third-party/</url> + <url>https://ec.europa.eu/digital-building-blocks/artifact/content/repositories/eDelivery-third-party/</url> </repository> </repositories> <!-- Where to deploy binaries --> <distributionManagement> <repository> <id>cefdigital-releases</id> - <url>https://ec.europa.eu/cefdigital/artifact/content/repositories/eDelivery/</url> + <url>https://ec.europa.eu/digital-building-blocks/artifact/content/repositories/eDelivery/</url> </repository> <snapshotRepository> <id>cefdigital-snapshots</id> - <url>https://ec.europa.eu/cefdigital/artifact/content/repositories/eDelivery-snapshots/</url> + <url>https://ec.europa.eu/digital-building-blocks/artifact/content/repositories/eDelivery-snapshots/</url> </snapshotRepository> </distributionManagement> diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java index e1340a8c25502565e85e92c262dbd007095c4213..add6c9cb4c2f5ca5ea0d44b8463de5d4a07a2219 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ConfigurationDao.java @@ -46,9 +46,9 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { List<PropertyUpdateListener> updateListenerList = new ArrayList<>(); boolean isRefreshProcess = false; - Properties cachedProperties = new Properties(); + final Properties cachedProperties = new Properties(); - Map<String, Object> cachedPropertyValues = new HashMap(); + HashMap cachedPropertyValues = new HashMap(); LocalDateTime lastUpdate = null; @@ -130,7 +130,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { // check and update non encrypted tokens updateCurrentEncryptedValues(); } else { - LOG.info("Skip property update because max(LastUpdate) of properties in database is not changed: {}.", lastUpdateFromDB ); + LOG.info("Skip property update because max(LastUpdate) of properties in database is not changed: [{}].", lastUpdateFromDB); } } @@ -140,7 +140,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { if (lastUpdate == null || lastUpdateFromDB == null || lastUpdateFromDB.isAfter(lastUpdate)) { reloadPropertiesFromDatabase(); } else { - LOG.info("Skip property update because max(LastUpdate) of properties in database is not changed: {}.", lastUpdateFromDB ); + LOG.info("Skip property update because max(LastUpdate) of properties in database is not changed: [{}].", lastUpdateFromDB); } } @@ -150,7 +150,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { DatabaseProperties newProperties = new DatabaseProperties(memEManager); // first update deprecated values updateDeprecatedValues(newProperties); - Map<String, Object> resultProperties = null; + Map<String, Object> resultProperties; try { resultProperties = validateConfiguration(newProperties); } catch (SMPRuntimeException ex) { @@ -172,17 +172,17 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { } // update all listeners - updateListenerList.forEach(propertyUpdateListener -> propertyUpdateListener.propertiesUpdate()); + updateListenerList.forEach(PropertyUpdateListener::propertiesUpdate); } else { LOG.warn("Refreshing of database properties is already in process!"); } } - public void addPropertyUpdateListener(PropertyUpdateListener listener){ + public void addPropertyUpdateListener(PropertyUpdateListener listener) { updateListenerList.add(listener); } - public boolean removePropertyUpdateListener(PropertyUpdateListener listener){ + public boolean removePropertyUpdateListener(PropertyUpdateListener listener) { return updateListenerList.remove(listener); } @@ -231,7 +231,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { File encryptionKey = (File) cachedPropertyValues.get(ENCRYPTION_FILENAME.getProperty()); for (SMPPropertyEnum prop : SMPPropertyEnum.values()) { String value = getProperty(cachedProperties, prop); - if (prop.isEncrypted() && !StringUtils.isBlank(value) && value.startsWith( SecurityUtils.DECRYPTED_TOKEN_PREFIX)) { + if (prop.isEncrypted() && !StringUtils.isBlank(value) && value.startsWith(SecurityUtils.DECRYPTED_TOKEN_PREFIX)) { String valToEncrypt = SecurityUtils.getNonEncryptedValue(value); String encVal = encryptString(prop, valToEncrypt, encryptionKey); setPropertyToDatabase(prop, encVal, prop.getDesc()); @@ -240,28 +240,35 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { } - protected void validateBasicProperties(Properties properties){ + protected void validateBasicProperties(Properties properties) { // retrieve and validate configuration dir and encryption filename // because they are important for 'parsing and validating' other parameters String configurationDir = getProperty(properties, CONFIGURATION_DIR); if (StringUtils.isBlank(configurationDir)) { - throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Empty configuration folder. Property '%s' is mandatory", CONFIGURATION_DIR.getProperty())); + throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Empty configuration folder. Property [%s] is mandatory", CONFIGURATION_DIR.getProperty())); } String encryptionKeyFilename = getProperty(properties, ENCRYPTION_FILENAME); if (StringUtils.isBlank(encryptionKeyFilename)) { - throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Empty configuration folder. Property '%s' is mandatory", CONFIGURATION_DIR.getProperty())); + throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Empty configuration folder. Property [%s] is mandatory", CONFIGURATION_DIR.getProperty())); } File configFolder = new File(configurationDir); - if (!configFolder.exists() || !configFolder.isDirectory()) { - throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Configuration folder does not exists or is not a folder! Value: %s", - configurationDir)); + if (!configFolder.exists()) { + LOG.error("Configuration folder [{}] (absolute path: [{}]) does not exist. Try to create folder", configurationDir, configFolder.getAbsolutePath()); + if (!configFolder.mkdirs()) { + throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Configuration folder does not exists and can not be created! Value: [%s] (Absolute path [%s])", + configurationDir, configFolder.getAbsolutePath())); + } + } + if (!configFolder.isDirectory()) { + throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Configuration folder is not a folder! Value: [%s] (Absolute path [%s])", + configurationDir, configFolder.getAbsolutePath())); } File encryptionKeyFile = new File(configurationDir, encryptionKeyFilename); if (!encryptionKeyFile.exists() || !encryptionKeyFile.isFile()) { - throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Encryption file does not exists or is not a File! Value: %s", + throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Encryption file does not exists or is not a File! Value: [%s]", encryptionKeyFile.getAbsolutePath())); } } @@ -278,7 +285,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { File configFolder = new File(configurationDir); File encryptionKeyFile = new File(configurationDir, encryptionKeyFilename); - Map<String, Object> propertyValues = new HashMap(); + HashMap propertyValues = new HashMap(); // put the first two values propertyValues.put(CONFIGURATION_DIR.getProperty(), configFolder); propertyValues.put(ENCRYPTION_FILENAME.getProperty(), encryptionKeyFile); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java index b57244870c9943edc7dfaa5cdb69d794fa0cb039..70aed2d4b0b608907cf1e827a666478189bdcd4b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java @@ -72,7 +72,7 @@ public class ServiceGroupService { * for all domains else it returns metadata only for particular domain. * If domain is given and participantId is not defined on that domain than NotFoundException if thrown. * - * @param participantId + * @param participantId participant identifier object * @return ServiceGroup for participant id */ public ServiceGroup getServiceGroup(ParticipantIdentifierType participantId) { @@ -90,11 +90,11 @@ public class ServiceGroupService { /** * Method save (or update if exists) serviceGroup for domain and servicegroup owner * - * @param serviceGroup - * @param domain - * @param serviceGroupOwner - * @param authenticatedUser - * @return + * @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 */ @Transactional public boolean saveServiceGroup(ServiceGroup serviceGroup, String domain, String serviceGroupOwner, String authenticatedUser) { @@ -113,12 +113,13 @@ public class ServiceGroupService { // try harder String[] val = splitSerialFromSubject(ownerName); String newOwnerName = DistinguishedNamesCodingUtil.normalizeDN(val[0]) + ':' + val[1]; - LOG.info("Owner not found: {} try with normalized owner: {}.", ownerName, newOwnerName); + LOG.info("Owner not found: [{}] try with normalized owner: [{}].", ownerName, newOwnerName); newOwner = userDao.findUserByIdentifier(newOwnerName); ownerName = newOwnerName; } 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() ); throw ex; diff --git a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationClientCertTest.java b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationClientCertTest.java index 974548b0934baa5a5f59f0e845c772b5579bbcff..ce5cf0afeb74cd03c3ed015c8bfd9dac23047e16 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationClientCertTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/cipa/smp/server/security/SecurityConfigurationClientCertTest.java @@ -15,6 +15,7 @@ package eu.europa.ec.cipa.smp.server.security; import eu.europa.ec.edelivery.smp.config.*; +import eu.europa.ec.edelivery.smp.testutils.X509CertificateTestUtils; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -34,6 +35,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; @@ -156,14 +158,14 @@ public class SecurityConfigurationClientCertTest { @Before - public void setup() { - + public void setup() throws IOException { + X509CertificateTestUtils.reloadKeystores(); mvc = MockMvcBuilders.webAppContextSetup(context) .apply(SecurityMockMvcConfigurers.springSecurity()) .build(); } - @Parameterized.Parameter(0) + @Parameterized.Parameter() public String testName; @Parameterized.Parameter(1) diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerSingleDomainTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerSingleDomainTest.java index f970950a7bbf5e9398261b28b811ab3462dd051b..f868c8f8ce5b5002dba3c3c88e3cfa86f32e7fc0 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerSingleDomainTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/controllers/ServiceGroupControllerSingleDomainTest.java @@ -82,8 +82,7 @@ public class ServiceGroupControllerSingleDomainTest { private static final String HTTP_HEADER_KEY_DOMAIN = "Domain"; private static final String HTTP_HEADER_KEY_SERVICE_GROUP_OWNER = "ServiceGroup-Owner"; - - private static final String OTHER_OWNER_NAME_URL_ENCODED = "CN=utf-8_%C5%BC_SMP,O=EC,C=BE:0000000000000666"; + private static final String OTHER_OWNER_NAME = "CN=EHEALTH_SMP_TEST_BRAZIL,O=European Commission,C=BE:48b681ee8e0dcc08"; private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("smp_admin", "test123"); @@ -224,7 +223,7 @@ public class ServiceGroupControllerSingleDomainTest { mvc.perform(put(URL_PATH) .with(ADMIN_CREDENTIALS) .contentType(APPLICATION_XML_VALUE) - .header(HTTP_HEADER_KEY_SERVICE_GROUP_OWNER, OTHER_OWNER_NAME_URL_ENCODED) + .header(HTTP_HEADER_KEY_SERVICE_GROUP_OWNER, OTHER_OWNER_NAME) .content(SERVICE_GROUP_INPUT_BODY)) .andExpect(status().isCreated()); }