KEYCLOAK-19391: Fix ldap query search adding custom serach filter
This commit is contained in:
parent
cdd5c47ed7
commit
e69c3dcb1f
1 changed files with 18 additions and 8 deletions
|
@ -370,26 +370,36 @@ public class LDAPOperationManager {
|
|||
}
|
||||
|
||||
public String getFilterById(String id) {
|
||||
String filter = null;
|
||||
StringBuilder filter = new StringBuilder();
|
||||
filter.insert(0, "(&");
|
||||
|
||||
if (this.config.isObjectGUID()) {
|
||||
byte[] objectGUID = LDAPUtil.encodeObjectGUID(id);
|
||||
|
||||
filter = "(&(objectClass=*)(" + getUuidAttributeName() + LDAPConstants.EQUAL + LDAPUtil.convertObjectGUIDToByteString(objectGUID) + "))";
|
||||
filter.append("(objectClass=*)(").append(
|
||||
getUuidAttributeName()).append(LDAPConstants.EQUAL)
|
||||
.append(LDAPUtil.convertObjectGUIDToByteString(
|
||||
objectGUID)).append(")");
|
||||
|
||||
} else if (this.config.isEdirectoryGUID()) {
|
||||
filter = "(&(objectClass=*)(" + getUuidAttributeName().toUpperCase() + LDAPConstants.EQUAL + LDAPUtil.convertGUIDToEdirectoryHexString(id) + "))";
|
||||
filter.append("(objectClass=*)(").append(getUuidAttributeName().toUpperCase())
|
||||
.append(LDAPConstants.EQUAL
|
||||
).append(LDAPUtil.convertGUIDToEdirectoryHexString(id)).append(")");
|
||||
} else {
|
||||
filter.append("(objectClass=*)(").append(getUuidAttributeName()).append(LDAPConstants.EQUAL)
|
||||
.append(id).append(")");
|
||||
}
|
||||
|
||||
if (filter == null) {
|
||||
filter = "(&(objectClass=*)(" + getUuidAttributeName() + LDAPConstants.EQUAL + id + "))";
|
||||
if (config.getCustomUserSearchFilter() != null) {
|
||||
filter.append(config.getCustomUserSearchFilter());
|
||||
}
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.tracef("Using filter for lookup user by LDAP ID: %s", filter);
|
||||
logger.tracef("Using filter for lookup user by LDAP ID: %s", filter.toString());
|
||||
}
|
||||
|
||||
return filter;
|
||||
filter.append(")");
|
||||
|
||||
return filter.toString();
|
||||
}
|
||||
|
||||
public SearchResult lookupById(final String baseDN, final String id, final Collection<String> returningAttributes) {
|
||||
|
|
Loading…
Reference in a new issue