public static boolean isLdapObjectOutOfScopeFromBaseDn(DirContextAdapter adapter, String baseDn) {
    boolean isOutOfScope = true;
    try {
      Name dn = adapter.getDn();
      Preconditions.checkArgument(dn != null, "DN cannot be null in LDAP response object");

      Name fullDn = getFullDn(dn, adapter);
      Name base = LdapUtils.newLdapName(baseDn);
      if (fullDn.startsWith(base)) {
        isOutOfScope = false;
      }
    } catch (Exception e) {
      LOG.error(e.getMessage());
    }
    return isOutOfScope;
  }
Determine that the full DN of an LDAP object is in/out of the base DN scope.

@param adapter used for get the full dn from the ldap query response
@param baseDn  the base distinguished name
@return true if the object is out of scope; false otherwise
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariLdapUtils.java