We are migrating a java based application hosted on RHEL 5 to RHEL 7. It has a feature to search users based on username (cn) from ldap directory installed on the linux server.The above feature is working fine with RHEL 5 having openldap version 2.3.43 in the server.And our application is internally using spring-ldap-core-1.3.1.RELEASE jar to fetch the data from the openldap .JAVA version in old server is 1.7
Currently we are having RHEL 7 ,JBOSS-EAP 7,opendldap 2.4.44 ,java 8 and spring-ldap-core-1.3.1 .
When we are running ldap command directly on server to search the user based on "cn" it is giving us the desired result but via application it is unable to fetch the result using the spring ldap jar
Below is the command use to get result on the server :
ldapsearch -x -h localhost -b "cn=xxx,o=xxxUser,dc=eu,dc=xxx,dc=com"
With the above command we are getting the desired result but dont know why unable to get using the above jar.
We tried to upgrade spring-ldap-core-1.3.1 to 2.3.2.RELEASE version.But still facing same issue.
We are using below codes to call :
public List<User> searchUsersByUserName(final String userName) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectClass", "user"));
filter.and(new WhitespaceWildcardsFilter("cn", userName));
return this.processSearchResults(this.ldapTemplate.search("o=xxxUser", filter.encode(), new UserContextMapper()));
}
I am unable to get data from the ldap server for cn and unable to pass it to UserContextMapper .
This is our UserContextMapper class :
/**
* Context mapper for ldap users.
*/
public class UserContextMapper implements ParameterizedContextMapper<User> {
@Override
public User mapFromContext(final Object ctx) {
DirContextAdapter context = (DirContextAdapter) ctx;
String cn = context.getStringAttribute("cn");
String surName = context.getStringAttribute("sn");
String fullName = context.getStringAttribute("displayName");
String givenName = context.getStringAttribute("givenName");
String userMail = context.getStringAttribute("usermail");
User u = new User(cn, surName, fullName, givenName, userMail);
String[] groupsArray = context.getStringAttributes("memberOf");
if (groupsArray != null) {
for (String group : Arrays.asList(groupsArray)) {
u.getGroups().add(LdapHelper.getOrganizationalUnit(group));
}
}
return u;
}
}
ldapTemplate.search("o=xxxUser,dc=eu,dc=xxx,dc=com", filter.encode(), new UserContextMapper())
. And filter username withnew EqualsFilter("cn", userName);
- EricLavault