From 59f923d0556ed8d49c23daab71a89d35d0900084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Lindo?= Date: Thu, 7 Nov 2024 09:19:48 +0000 Subject: [PATCH] wip --- .../common/client/ViewerConstants.java | 2 - .../common/server/ViewerConfiguration.java | 42 ++++++++----------- .../resources/config/dbvtk-viewer.properties | 6 +++ .../resources/config/users-groups.properties | 20 +++++++++ 4 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 src/main/resources/config/users-groups.properties diff --git a/src/main/java/com/databasepreservation/common/client/ViewerConstants.java b/src/main/java/com/databasepreservation/common/client/ViewerConstants.java index 3e82c85f..4be8400b 100644 --- a/src/main/java/com/databasepreservation/common/client/ViewerConstants.java +++ b/src/main/java/com/databasepreservation/common/client/ViewerConstants.java @@ -56,8 +56,6 @@ public class ViewerConstants { public static final String INSTALL_FOLDER_ENVIRONMENT_VARIABLE = "DBVTK_HOME"; public static final String INSTALL_FOLDER_DEFAULT_SUBFOLDER_UNDER_HOME = ".dbvtk"; - public static final String EXTERNAL_USERS_GROUPS_PROPERTIES_FILE = "EXTERNAL_USERS_GROUPS_PROPERTIES_FILE"; - public static final String RUNNING_IN_DOCKER_ENVIRONMENT_VARIABLE = "DBVTK_RUNNING_IN_DOCKER"; // from logback.xml diff --git a/src/main/java/com/databasepreservation/common/server/ViewerConfiguration.java b/src/main/java/com/databasepreservation/common/server/ViewerConfiguration.java index c3cc4510..1fb48797 100644 --- a/src/main/java/com/databasepreservation/common/server/ViewerConfiguration.java +++ b/src/main/java/com/databasepreservation/common/server/ViewerConfiguration.java @@ -135,6 +135,9 @@ public class ViewerConfiguration extends ViewerAbstractConfiguration { public static final String PROPERTY_BLOB_PREFIX_NAME = "ui.blob.prefix.name"; + public static final String RELOAD_DBPTK_VIEWER_PROPERTIES = "ui.reload.viewer.properties"; + public static final String RELOAD_DBPTK_VIEWER_PROPERTIES_PERIOD = "ui.reload.viewer.properties.period"; + private static boolean instantiatedWithoutErrors = true; private static String applicationEnvironment = ViewerConstants.APPLICATION_ENV_SERVER; @@ -158,6 +161,7 @@ public class ViewerConfiguration extends ViewerAbstractConfiguration { private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private static CombinedConfiguration combinedConfiguration = new CombinedConfiguration(); private static List configurationFiles = null; + private static List commonConfigurationFiles = null; private List cachedWhitelistedIPs = null; private List cachedWhiteListedUsername = null; @@ -285,18 +289,12 @@ private ViewerConfiguration() { // load core configurations configurationFiles = new ArrayList<>(); - boolean useExternalPropertiesFile = Boolean.parseBoolean(System.getenv(ViewerConstants.EXTERNAL_USERS_GROUPS_PROPERTIES_FILE)); - - if (useExternalPropertiesFile) { - List commonConfigurationList = new ArrayList<>(); - commonConfigurationList.add("dbvtk-viewer.properties"); - commonConfigurationList.add("users-groups.properties"); - addCommonConfiguration(commonConfigurationList); - LOGGER.debug("Finished loading " + String.join(" , ", commonConfigurationList)); - } else { - addConfiguration("dbvtk-viewer.properties"); - LOGGER.debug("Finished loading dbvtk-viewer.properties"); - } + commonConfigurationFiles = new ArrayList<>(); + + commonConfigurationFiles.add("dbvtk-viewer.properties"); + commonConfigurationFiles.add("users-groups.properties"); + addCommonConfiguration(); + LOGGER.debug("Finished loading " + String.join(" , ", commonConfigurationFiles)); addConfiguration("dbvtk-roles.properties"); LOGGER.debug("Finished loading dbvtk-roles.properties"); @@ -304,14 +302,17 @@ private ViewerConfiguration() { applicationEnvironment = System.getProperty(ViewerConstants.APPLICATION_ENV_KEY, ViewerConstants.APPLICATION_ENV_SERVER); - if (useExternalPropertiesFile) { + boolean reloadViewerConfiguration = getViewerConfigurationAsBoolean(false, RELOAD_DBPTK_VIEWER_PROPERTIES); + + if (reloadViewerConfiguration) { + long reloadPeriod = getViewerConfigurationAsInt(86400000, RELOAD_DBPTK_VIEWER_PROPERTIES_PERIOD); scheduler.scheduleAtFixedRate(() -> { try { reloadCombinedConfiguration(); } catch (ConfigurationException e) { LOGGER.error("Error reloading combined configuration", e); } - }, 0, 1, TimeUnit.MINUTES); + }, 0, reloadPeriod, TimeUnit.MILLISECONDS); } } catch (ConfigurationException e) { @@ -706,11 +707,10 @@ private static void addConfiguration(String configurationFile) throws Configurat configurationFiles.add(configurationFile); } - private static void addCommonConfiguration(List commonConfigurationList) throws ConfigurationException { - for (String configurationFile : commonConfigurationList) { + private static void addCommonConfiguration() throws ConfigurationException { + for (String configurationFile : commonConfigurationFiles) { Configuration configuration = getConfiguration(configurationFile); combinedConfiguration.addConfiguration((PropertiesConfiguration) configuration); - configurationFiles.add(configurationFile); } viewerConfiguration.addConfiguration(combinedConfiguration); } @@ -718,13 +718,7 @@ private static void addCommonConfiguration(List commonConfigurationList) private void reloadCombinedConfiguration() throws ConfigurationException { viewerConfiguration.removeConfiguration(combinedConfiguration); combinedConfiguration.clear(); - CombinedConfiguration newConfiguration = new CombinedConfiguration(); - for (String configurationFile : configurationFiles) { - Configuration configuration = getConfiguration(configurationFile); - newConfiguration.addConfiguration((PropertiesConfiguration) configuration); - } - combinedConfiguration = newConfiguration; - viewerConfiguration.addConfiguration(combinedConfiguration); + addCommonConfiguration(); clearViewerCachableObjectsAfterConfigurationChange(); } diff --git a/src/main/resources/config/dbvtk-viewer.properties b/src/main/resources/config/dbvtk-viewer.properties index 4b5e1f43..0023583e 100644 --- a/src/main/resources/config/dbvtk-viewer.properties +++ b/src/main/resources/config/dbvtk-viewer.properties @@ -8,6 +8,7 @@ ############################################## ui.sharedProperties.whitelist.configuration.prefix=lists ui.sharedProperties.whitelist.configuration.prefix=ui.lists +ui.sharedProperties.whitelist.configuration.prefix=ui.reload ui.sharedProperties.whitelist.configuration.prefix=ui.header ui.sharedProperties.whitelist.configuration.prefix=ui.interface ui.sharedProperties.whitelist.configuration.prefix=ui.disable @@ -163,3 +164,8 @@ ui.lists.DatabaseList_all.search.selectedInfo.label.default.i18n=lists.label.Dat # Show schema name in reference table ############################################## ui.reference.table.show.schema.name=true +############################################## +# Reload dbptk viewer properties +############################################## +ui.reload.viewer.properties=false +ui.reload.viewer.properties.period=86400000 diff --git a/src/main/resources/config/users-groups.properties b/src/main/resources/config/users-groups.properties new file mode 100644 index 00000000..53187078 --- /dev/null +++ b/src/main/resources/config/users-groups.properties @@ -0,0 +1,20 @@ +############################################## +# This file is used to configure the users and groups if automatic reload of them is desired. +# If not keep this file empty. +############################################## +############################################## +# Authorization Groups +#-------------------------------------------- +# A list of authorization groups for databases, +# DBPTKE will compare user roles with permissions saved in databases status using these groups. +# Label: Replaces attributeValue in interface. +# attributeName: Session attribute that will be added in user roles +# attributeOperator: Operator used to check database permissions +# attributeValue: Value used to check database permissions +# For now only the EQUAL operator is implemented +############################################## +#lists.collections.authorization.groups[]={list value} +#lists.collections.authorization.groups[].{list value}.label=Group1 +#lists.collections.authorization.groups[].{list value}.attributeName=memberOf +#lists.collections.authorization.groups[].{list value}.attributeOperator=EQUAL +#lists.collections.authorization.groups[].{list value}.attributeValue=roda \ No newline at end of file