TSK-1751: LdapClient now returns accessIds for users in lower case if configured.

This commit is contained in:
Holger Hagen 2021-10-19 16:57:48 +02:00 committed by holgerhagen
parent 23919eb0a1
commit 97b5c73158
4 changed files with 20 additions and 10 deletions

View File

@ -345,14 +345,14 @@ ou: Organisationseinheit/Organisationseinheit B
cn: Bernd Bern
userPassword: user-b-1
dn: uid=user-b-2,cn=users,OU=Test,O=TASKANA
dn: uid=User-b-2,cn=users,OU=Test,O=TASKANA
objectclass: inetorgperson
objectclass: organizationalperson
objectclass: person
objectclass: top
givenName: Brunhilde
description: desc
uid: user-b-2
uid: User-b-2
sn: Bio
ou: Organisationseinheit/Organisationseinheit B
cn: Brunhilde Bio

View File

@ -340,14 +340,14 @@ ou: Organisationseinheit/Organisationseinheit B
cn: Bernd Bern
userPassword: user-b-1
dn: uid=user-b-2,cn=users,OU=Test,O=TASKANA
dn: uid=User-b-2,cn=users,OU=Test,O=TASKANA
objectclass: inetorgperson
objectclass: organizationalperson
objectclass: person
objectclass: top
givenName: Brunhilde
description: desc
uid: user-b-2
uid: User-b-2
sn: Bio
ou: Organisationseinheit/Organisationseinheit B
cn: Brunhilde Bio

View File

@ -584,6 +584,15 @@ public class LdapClient {
}
}
private String getUserIdFromContext(final DirContextOperations context) {
String userId = context.getStringAttribute(getUserIdAttribute());
if (userId != null && useLowerCaseForAccessIds) {
return userId.toLowerCase();
} else {
return userId;
}
}
/** Context Mapper for user entries. */
class GroupContextMapper extends AbstractContextMapper<AccessIdRepresentationModel> {
@ -602,7 +611,7 @@ public class LdapClient {
@Override
public User doMapFromContext(final DirContextOperations context) {
final User user = new UserImpl();
user.setId(context.getStringAttribute(getUserIdAttribute()));
user.setId(getUserIdFromContext(context));
user.setFirstName(context.getStringAttribute(getUserFirstnameAttribute()));
user.setLastName(context.getStringAttribute(getUserLastnameAttribute()));
user.setFullName(context.getStringAttribute(getUserFullnameAttribute()));
@ -624,7 +633,7 @@ public class LdapClient {
@Override
public AccessIdRepresentationModel doMapFromContext(final DirContextOperations context) {
final AccessIdRepresentationModel accessId = new AccessIdRepresentationModel();
accessId.setAccessId(context.getStringAttribute(getUserIdAttribute()));
accessId.setAccessId(getUserIdFromContext(context));
String firstName = context.getStringAttribute(getUserFirstnameAttribute());
String lastName = context.getStringAttribute(getUserLastnameAttribute());
accessId.setName(String.format("%s, %s", lastName, firstName));
@ -638,7 +647,7 @@ public class LdapClient {
@Override
public AccessIdRepresentationModel doMapFromContext(final DirContextOperations context) {
final AccessIdRepresentationModel accessId = new AccessIdRepresentationModel();
String userId = context.getStringAttribute(getUserIdAttribute());
String userId = getUserIdFromContext(context);
if (userId != null) {
accessId.setAccessId(userId);
String firstName = context.getStringAttribute(getUserFirstnameAttribute());

View File

@ -43,9 +43,11 @@ class AccessIdControllerIntTest {
List.of(
Pair.of(
"cn=ksc-users,cn=groups,OU=Test,O=TASKANA",
"cn=ksc-users,cn=groups,OU=Test,O=TASKANA"),
"cn=ksc-users,cn=groups,ou=test,o=taskana"),
Pair.of("uid=teamlead-1,cn=users,OU=Test,O=TASKANA", "teamlead-1"),
Pair.of("ksc-use", "cn=ksc-users,cn=groups,OU=Test,O=TASKANA"));
Pair.of("ksc-use", "cn=ksc-users,cn=groups,ou=test,o=taskana"),
Pair.of("user-b-2", "user-b-2"),
Pair.of("User-b-2", "user-b-2"));
ThrowingConsumer<Pair<String, String>> test =
pair -> {
@ -60,7 +62,6 @@ class AccessIdControllerIntTest {
assertThat(response.getBody())
.isNotNull()
.extracting(AccessIdRepresentationModel::getAccessId)
.usingElementComparator(String.CASE_INSENSITIVE_ORDER)
.containsExactly(pair.getRight());
};