Skip to content

Commit

Permalink
UBO-345 Do not die on multiple LEAD_ID in IdentityPicker (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi authored Jul 17, 2024
1 parent 6a5e4f1 commit abf9930
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions ubo-common/src/main/java/org/mycore/ubo/local/LocalService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package org.mycore.ubo.local;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.naming.OperationNotSupportedException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jdom2.Element;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.ubo.picker.IdentityService;
Expand All @@ -17,7 +12,14 @@
import org.mycore.user2.MCRUserAttribute;
import org.mycore.user2.MCRUserManager;

import javax.naming.OperationNotSupportedException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class LocalService implements IdentityService {
private final static Logger LOGGER = LogManager.getLogger(LocalService.class);

private final String USER_FIRST_NAME_ATTR = "firstName";

Expand Down Expand Up @@ -51,7 +53,16 @@ public PersonSearchResult searchPerson(String query, MCRRealm realm) {

List<PersonSearchResult.PersonResult> personResults = matchingUsers.stream().map(user -> {
PersonSearchResult.PersonResult personSearchResult = new PersonSearchResult.PersonResult(this);
personSearchResult.pid = user.getUserAttribute("id_" + LEAD_ID);
List<MCRUserAttribute> leadIdAttributes = user.getAttributes()
.stream()
.filter(attr -> ("id_" + LEAD_ID).equals(attr.getName()))
.toList();

if (leadIdAttributes.size() > 1) {
LOGGER.warn("Found more than one {} for user {}", ("id_" + LEAD_ID), user.getUserID());
}

personSearchResult.pid = leadIdAttributes.size() > 0 ? leadIdAttributes.get(0).getValue() : null;
personSearchResult.displayName = user.getRealName().length() > 0 ? user.getRealName() : user.getUserName();

user.getAttributes().stream()
Expand Down

0 comments on commit abf9930

Please sign in to comment.