docs: public static String prepareDN(String DN, String searchRoot) {
          if (DN == null || DN.trim().length() == 0) {
              return searchRoot;
          }
          // unescape double blackslashes
          DN = unescapeDoubleBackslash(DN);
          DN = unescapeSingleQuote(DN); // fix login failure when single quote (') is in userid
          DN = UniqueNameHelper.unescapeSpaces(DN);
  
          //process special character enclosing double quotes
          int length = DN.length();
          if ((DN.charAt(0) == '\"') && (DN.charAt(length - 1) == '\"')) {
              DN = DN.substring(1, length - 1);
          }
  
          // Remove server URL suffix if the DN is referral from another LDAP server.
          if (DN.startsWith("/")) {
              int pos1 = DN.indexOf(':');
              if (pos1 > -1) {
                  int pos2 = DN.indexOf('/', pos1);
                  if (pos2 > 0)
                      DN = DN.substring(pos2 + 1);
              }
  
          } else if (DN.toLowerCase().startsWith("ldap://")) {
              boolean parsed = false;
  
              try {
                  // Use the Ldap URL parser to ensure that %xx gets decoded
                  LdapURL ldapURL = new LdapURL(DN);
                  if (ldapURL.parsedOK()) {
                      DN = ldapURL.get_dn();
                      parsed = true;
                  }
              } catch (Exception excp) {
              }
  
              if (!parsed) {
                  int pos1 = DN.indexOf(':', "ldap://".length());
                  if (pos1 > 0) {
                      int pos2 = DN.indexOf("/", pos1);
                      if (pos2 > 0)
                          DN = DN.substring(pos2 + 1);
                  }
              }
          } else if (DN.toLowerCase().startsWith("ldaps://")) {
              boolean parsed = false;
  
              try {
                  // Use the Ldap URL parser to ensure that %xx gets decoded
                  LdapURL ldapURL = new LdapURL(DN);
                  if (ldapURL.parsedOK()) {
                      DN = ldapURL.get_dn();
                      parsed = true;
                  }
              } catch (Exception excp) {
              }
  
              if (!parsed) {
                  int pos1 = DN.indexOf(':', "ldaps://".length());
                  if (pos1 > 0) {
                      int pos2 = DN.indexOf("/", pos1);
                      if (pos2 > 0)
                          DN = DN.substring(pos2 + 1);
                  }
              }
          }
          if (searchRoot == null || searchRoot.trim().length() == 0) {
              return DN;
          }
          StringTokenizer stDN = new StringTokenizer(DN, LdapConstants.LDAP_DN_SEPARATOR);
          StringTokenizer stSearchRoot = new StringTokenizer(searchRoot, LdapConstants.LDAP_DN_SEPARATOR);
          String lastDNToken = null;
          String lastSearchRootToken = null;
  
          while (stDN.hasMoreTokens()) {
              lastDNToken = stDN.nextToken();
          }
          while (stSearchRoot.hasMoreTokens()) {
              lastSearchRootToken = stSearchRoot.nextToken();
          }
          if (lastDNToken != null)
              lastDNToken = lastDNToken.trim();
          else
              lastDNToken = "";
          if (lastSearchRootToken != null) {
              lastSearchRootToken = lastSearchRootToken.trim();
          } else {
              lastSearchRootToken = "";
          }
          if (!lastDNToken.equalsIgnoreCase(lastSearchRootToken))
              if (DN.length() > 0) {
                  DN = DN + LdapConstants.LDAP_DN_SEPARATOR + searchRoot;
              } else
                  DN = searchRoot;
          return DN;
  
      }