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

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

Fix windows build issue

parent 9515a6f9
No related branches found
No related tags found
No related merge requests found
...@@ -46,9 +46,9 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { ...@@ -46,9 +46,9 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> {
List<PropertyUpdateListener> updateListenerList = new ArrayList<>(); List<PropertyUpdateListener> updateListenerList = new ArrayList<>();
boolean isRefreshProcess = false; 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; LocalDateTime lastUpdate = null;
...@@ -130,7 +130,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { ...@@ -130,7 +130,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> {
// check and update non encrypted tokens // check and update non encrypted tokens
updateCurrentEncryptedValues(); updateCurrentEncryptedValues();
} else { } 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> { ...@@ -140,7 +140,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> {
if (lastUpdate == null || lastUpdateFromDB == null || lastUpdateFromDB.isAfter(lastUpdate)) { if (lastUpdate == null || lastUpdateFromDB == null || lastUpdateFromDB.isAfter(lastUpdate)) {
reloadPropertiesFromDatabase(); reloadPropertiesFromDatabase();
} else { } 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> { ...@@ -150,7 +150,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> {
DatabaseProperties newProperties = new DatabaseProperties(memEManager); DatabaseProperties newProperties = new DatabaseProperties(memEManager);
// first update deprecated values // first update deprecated values
updateDeprecatedValues(newProperties); updateDeprecatedValues(newProperties);
Map<String, Object> resultProperties = null; Map<String, Object> resultProperties;
try { try {
resultProperties = validateConfiguration(newProperties); resultProperties = validateConfiguration(newProperties);
} catch (SMPRuntimeException ex) { } catch (SMPRuntimeException ex) {
...@@ -172,17 +172,17 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { ...@@ -172,17 +172,17 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> {
} }
// update all listeners // update all listeners
updateListenerList.forEach(propertyUpdateListener -> propertyUpdateListener.propertiesUpdate()); updateListenerList.forEach(PropertyUpdateListener::propertiesUpdate);
} else { } else {
LOG.warn("Refreshing of database properties is already in process!"); LOG.warn("Refreshing of database properties is already in process!");
} }
} }
public void addPropertyUpdateListener(PropertyUpdateListener listener){ public void addPropertyUpdateListener(PropertyUpdateListener listener) {
updateListenerList.add(listener); updateListenerList.add(listener);
} }
public boolean removePropertyUpdateListener(PropertyUpdateListener listener){ public boolean removePropertyUpdateListener(PropertyUpdateListener listener) {
return updateListenerList.remove(listener); return updateListenerList.remove(listener);
} }
...@@ -231,7 +231,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { ...@@ -231,7 +231,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> {
File encryptionKey = (File) cachedPropertyValues.get(ENCRYPTION_FILENAME.getProperty()); File encryptionKey = (File) cachedPropertyValues.get(ENCRYPTION_FILENAME.getProperty());
for (SMPPropertyEnum prop : SMPPropertyEnum.values()) { for (SMPPropertyEnum prop : SMPPropertyEnum.values()) {
String value = getProperty(cachedProperties, prop); 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 valToEncrypt = SecurityUtils.getNonEncryptedValue(value);
String encVal = encryptString(prop, valToEncrypt, encryptionKey); String encVal = encryptString(prop, valToEncrypt, encryptionKey);
setPropertyToDatabase(prop, encVal, prop.getDesc()); setPropertyToDatabase(prop, encVal, prop.getDesc());
...@@ -240,28 +240,35 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { ...@@ -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 // retrieve and validate configuration dir and encryption filename
// because they are important for 'parsing and validating' other parameters // because they are important for 'parsing and validating' other parameters
String configurationDir = getProperty(properties, CONFIGURATION_DIR); String configurationDir = getProperty(properties, CONFIGURATION_DIR);
if (StringUtils.isBlank(configurationDir)) { 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); String encryptionKeyFilename = getProperty(properties, ENCRYPTION_FILENAME);
if (StringUtils.isBlank(encryptionKeyFilename)) { 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); File configFolder = new File(configurationDir);
if (!configFolder.exists() || !configFolder.isDirectory()) { if (!configFolder.exists()) {
throw new SMPRuntimeException(CONFIGURATION_ERROR, String.format("Configuration folder does not exists or is not a folder! Value: %s", LOG.error("Configuration folder [{}] (absolute path: [{}]) does not exist. Try to create folder", configurationDir, configFolder.getAbsolutePath());
configurationDir)); 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); File encryptionKeyFile = new File(configurationDir, encryptionKeyFilename);
if (!encryptionKeyFile.exists() || !encryptionKeyFile.isFile()) { 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())); encryptionKeyFile.getAbsolutePath()));
} }
} }
...@@ -278,7 +285,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> { ...@@ -278,7 +285,7 @@ public class ConfigurationDao extends BaseDao<DBConfiguration> {
File configFolder = new File(configurationDir); File configFolder = new File(configurationDir);
File encryptionKeyFile = new File(configurationDir, encryptionKeyFilename); File encryptionKeyFile = new File(configurationDir, encryptionKeyFilename);
Map<String, Object> propertyValues = new HashMap(); HashMap propertyValues = new HashMap();
// put the first two values // put the first two values
propertyValues.put(CONFIGURATION_DIR.getProperty(), configFolder); propertyValues.put(CONFIGURATION_DIR.getProperty(), configFolder);
propertyValues.put(ENCRYPTION_FILENAME.getProperty(), encryptionKeyFile); propertyValues.put(ENCRYPTION_FILENAME.getProperty(), encryptionKeyFile);
......
...@@ -72,7 +72,7 @@ public class ServiceGroupService { ...@@ -72,7 +72,7 @@ public class ServiceGroupService {
* for all domains else it returns metadata only for particular domain. * 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. * 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 * @return ServiceGroup for participant id
*/ */
public ServiceGroup getServiceGroup(ParticipantIdentifierType participantId) { public ServiceGroup getServiceGroup(ParticipantIdentifierType participantId) {
...@@ -90,11 +90,11 @@ public class ServiceGroupService { ...@@ -90,11 +90,11 @@ public class ServiceGroupService {
/** /**
* Method save (or update if exists) serviceGroup for domain and servicegroup owner * Method save (or update if exists) serviceGroup for domain and servicegroup owner
* *
* @param serviceGroup * @param serviceGroup service group entity to be stored
* @param domain * @param domain domain of service group
* @param serviceGroupOwner * @param serviceGroupOwner owner of the service group
* @param authenticatedUser * @param authenticatedUser authenticated user who is trying to save service group
* @return * @return return true if object was stored
*/ */
@Transactional @Transactional
public boolean saveServiceGroup(ServiceGroup serviceGroup, String domain, String serviceGroupOwner, String authenticatedUser) { public boolean saveServiceGroup(ServiceGroup serviceGroup, String domain, String serviceGroupOwner, String authenticatedUser) {
...@@ -113,12 +113,13 @@ public class ServiceGroupService { ...@@ -113,12 +113,13 @@ public class ServiceGroupService {
// try harder // try harder
String[] val = splitSerialFromSubject(ownerName); String[] val = splitSerialFromSubject(ownerName);
String newOwnerName = DistinguishedNamesCodingUtil.normalizeDN(val[0]) + ':' + val[1]; 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); newOwner = userDao.findUserByIdentifier(newOwnerName);
ownerName = newOwnerName; ownerName = newOwnerName;
} }
if (!newOwner.isPresent()) { if (!newOwner.isPresent()) {
LOG.error("The owner [{}] does not exist! Save service group is rejected!", ownerName);
SMPRuntimeException ex = new SMPRuntimeException(USER_NOT_EXISTS); SMPRuntimeException ex = new SMPRuntimeException(USER_NOT_EXISTS);
LOG.businessError(SMPMessageCode.BUS_SAVE_SERVICE_GROUP_FAILED,domain,normalizedParticipantId.getValue(), normalizedParticipantId.getScheme(), ex.getMessage() ); LOG.businessError(SMPMessageCode.BUS_SAVE_SERVICE_GROUP_FAILED,domain,normalizedParticipantId.getValue(), normalizedParticipantId.getScheme(), ex.getMessage() );
throw ex; throw ex;
......
...@@ -15,6 +15,7 @@ package eu.europa.ec.cipa.smp.server.security; ...@@ -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.config.*;
import eu.europa.ec.edelivery.smp.testutils.X509CertificateTestUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
...@@ -34,6 +35,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; ...@@ -34,6 +35,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Arrays; import java.util.Arrays;
...@@ -156,14 +158,14 @@ public class SecurityConfigurationClientCertTest { ...@@ -156,14 +158,14 @@ public class SecurityConfigurationClientCertTest {
@Before @Before
public void setup() { public void setup() throws IOException {
X509CertificateTestUtils.reloadKeystores();
mvc = MockMvcBuilders.webAppContextSetup(context) mvc = MockMvcBuilders.webAppContextSetup(context)
.apply(SecurityMockMvcConfigurers.springSecurity()) .apply(SecurityMockMvcConfigurers.springSecurity())
.build(); .build();
} }
@Parameterized.Parameter(0) @Parameterized.Parameter()
public String testName; public String testName;
@Parameterized.Parameter(1) @Parameterized.Parameter(1)
......
...@@ -82,8 +82,7 @@ public class ServiceGroupControllerSingleDomainTest { ...@@ -82,8 +82,7 @@ public class ServiceGroupControllerSingleDomainTest {
private static final String HTTP_HEADER_KEY_DOMAIN = "Domain"; 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 HTTP_HEADER_KEY_SERVICE_GROUP_OWNER = "ServiceGroup-Owner";
private static final String OTHER_OWNER_NAME = "CN=EHEALTH_SMP_TEST_BRAZIL,O=European Commission,C=BE:48b681ee8e0dcc08";
private static final String OTHER_OWNER_NAME_URL_ENCODED = "CN=utf-8_%C5%BC_SMP,O=EC,C=BE:0000000000000666";
private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("smp_admin", "test123"); private static final RequestPostProcessor ADMIN_CREDENTIALS = httpBasic("smp_admin", "test123");
...@@ -224,7 +223,7 @@ public class ServiceGroupControllerSingleDomainTest { ...@@ -224,7 +223,7 @@ public class ServiceGroupControllerSingleDomainTest {
mvc.perform(put(URL_PATH) mvc.perform(put(URL_PATH)
.with(ADMIN_CREDENTIALS) .with(ADMIN_CREDENTIALS)
.contentType(APPLICATION_XML_VALUE) .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)) .content(SERVICE_GROUP_INPUT_BODY))
.andExpect(status().isCreated()); .andExpect(status().isCreated());
} }
......
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