private static Map<String, List<Object>> collectAttributeValueForEntry(final LdapEntry ldapEntry, final String key,
                                                                           final Collection<String> attributeNames) {
        val attributeMap = new HashMap<String, List<Object>>();
        val attr = ldapEntry.getAttribute(key);
        if (attr != null) {
            LOGGER.debug("Found principal attribute: [{}]", attr);

            if (attributeNames.isEmpty()) {
                LOGGER.debug("Principal attribute [{}] is collected as [{}]", attr, key);
                attributeMap.put(key, CollectionUtils.wrap(attr.getStringValues()));
            } else {
                attributeNames.forEach(s -> {
                    LOGGER.debug("Principal attribute [{}] is virtually remapped/renamed to [{}]", attr, s);
                    attributeMap.put(s, CollectionUtils.wrap(attr.getStringValues()));
                });
            }
        } else {
            LOGGER.warn("Requested LDAP attribute [{}] could not be found on LDAP entry for [{}]", key, ldapEntry.getDn());
        }
        return attributeMap;
    }
Gets ldap principal identifier. If the principal id attribute is defined, it's retrieved.
If no attribute value is found, a warning is generated and the provided username is used instead.
If no attribute is defined, username is used instead.

@param username  the username
@param ldapEntry the ldap entry
@return the ldap principal identifier
@throws LoginException in case the principal id cannot be determined.
support/cas-server-support-ldap-core/src/main/java/org/apereo/cas/authentication/LdapAuthenticationHandler.java