code: protected Pair<String, Map<String, List<Object>>> convertPersonAttributesToPrincipal(final String extractedPrincipalId,
                                                                                           final Map<String, List<Object>> attributes) {
          val convertedAttributes = new LinkedHashMap<String, List<Object>>();
          attributes.forEach((key, attrValue) -> {
              val values = CollectionUtils.toCollection(attrValue, ArrayList.class);
              LOGGER.debug("Found attribute [{}] with value(s) [{}]", key, values);
              if (values.size() == 1) {
                  val value = CollectionUtils.firstElement(values).get();
                  convertedAttributes.put(key, CollectionUtils.wrapList(value));
              } else {
                  convertedAttributes.put(key, values);
              }
          });
  
          var principalId = extractedPrincipalId;
  
          if (StringUtils.isNotBlank(this.principalAttributeNames)) {
              val attrNames = org.springframework.util.StringUtils.commaDelimitedListToSet(this.principalAttributeNames);
              val result = attrNames.stream()
                  .map(String::trim)
                  .filter(attributes::containsKey)
                  .map(attributes::get)
                  .findFirst();
  
              if (result.isPresent()) {
                  val values = result.get();
                  if (!values.isEmpty()) {
                      principalId = CollectionUtils.firstElement(values).get().toString();
                      LOGGER.debug("Found principal id attribute value [{}] and removed it from the collection of attributes", principalId);
                  }
              } else {
                  LOGGER.warn("Principal resolution is set to resolve the authenticated principal via attribute(s) [{}], and yet "
                      + "the collection of attributes retrieved [{}] do not contain any of those attributes. This is likely due to misconfiguration "
                      + "and CAS will switch to use [{}] as the final principal id", this.principalAttributeNames, attributes.keySet(), principalId);
              }
          }
  
          return Pair.of(principalId, convertedAttributes);
      }
docs: Convert person attributes to principal pair.
  
  @param extractedPrincipalId the extracted principal id
  @param attributes           the attributes
  @return the pair