-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
users and groups synchronization (#438)
- Loading branch information
1 parent
97cd819
commit c2c4086
Showing
4 changed files
with
101 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,13 @@ | |
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.configuration.CombinedConfiguration; | ||
import org.apache.commons.configuration.CompositeConfiguration; | ||
import org.apache.commons.configuration.Configuration; | ||
import org.apache.commons.configuration.ConfigurationException; | ||
|
@@ -60,7 +64,7 @@ | |
|
||
/** | ||
* Singleton configuration instance used by the Database Visualization Toolkit | ||
* | ||
* | ||
* @author Bruno Ferreira <[email protected]> | ||
*/ | ||
public class ViewerConfiguration extends ViewerAbstractConfiguration { | ||
|
@@ -100,7 +104,7 @@ public class ViewerConfiguration extends ViewerAbstractConfiguration { | |
|
||
public static final String PROPERTY_AUTHORIZATION_FULLNAME_ATTRIBUTE = "user.attribute.fullname"; | ||
public static final String PROPERTY_AUTHORIZATION_EMAIL_ATTRIBUTE = "user.attribute.email"; | ||
public static final String PROPERTY_AUTHORIZATION_ROLES_ATTRIBUTE = "user.attribute.roles"; | ||
public static final String PROPERTY_AUTHORIZATION_ROLES_ATTRIBUTE = "user.attribute.roles[]"; | ||
public static final String PROPERTY_AUTHORIZATION_ADMINISTRATORS = "user.attribute.roles.administrators"; | ||
|
||
public static final String PROPERTY_AUTHENTICATED_USER_ENABLE_DEFAULT_ATTRIBUTES = "authenticated.user.enable.default.attributes"; | ||
|
@@ -132,6 +136,8 @@ public class ViewerConfiguration extends ViewerAbstractConfiguration { | |
public static final String PROPERTY_BLOB_PREFIX_NAME = "ui.blob.prefix.name"; | ||
|
||
public static final String SIARD_AVAILABLE_TO_SEARCH_ALL = "ui.siard.available.search.all"; | ||
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; | ||
|
@@ -153,7 +159,10 @@ public class ViewerConfiguration extends ViewerAbstractConfiguration { | |
|
||
// Configuration related objects | ||
private static CompositeConfiguration viewerConfiguration = null; | ||
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; | ||
|
@@ -281,15 +290,32 @@ private ViewerConfiguration() { | |
|
||
// load core configurations | ||
configurationFiles = new ArrayList<>(); | ||
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); | ||
|
||
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, reloadPeriod, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
} catch (ConfigurationException e) { | ||
LOGGER.error("Error loading dbvtk properties", e); | ||
instantiatedWithoutErrors = false; | ||
|
@@ -534,14 +560,14 @@ public AuthorizationGroupsList getCollectionsAuthorizationGroupsWithAdminAndUser | |
AuthorizationGroupsList authorizationGroupsList = getCollectionsAuthorizationGroups(); | ||
|
||
final List<String> adminRoles = ViewerConfiguration.getInstance() | ||
.getViewerConfigurationAsList(ViewerConfiguration.PROPERTY_AUTHORIZATION_ADMINISTRATORS); | ||
.getViewerConfigurationAsList(ViewerConfiguration.PROPERTY_AUTHORIZATION_ADMINISTRATORS); | ||
|
||
for (String adminRole : adminRoles) { | ||
AuthorizationGroup authorizationGroup = new AuthorizationGroup(); | ||
authorizationGroup.setId("roles.administrators." + adminRole); | ||
authorizationGroup.setLabel("Administrators"); | ||
authorizationGroup.setAttributeName(getViewerConfigurationAsString(ViewerConstants.DEFAULT_ATTRIBUTE_ROLES, | ||
ViewerConfiguration.PROPERTY_AUTHORIZATION_ROLES_ATTRIBUTE)); | ||
ViewerConfiguration.PROPERTY_AUTHORIZATION_ROLES_ATTRIBUTE)); | ||
authorizationGroup.setAttributeOperator(PROPERTY_COLLECTIONS_AUTHORIZATION_GROUP_OPERATOR_EQUAL); | ||
authorizationGroup.setAttributeValue(adminRole); | ||
authorizationGroup.setType(AuthorizationGroup.Type.DEFAULT); | ||
|
@@ -553,7 +579,7 @@ public AuthorizationGroupsList getCollectionsAuthorizationGroupsWithAdminAndUser | |
authorizationGroup.setId("roles.users"); | ||
authorizationGroup.setLabel("Users"); | ||
authorizationGroup.setAttributeName(getViewerConfigurationAsString(ViewerConstants.DEFAULT_ATTRIBUTE_ROLES, | ||
ViewerConfiguration.PROPERTY_AUTHORIZATION_ROLES_ATTRIBUTE)); | ||
ViewerConfiguration.PROPERTY_AUTHORIZATION_ROLES_ATTRIBUTE)); | ||
authorizationGroup.setAttributeOperator(PROPERTY_COLLECTIONS_AUTHORIZATION_GROUP_OPERATOR_EQUAL); | ||
authorizationGroup.setAttributeValue(getViewerConfigurationAsString("users", "user.attribute.roles.users")); | ||
authorizationGroup.setType(AuthorizationGroup.Type.DEFAULT); | ||
|
@@ -682,6 +708,21 @@ private static void addConfiguration(String configurationFile) throws Configurat | |
configurationFiles.add(configurationFile); | ||
} | ||
|
||
private static void addCommonConfiguration() throws ConfigurationException { | ||
for (String configurationFile : commonConfigurationFiles) { | ||
Configuration configuration = getConfiguration(configurationFile); | ||
combinedConfiguration.addConfiguration((PropertiesConfiguration) configuration); | ||
} | ||
viewerConfiguration.addConfiguration(combinedConfiguration); | ||
} | ||
|
||
private void reloadCombinedConfiguration() throws ConfigurationException { | ||
viewerConfiguration.removeConfiguration(combinedConfiguration); | ||
combinedConfiguration.clear(); | ||
addCommonConfiguration(); | ||
clearViewerCachableObjectsAfterConfigurationChange(); | ||
} | ||
|
||
private static Configuration getConfiguration(String configurationFile) throws ConfigurationException { | ||
Path config = configPath.resolve(configurationFile); | ||
PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |