Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 committed Nov 7, 2024
1 parent 6b0a74a commit 59f923d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> configurationFiles = null;
private static List<String> commonConfigurationFiles = null;

private List<String> cachedWhitelistedIPs = null;
private List<String> cachedWhiteListedUsername = null;
Expand Down Expand Up @@ -285,33 +289,30 @@ private ViewerConfiguration() {

// load core configurations
configurationFiles = new ArrayList<>();
boolean useExternalPropertiesFile = Boolean.parseBoolean(System.getenv(ViewerConstants.EXTERNAL_USERS_GROUPS_PROPERTIES_FILE));

if (useExternalPropertiesFile) {
List<String> 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");

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) {
Expand Down Expand Up @@ -706,25 +707,18 @@ private static void addConfiguration(String configurationFile) throws Configurat
configurationFiles.add(configurationFile);
}

private static void addCommonConfiguration(List<String> 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);
}

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();
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config/dbvtk-viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
20 changes: 20 additions & 0 deletions src/main/resources/config/users-groups.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 59f923d

Please sign in to comment.