diff --git a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java index 2a499fd3f634cf3a5d392b7edea6e5587789386d..9496ab1d308ded60ed0cb15f9aba0c685b1009bb 100644 --- a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java +++ b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java @@ -220,12 +220,17 @@ public enum ConfigurationElementType { LDAP_LAST_NAME_ATTRIBUTE("LDAP last name attribute", "sn", ConfigurationElementEditType.STRING, true, ConfigurationElementTypeGroup.LDAP_CONFIGURATION), // LDAP_EMAIL_ATTRIBUTE("LDAP email attribute", "mail", ConfigurationElementEditType.STRING, true, - ConfigurationElementTypeGroup.LDAP_CONFIGURATION),// - LDAP_FILTER("LDAP filter ", "(memberof=cn=minerva,cn=groups,cn=accounts,dc=uni,dc=lu)", ConfigurationElementEditType.STRING, true, ConfigurationElementTypeGroup.LDAP_CONFIGURATION), // + + LDAP_FILTER("LDAP filter", "(memberof=cn=minerva,cn=groups,cn=accounts,dc=uni,dc=lu)", + ConfigurationElementEditType.STRING, true, ConfigurationElementTypeGroup.LDAP_CONFIGURATION), // DEFAULT_CUSTOM_LAYOUTS("Default user privilege for: " + PrivilegeType.CUSTOM_LAYOUTS.getCommonName(), "0", ConfigurationElementEditType.INTEGER, true, ConfigurationElementTypeGroup.DEFAULT_USER_PRIVILEGES), + + LDAP_UID("LDAP login (user id)", "uid", ConfigurationElementEditType.STRING, true, + ConfigurationElementTypeGroup.LDAP_CONFIGURATION), // + ; /** diff --git a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationOption.java b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationOption.java index 2d12ff2709ea90568aeb662b92b52150ff3b81a7..c664b6fb46087b1a53fd1146d218bd08c5f8f15e 100644 --- a/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationOption.java +++ b/model/src/main/java/lcsb/mapviewer/model/user/ConfigurationOption.java @@ -4,6 +4,8 @@ import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -35,6 +37,7 @@ public class ConfigurationOption implements Serializable { /** * Type of the configuration element. */ + @Enumerated(EnumType.STRING) private ConfigurationElementType type; /** diff --git a/persist/src/main/resources/db/migration/12.1.0~beta.2/V12.1.0.20181001__configuration_option_type_resolved_by_name.sql b/persist/src/main/resources/db/migration/12.1.0~beta.2/V12.1.0.20181001__configuration_option_type_resolved_by_name.sql new file mode 100644 index 0000000000000000000000000000000000000000..bb09473307e7bc2c51292a04dbe6e1b30f3f46e7 --- /dev/null +++ b/persist/src/main/resources/db/migration/12.1.0~beta.2/V12.1.0.20181001__configuration_option_type_resolved_by_name.sql @@ -0,0 +1,49 @@ +--configuration table should have type column that is resolved by string enum name (not enum id) +alter table configuration_table add column type_string varchar; +update configuration_table set type_string='EMAIL_ADDRESS' where type = 0; +update configuration_table set type_string='EMAIL_LOGIN' where type = 1; +update configuration_table set type_string='EMAIL_PASSWORD' where type = 2; +update configuration_table set type_string='EMAIL_IMAP_SERVER' where type = 3; +update configuration_table set type_string='EMAIL_SMTP_SERVER' where type = 4; +update configuration_table set type_string='EMAIL_SMTP_PORT' where type = 5; +update configuration_table set type_string='DEFAULT_MAP' where type = 6; +update configuration_table set type_string='LOGO_IMG' where type = 7; +update configuration_table set type_string='LOGO_LINK' where type = 8; +update configuration_table set type_string='SEARCH_DISTANCE' where type = 9; +update configuration_table set type_string='REQUEST_ACCOUNT_EMAIL' where type = 10; +update configuration_table set type_string='SEARCH_RESULT_NUMBER' where type = 11; +update configuration_table set type_string='GOOGLE_ANALYTICS_IDENTIFIER' where type = 12; +update configuration_table set type_string='LOGO_TEXT' where type = 13; +update configuration_table set type_string='X_FRAME_DOMAIN' where type = 14; +update configuration_table set type_string='BIG_FILE_STORAGE_DIR' where type = 15; +update configuration_table set type_string='LEGEND_FILE_1' where type = 16; +update configuration_table set type_string='LEGEND_FILE_2' where type = 17; +update configuration_table set type_string='LEGEND_FILE_3' where type = 18; +update configuration_table set type_string='LEGEND_FILE_4' where type = 19; +update configuration_table set type_string='USER_MANUAL_FILE' where type = 20; +update configuration_table set type_string='MIN_COLOR_VAL' where type = 21; +update configuration_table set type_string='MAX_COLOR_VAL' where type = 22; +update configuration_table set type_string='SIMPLE_COLOR_VAL' where type = 23; +update configuration_table set type_string='NEUTRAL_COLOR_VAL' where type = 24; +update configuration_table set type_string='OVERLAY_OPACITY' where type = 25; +update configuration_table set type_string='REQUEST_ACCOUNT_DEFAULT_CONTENT' where type = 26; +update configuration_table set type_string='DEFAULT_VIEW_PROJECT' where type = 27; +update configuration_table set type_string='DEFAULT_EDIT_COMMENTS_PROJECT' where type = 28; +update configuration_table set type_string='DEFAULT_LAYOUT_MANAGEMENT' where type = 29; +update configuration_table set type_string='SHOW_REACTION_TYPE' where type = 30; +update configuration_table set type_string='GOOGLE_MAPS_API_KEY' where type = 31; +update configuration_table set type_string='TERMS_OF_USE' where type = 32; +update configuration_table set type_string='LDAP_ADDRESS' where type = 33; +update configuration_table set type_string='LDAP_PORT' where type = 34; +update configuration_table set type_string='LDAP_SSL' where type = 35; +update configuration_table set type_string='LDAP_BIND_DN' where type = 36; +update configuration_table set type_string='LDAP_PASSWORD' where type = 37; +update configuration_table set type_string='LDAP_BASE_DN' where type = 38; +update configuration_table set type_string='LDAP_OBJECT_CLASS' where type = 39; +update configuration_table set type_string='LDAP_FIRST_NAME_ATTRIBUTE' where type = 40; +update configuration_table set type_string='LDAP_LAST_NAME_ATTRIBUTE' where type = 41; +update configuration_table set type_string='LDAP_EMAIL_ATTRIBUTE' where type = 42; +update configuration_table set type_string='LDAP_FILTER' where type = 43; +update configuration_table set type_string='DEFAULT_CUSTOM_LAYOUTS' where type = 44; +alter table configuration_table drop column type; +alter table configuration_table rename column type_string to type; diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/LdapService.java b/service/src/main/java/lcsb/mapviewer/services/impl/LdapService.java index 1f06dc7d90eb4a05f8418a7b70ace190481b0ec2..868bc973d86d0814f738f36c4bfa2d7941039a0d 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/LdapService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/LdapService.java @@ -113,10 +113,11 @@ public class LdapService implements ILdapService { Filter filter = Filter.createANDFilter(f2, f3); String baseDn = configurationService.getConfigurationValue(ConfigurationElementType.LDAP_BASE_DN); + String uidProperty = configurationService.getConfigurationValue(ConfigurationElementType.LDAP_UID); SearchResult searchResult = connection.search(baseDn, SearchScope.SUB, filter); for (SearchResultEntry entry : searchResult.getSearchEntries()) { - Attribute uid = entry.getAttribute("uid"); + Attribute uid = entry.getAttribute(uidProperty); if (uid != null) { result.add(uid.getValue()); } else { @@ -137,12 +138,15 @@ public class LdapService implements ILdapService { LDAPConnection connection = getConnection(); try { String baseDn = configurationService.getConfigurationValue(ConfigurationElementType.LDAP_BASE_DN); + String uidAttribute = configurationService.getConfigurationValue(ConfigurationElementType.LDAP_UID); + String firstNameAttribute = configurationService .getConfigurationValue(ConfigurationElementType.LDAP_FIRST_NAME_ATTRIBUTE); String lastNameAttribute = configurationService .getConfigurationValue(ConfigurationElementType.LDAP_LAST_NAME_ATTRIBUTE); String emailAttribute = configurationService.getConfigurationValue(ConfigurationElementType.LDAP_EMAIL_ATTRIBUTE); + Filter f1 = createLoginFilter(login); Filter f2 = createObjectClassFilter(); Filter f3 = createAttributeFilter(); @@ -154,9 +158,9 @@ public class LdapService implements ILdapService { UserDTO result = new UserDTO(); result.setBindDn(entry.getDN()); - Attribute uidAttribute = entry.getAttribute("uid"); - if (uidAttribute != null) { - result.setLogin(uidAttribute.getValue()); + Attribute uid = entry.getAttribute(uidAttribute); + if (uid != null) { + result.setLogin(uid.getValue()); } else { logger.warn("Invalid ldap entry: " + entry); } @@ -210,7 +214,8 @@ public class LdapService implements ILdapService { } private Filter createLoginFilter(String login) { - return Filter.createEqualityFilter("uid", login); + String uidProperty = configurationService.getConfigurationValue(ConfigurationElementType.LDAP_UID); + return Filter.createEqualityFilter(uidProperty, login); } public IConfigurationService getConfigurationService() {