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 cn: Bernd Bern
userPassword: user-b-1 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: inetorgperson
objectclass: organizationalperson objectclass: organizationalperson
objectclass: person objectclass: person
objectclass: top objectclass: top
givenName: Brunhilde givenName: Brunhilde
description: desc description: desc
uid: user-b-2 uid: User-b-2
sn: Bio sn: Bio
ou: Organisationseinheit/Organisationseinheit B ou: Organisationseinheit/Organisationseinheit B
cn: Brunhilde Bio cn: Brunhilde Bio

View File

@ -340,14 +340,14 @@ ou: Organisationseinheit/Organisationseinheit B
cn: Bernd Bern cn: Bernd Bern
userPassword: user-b-1 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: inetorgperson
objectclass: organizationalperson objectclass: organizationalperson
objectclass: person objectclass: person
objectclass: top objectclass: top
givenName: Brunhilde givenName: Brunhilde
description: desc description: desc
uid: user-b-2 uid: User-b-2
sn: Bio sn: Bio
ou: Organisationseinheit/Organisationseinheit B ou: Organisationseinheit/Organisationseinheit B
cn: Brunhilde Bio 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. */ /** Context Mapper for user entries. */
class GroupContextMapper extends AbstractContextMapper<AccessIdRepresentationModel> { class GroupContextMapper extends AbstractContextMapper<AccessIdRepresentationModel> {
@ -602,7 +611,7 @@ public class LdapClient {
@Override @Override
public User doMapFromContext(final DirContextOperations context) { public User doMapFromContext(final DirContextOperations context) {
final User user = new UserImpl(); final User user = new UserImpl();
user.setId(context.getStringAttribute(getUserIdAttribute())); user.setId(getUserIdFromContext(context));
user.setFirstName(context.getStringAttribute(getUserFirstnameAttribute())); user.setFirstName(context.getStringAttribute(getUserFirstnameAttribute()));
user.setLastName(context.getStringAttribute(getUserLastnameAttribute())); user.setLastName(context.getStringAttribute(getUserLastnameAttribute()));
user.setFullName(context.getStringAttribute(getUserFullnameAttribute())); user.setFullName(context.getStringAttribute(getUserFullnameAttribute()));
@ -624,7 +633,7 @@ 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();
accessId.setAccessId(context.getStringAttribute(getUserIdAttribute())); 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));
@ -638,7 +647,7 @@ 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 = context.getStringAttribute(getUserIdAttribute()); String userId = getUserIdFromContext(context);
if (userId != null) { if (userId != null) {
accessId.setAccessId(userId); accessId.setAccessId(userId);
String firstName = context.getStringAttribute(getUserFirstnameAttribute()); String firstName = context.getStringAttribute(getUserFirstnameAttribute());

View File

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