From 97b5c7315878026beab20d8da4d9f557d328cbef Mon Sep 17 00:00:00 2001 From: Holger Hagen <19706592+holgerhagen@users.noreply.github.com> Date: Tue, 19 Oct 2021 16:57:48 +0200 Subject: [PATCH] TSK-1751: LdapClient now returns accessIds for users in lower case if configured. --- .../src/main/resources/taskana-test.ldif | 4 ++-- .../src/main/resources/taskana-example.ldif | 4 ++-- .../pro/taskana/common/rest/ldap/LdapClient.java | 15 ++++++++++++--- .../common/rest/AccessIdControllerIntTest.java | 7 ++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/common/taskana-common-test/src/main/resources/taskana-test.ldif b/common/taskana-common-test/src/main/resources/taskana-test.ldif index 30bd7e809..2c05e7969 100644 --- a/common/taskana-common-test/src/main/resources/taskana-test.ldif +++ b/common/taskana-common-test/src/main/resources/taskana-test.ldif @@ -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 diff --git a/rest/taskana-rest-spring-example-common/src/main/resources/taskana-example.ldif b/rest/taskana-rest-spring-example-common/src/main/resources/taskana-example.ldif index 962a39cea..dad402a47 100644 --- a/rest/taskana-rest-spring-example-common/src/main/resources/taskana-example.ldif +++ b/rest/taskana-rest-spring-example-common/src/main/resources/taskana-example.ldif @@ -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 diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/ldap/LdapClient.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/ldap/LdapClient.java index d34b1d2d8..040cd56dd 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/ldap/LdapClient.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/ldap/LdapClient.java @@ -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 { @@ -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()); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java index 2544c6840..acf5862d0 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java @@ -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> test = pair -> { @@ -60,7 +62,6 @@ class AccessIdControllerIntTest { assertThat(response.getBody()) .isNotNull() .extracting(AccessIdRepresentationModel::getAccessId) - .usingElementComparator(String.CASE_INSENSITIVE_ORDER) .containsExactly(pair.getRight()); };