code: @Override
      public Function<Principal, Principal> getPrincipalMapper() {
          return p -> {
              final ClassLoader old = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(UserLdapCallbackHandler.class);
              LdapConnectionHandler ldapConnectionHandler = createLdapConnectionHandler();
              try {
                  try {
                      SearchResult<LdapEntry> searchResult = userSearcherInjector.getValue().search(ldapConnectionHandler, p.getName());
  
                      return p instanceof RealmUser ? new MappedPrincipal(((RealmUser) p).getRealm(), searchResult.getResult().getSimpleName(), p.getName())
                              : new MappedPrincipal(searchResult.getResult().getSimpleName(), p.getName());
                  } catch (IllegalStateException | IOException | NamingException e) {
                      SECURITY_LOGGER.trace("Unable to map principal.", e);
                      return p;
                  }
              } finally {
                  safeClose(ldapConnectionHandler);
                  WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(old);
              }
          };
      }
docs: /*
  Service Methods