Skip to content
Snippets Groups Projects
Commit 7cdca594 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

configuration option enum is mapped by string not id; ldap uses additional option uid

parent 1c993ac3
No related branches found
No related tags found
2 merge requests!43412.1.0~beta.2 into master,!430Resolve "ldap uid parameter should be configurable"
Pipeline #6627 passed
......@@ -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), //
;
/**
......
......@@ -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;
/**
......
--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;
......@@ -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() {
......
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