TSK-1833: distinguish between ldap user and group by objectClass

This commit is contained in:
holgerhagen 2022-03-30 16:05:56 +02:00 committed by holgerhagen
parent f70d845793
commit e738cd2867
1 changed files with 10 additions and 6 deletions

View File

@ -509,9 +509,9 @@ public class LdapClient {
String[] getLookUpGroupAttributesToReturn() { String[] getLookUpGroupAttributesToReturn() {
if (CN.equals(getGroupNameAttribute())) { if (CN.equals(getGroupNameAttribute())) {
return new String[] {CN}; return new String[] {CN, getGroupSearchFilterName()};
} }
return new String[] {getGroupNameAttribute(), CN}; return new String[] {getGroupNameAttribute(), CN, getGroupSearchFilterName()};
} }
String[] getLookUpUserAndGroupAttributesToReturn() { String[] getLookUpUserAndGroupAttributesToReturn() {
@ -523,7 +523,10 @@ public class LdapClient {
String[] getLookUpUserAttributesToReturn() { String[] getLookUpUserAttributesToReturn() {
return new String[] { return new String[] {
getUserFirstnameAttribute(), getUserLastnameAttribute(), getUserIdAttribute() getUserFirstnameAttribute(),
getUserLastnameAttribute(),
getUserIdAttribute(),
getUserSearchFilterName()
}; };
} }
@ -663,9 +666,10 @@ public class LdapClient {
@Override @Override
public AccessIdRepresentationModel doMapFromContext(final DirContextOperations context) { public AccessIdRepresentationModel doMapFromContext(final DirContextOperations context) {
final AccessIdRepresentationModel accessId = new AccessIdRepresentationModel(); final AccessIdRepresentationModel accessId = new AccessIdRepresentationModel();
String userId = getUserIdFromContext(context); String[] objectClasses = context.getStringAttributes(getUserSearchFilterName());
if (userId != null) { if (objectClasses != null
accessId.setAccessId(userId); && Arrays.asList(objectClasses).contains(getUserSearchFilterValue())) {
accessId.setAccessId(getUserIdFromContext(context));
String firstName = context.getStringAttribute(getUserFirstnameAttribute()); String firstName = context.getStringAttribute(getUserFirstnameAttribute());
String lastName = context.getStringAttribute(getUserLastnameAttribute()); String lastName = context.getStringAttribute(getUserLastnameAttribute());
accessId.setName(String.format("%s, %s", lastName, firstName)); accessId.setName(String.format("%s, %s", lastName, firstName));