Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-67271 SF rename #30

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,6 +4,7 @@ targetCompatibility = "1.8"
dependencies {
compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "default"
compileOnly group: "commons-lang", name: "commons-lang", version: "2.6"
compileOnly group: "org.osgi", name: "org.osgi.service.cm", version: "1.5.0"
compileOnly project(":apps:portal-security:portal-security-export-import-api")
compileOnly project(":apps:static:portal-configuration:portal-configuration-metatype-api")
Expand Down
Expand Up @@ -17,6 +17,7 @@
import com.liferay.petra.string.CharPool;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.util.DateFormatFactoryUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;

import java.text.DateFormat;
Expand All @@ -28,6 +29,8 @@
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;

import org.apache.commons.lang.StringEscapeUtils;

/**
* @author Toma Bedolla
* @author Michael Young
Expand All @@ -37,6 +40,22 @@
*/
public class LDAPUtil {

public static String escapeCharacters(String attribute) {
if (attribute.contains(StringPool.BACK_SLASH)) {
String escapedSingleBackSlash = StringPool.DOUBLE_BACK_SLASH.concat(
StringPool.BACK_SLASH);

attribute = attribute.replace(
StringPool.BACK_SLASH, escapedSingleBackSlash);
}
else {
attribute = StringEscapeUtils.escapeJava(attribute);
}

return StringUtil.replace(
attribute, _INVALID_CHARS, _INVALID_CHARS_SUBS);
}

public static Object getAttributeObject(
Attributes attributes, Properties properties, String key)
throws NamingException {
Expand Down Expand Up @@ -213,4 +232,18 @@ else if (date.indexOf(CharPool.PERIOD) != -1) {
return dateFormat.parse(date);
}

private static final String[] _INVALID_CHARS = {
StringPool.GREATER_THAN, StringPool.LESS_THAN, StringPool.PLUS,
StringPool.POUND, StringPool.QUOTE, StringPool.SEMICOLON
};

private static final String[] _INVALID_CHARS_SUBS = {
StringPool.DOUBLE_BACK_SLASH.concat(StringPool.GREATER_THAN),
StringPool.DOUBLE_BACK_SLASH.concat(StringPool.LESS_THAN),
StringPool.DOUBLE_BACK_SLASH.concat(StringPool.PLUS),
StringPool.DOUBLE_BACK_SLASH.concat(StringPool.POUND),
StringPool.DOUBLE_BACK_SLASH.concat(StringPool.QUOTE),
StringPool.DOUBLE_BACK_SLASH.concat(StringPool.SEMICOLON)
};

}
@@ -1 +1 @@
version 1.0.0
version 1.1.0
Expand Up @@ -36,6 +36,7 @@
import com.liferay.portal.security.ldap.configuration.ConfigurationProvider;
import com.liferay.portal.security.ldap.configuration.LDAPServerConfiguration;
import com.liferay.portal.security.ldap.configuration.SystemLDAPConfiguration;
import com.liferay.portal.security.ldap.util.LDAPUtil;
import com.liferay.portal.security.ldap.validator.LDAPFilterValidator;

import java.util.ArrayList;
Expand Down Expand Up @@ -538,7 +539,8 @@ public Binding getUser(
_ldapServerConfigurationProvider.getConfiguration(
companyId, ldapServerId);

String baseDN = ldapServerConfiguration.baseDN();
String baseDN = LDAPUtil.escapeCharacters(
ldapServerConfiguration.baseDN());

String userSearchFilter =
ldapServerConfiguration.userSearchFilter();
Expand Down Expand Up @@ -911,6 +913,8 @@ public byte[] searchLDAP(
List<SearchResult> searchResults)
throws Exception {

baseDN = LDAPUtil.escapeCharacters(baseDN);

SearchControls searchControls = new SearchControls(
SearchControls.SUBTREE_SCOPE, maxResults, 0, attributeIds, false,
false);
Expand Down
Expand Up @@ -43,6 +43,7 @@
import com.liferay.portal.security.ldap.constants.LDAPConstants;
import com.liferay.portal.security.ldap.exportimport.LDAPUserImporter;
import com.liferay.portal.security.ldap.exportimport.configuration.LDAPImportConfiguration;
import com.liferay.portal.security.ldap.util.LDAPUtil;

import java.util.HashMap;
import java.util.Hashtable;
Expand Down Expand Up @@ -299,7 +300,8 @@ protected int authenticate(
_ldapServerConfigurationProvider.getConfiguration(
companyId, ldapServerId);

String baseDN = ldapServerConfiguration.baseDN();
String baseDN = LDAPUtil.escapeCharacters(
ldapServerConfiguration.baseDN());

// Process LDAP auth search filter

Expand Down
Expand Up @@ -171,7 +171,8 @@ public User importUser(
_ldapServerConfigurationProvider.getConfiguration(
companyId, ldapServerId);

String baseDN = ldapServerConfiguration.baseDN();
String baseDN = LDAPUtil.escapeCharacters(
ldapServerConfiguration.baseDN());

ldapContext = _portalLDAP.getContext(ldapServerId, companyId);

Expand Down