{"id":24515,"date":"2024-02-15T14:53:34","date_gmt":"2024-02-15T22:53:34","guid":{"rendered":"https:\/\/docs.extraview.com\/v25\/book\/ldapsearch-1\/"},"modified":"2024-02-15T14:53:34","modified_gmt":"2024-02-15T22:53:34","slug":"ldapsearch-1","status":"publish","type":"page","link":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/","title":{"rendered":"ldapSearch"},"content":{"rendered":"<h3>\n\tPurpose<\/h3>\n<p>This method, when given a firstName, lastName, and userId, will search for and return user matches in place of a normal LDAP search.<\/p>\n<h3>\n\tApplies To<\/h3>\n<p>LDAP<\/p>\n<h3>\n\tSignature<\/h3>\n<pre class=\"code\">\r\n<code>public TreeMap ldapSearch(String firstName,\r\n                               String lastName,\r\n                               String userId,\r\n                               boolean exactMatch,\r\n                               String sortBy)<\/code>\r\n<\/pre>\n<h3>\n\tNotes<\/h3>\n<p>The exactMatch specifies if the match is exact, the sortBy can be by &#8220;last&#8221;, &#8220;first&#8221;, &#8220;userId&#8221; or &#8220;&#8221; signifying how the returned TreeMap should be sorted. The values in the returned TreeMap must be HashMap&#8217;s with the name\/value pairs used by ldap. The names can be retrived from the Configuration.properties. The names may include wildcards (*), and this method is only called if ldapOverrive() returns true.<\/p>\n<h3>\n\tExample<\/h3>\n<pre class=\"code\">\r\n<code>public TreeMap ldapSearch (String firstName, \r\n                           String lastName, \r\n                           String userId, \r\n                           boolean exactMatch, \r\n                           String sortBy)\r\n{\r\n    TreeMap sortedResults = new TreeMap();\r\n    boolean extraFilter = false;\r\n    String extraFilterString = \"\";\r\n    ArrayList searchAttrs = new ArrayList();\r\n    ArrayList searchVals = new ArrayList();\r\n    \r\n    if (TextManager.isStringVisible(firstName)) {\r\n        searchAttrs.add(Z.lu.LDAP_GIVENNAME);\r\n        searchVals.add(firstName);\r\n    }\r\n    if (TextManager.isStringVisible(lastName)) {\r\n        searchAttrs.add(Z.lu.LDAP_SURNAME);\r\n        searchVals.add(lastName);\r\n    }\r\n    if (TextManager.isStringVisible(userId)) {\r\n        searchAttrs.add(Z.lu.LDAP_PRIMARYKEY);\r\n        searchVals.add(userId);\r\n    }\r\n    if (searchAttrs.size() == 0) {\r\n        \/\/ We should never fall into this else but if we do here is an alert\r\n        Z.log.writeToLog(Z.log.ERROR, \"UC: ldapSearch: \" +\r\n            \"Cannot seach LDAP with null information\");\r\n        return sortedResults;\r\n    }\r\n    \r\n    extraFilterString = Z.config.getConfigValue(\"LDAP_SEARCH_FILTER\");\r\n    \r\n    if (TextManager.isStringVisible(extraFilterString)) {\r\n        extraFilterString.trim();\r\n        extraFilter = true;\r\n    }\r\n    \r\n    \/\/ Setting up the filter\r\n    StringBuffer filter = new StringBuffer();\r\n    \r\n    if (searchAttrs.size() == 1 &amp;&amp; ! extraFilter)\r\n    {\r\n        \/\/ a = b\r\n        filter.append(\"(\");\r\n        filter.append((String)searchAttrs.get(0));\r\n        filter.append(\"=\");\r\n        filter.append((String)searchVals.get(0));\r\n    \r\n        if (! exactMatch) {\r\n            filter.append(\"*\");\r\n        }\r\n    \r\n        filter.append(\")\");\r\n    }\r\n    else\r\n    {\r\n        \/\/ (&amp;(a=b)(c=d)(e=f))\r\n        filter.append(\"(&amp;\");\r\n    \r\n        if (extraFilter) {\r\n            filter.append(extraFilterString);\r\n        }\r\n    \r\n        for (int x = 0; x &lt; searchAttrs.size(); x++)\r\n        {\r\n            filter.append(\"(\");\r\n            filter.append((String)searchAttrs.get(x));\r\n            filter.append(\"=\");\r\n            filter.append((String)searchVals.get(x));\r\n    \r\n            if (!exactMatch) {\r\n                filter.append(\"*\");\r\n            }\r\n\r\n            filter.append(\")\");\r\n        }\r\n    \r\n        filter.append(\")\");\r\n    }\r\n    \r\n    \/\/ Specify the scope of the search\r\n    \/\/ subtree: starts at the base entry and searches\r\n    \/\/ everything below it, including the base entry\r\n    SearchControls constraints = new SearchControls();\r\n    constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);\r\n    \r\n    try\r\n    {\r\n        String dn = Z.lu.getInitMgrDn();\r\n        String password = Z.lu.getInitPswd();\r\n        \r\n        DirContext ctx = null;\r\n        ctx = this.getContext(dn, password);\r\n        \r\n        \/\/ Perform the actual search\r\n        \/\/ We pass the searchbase, filters and constraints\r\n        \/\/ containing the scope of the search\r\n        NamingEnumeration results = ctx.search(\r\n            Z.lu.getInitSearchBase(), filter.toString(), constraints\r\n        );\r\n        \r\n        \/\/ default sort is by lastname\r\n        String sortKey1 = Z.lu.LDAP_SURNAME;\r\n        String sortKey2 = Z.lu.LDAP_GIVENNAME;\r\n        String sortKey3 = Z.lu.LDAP_PRIMARYKEY;\r\n    \r\n        if (\"first\".equalsIgnoreCase(sortBy)) {\r\n            sortKey1 = Z.lu.LDAP_GIVENNAME;\r\n            sortKey2 = Z.lu.LDAP_SURNAME;\r\n            sortKey3 = Z.lu.LDAP_PRIMARYKEY;\r\n        }\r\n        else if (\"id\".equalsIgnoreCase(sortBy)) {\r\n            sortKey1 = Z.lu.LDAP_PRIMARYKEY;\r\n            sortKey2 = Z.lu.LDAP_SURNAME;\r\n            sortKey3 = Z.lu.LDAP_GIVENNAME;\r\n        }\r\n    \r\n        HashMap nameVals = null;\r\n    \r\n        \/\/ Now Stepping through the search results\r\n        while (results.hasMoreElements())\r\n        {\r\n            nameVals = new HashMap();\r\n            SearchResult sr = (SearchResult) results.next();\r\n            Attributes attrs = sr.getAttributes();\r\n            HashMap hm = Z.lu.getLdapFields();\r\n            Iterator it = hm.keySet().iterator();\r\n    \r\n            while (it.hasNext())\r\n            {\r\n                String key = (String) hm.get((String)it.next());\r\n                \r\n                Attribute attr = attrs.get(key);\r\n                StringBuffer tmp = new StringBuffer();\r\n                \r\n                if (attr != null)\r\n                {\r\n                    NamingEnumeration nEnum = attr.getAll();\r\n                    int cnt = 0;\r\n                    tmp.setLength(0);\r\n                    \r\n                    while (nEnum.hasMoreElements()) {\r\n                        if (cnt++ &gt; 0) { tmp.append(\", \"); }\r\n                        tmp.append(((String) nEnum.next()).trim());\r\n                    }\r\n                }\r\n                \r\n                if (TextManager.isStringInvisible(tmp.toString()) ) {\r\n                    tmp = new StringBuffer(LdapUtil.NA);\r\n                }\r\n                if (Z.lu.LDAP_PRIMARYKEY.equals(key)) {\r\n                    nameVals.put(key,tmp.toString().toUpperCase());\r\n                } else {\r\n                    nameVals.put(key,tmp.toString());\r\n                }\r\n            }\r\n    \r\n            sortedResults.put(TextManager.catStrings((String)nameVals.get(sortKey1),\r\n                \" \", (String)nameVals.get(sortKey2),\r\n                \" \", (String)nameVals.get(sortKey3)), nameVals\r\n            );\r\n        }\r\n    \r\n        results.close();\r\n        ctx.close();\r\n        \r\n    } catch (javax.naming.PartialResultException pre) {\r\n        \/\/ Don't throw and exception here...this is for MS Active Server stuff\r\n        \/\/ throwing this exception probably because of a referral problem...\r\n        \/\/ but in any case the results are OK according to the data retrieved\r\n        Z.log.writeToLog(Z.log.WARN, \"Partial Result Exception: \" + pre.toString());\r\n        \r\n    } catch (Exception e) {\r\n        Z.log.writeToLog(Z.log.ERROR, \"UC: ldapSearch Exception: \" + e);\r\n        ErrorWriter.write(e, ErrorWriter.LOGERR);\r\n    }\r\n    \r\n    return sortedResults;\r\n}<\/code>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Purpose This method, when given a firstName, lastName, and userId, will search for and return user matches in place of a normal LDAP search. Applies To LDAP Signature public TreeMap ldapSearch(String firstName, String lastName, String userId, boolean exactMatch, String sortBy) Notes The exactMatch specifies if the match is exact, the sortBy can be by &#8220;last&#8221;,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":24510,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_lmt_disableupdate":"","_lmt_disable":"","_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"class_list":["post-24515","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ldapSearch - Product Documentation<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ldapSearch - Product Documentation\" \/>\n<meta property=\"og:description\" content=\"Purpose This method, when given a firstName, lastName, and userId, will search for and return user matches in place of a normal LDAP search. Applies To LDAP Signature public TreeMap ldapSearch(String firstName, String lastName, String userId, boolean exactMatch, String sortBy) Notes The exactMatch specifies if the match is exact, the sortBy can be by &#8220;last&#8221;,...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/\" \/>\n<meta property=\"og:site_name\" content=\"Product Documentation\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/\",\"url\":\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/\",\"name\":\"ldapSearch - Product Documentation\",\"isPartOf\":{\"@id\":\"https:\/\/docs.extraview.com\/v25\/#website\"},\"datePublished\":\"2024-02-15T22:53:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/docs.extraview.com\/v25\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ExtraView 25\",\"item\":\"https:\/\/docs.extraview.com\/v25\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"User Custom Guide\",\"item\":\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Java Interface\",\"item\":\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"User Custom Methods\",\"item\":\"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"ldapSearch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/docs.extraview.com\/v25\/#website\",\"url\":\"https:\/\/docs.extraview.com\/v25\/\",\"name\":\"ExtraView Product Documentation\",\"description\":\"ExtraView Documentation\",\"publisher\":{\"@id\":\"https:\/\/docs.extraview.com\/v25\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/docs.extraview.com\/v25\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/docs.extraview.com\/v25\/#organization\",\"name\":\"ExtraView Corporation\",\"url\":\"https:\/\/docs.extraview.com\/v25\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/docs.extraview.com\/v25\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/docs-stg.extraview.com\/wp-content\/uploads\/2024\/03\/favicon.png\",\"contentUrl\":\"https:\/\/docs-stg.extraview.com\/wp-content\/uploads\/2024\/03\/favicon.png\",\"width\":512,\"height\":512,\"caption\":\"ExtraView Corporation\"},\"image\":{\"@id\":\"https:\/\/docs.extraview.com\/v25\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ldapSearch - Product Documentation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/","og_locale":"en_US","og_type":"article","og_title":"ldapSearch - Product Documentation","og_description":"Purpose This method, when given a firstName, lastName, and userId, will search for and return user matches in place of a normal LDAP search. Applies To LDAP Signature public TreeMap ldapSearch(String firstName, String lastName, String userId, boolean exactMatch, String sortBy) Notes The exactMatch specifies if the match is exact, the sortBy can be by &#8220;last&#8221;,...","og_url":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/","og_site_name":"Product Documentation","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/","url":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/","name":"ldapSearch - Product Documentation","isPartOf":{"@id":"https:\/\/docs.extraview.com\/v25\/#website"},"datePublished":"2024-02-15T22:53:34+00:00","breadcrumb":{"@id":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/ldapsearch-1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/docs.extraview.com\/v25\/"},{"@type":"ListItem","position":2,"name":"ExtraView 25","item":"https:\/\/docs.extraview.com\/v25\/"},{"@type":"ListItem","position":3,"name":"User Custom Guide","item":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/"},{"@type":"ListItem","position":4,"name":"Java Interface","item":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/"},{"@type":"ListItem","position":5,"name":"User Custom Methods","item":"https:\/\/docs.extraview.com\/v25\/extraview-25\/user-custom-guide-1\/java-interface-1\/user-custom-methods-1\/"},{"@type":"ListItem","position":6,"name":"ldapSearch"}]},{"@type":"WebSite","@id":"https:\/\/docs.extraview.com\/v25\/#website","url":"https:\/\/docs.extraview.com\/v25\/","name":"ExtraView Product Documentation","description":"ExtraView Documentation","publisher":{"@id":"https:\/\/docs.extraview.com\/v25\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/docs.extraview.com\/v25\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/docs.extraview.com\/v25\/#organization","name":"ExtraView Corporation","url":"https:\/\/docs.extraview.com\/v25\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/docs.extraview.com\/v25\/#\/schema\/logo\/image\/","url":"https:\/\/docs-stg.extraview.com\/wp-content\/uploads\/2024\/03\/favicon.png","contentUrl":"https:\/\/docs-stg.extraview.com\/wp-content\/uploads\/2024\/03\/favicon.png","width":512,"height":512,"caption":"ExtraView Corporation"},"image":{"@id":"https:\/\/docs.extraview.com\/v25\/#\/schema\/logo\/image\/"}}]}},"taxonomy_info":[],"featured_image_src_large":false,"author_info":{"display_name":"carl.koppel","author_link":"https:\/\/docs.extraview.com\/v25\/author\/carl-koppel\/"},"comment_info":0,"_links":{"self":[{"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/pages\/24515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/comments?post=24515"}],"version-history":[{"count":0,"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/pages\/24515\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/pages\/24510"}],"wp:attachment":[{"href":"https:\/\/docs.extraview.com\/v25\/wp-json\/wp\/v2\/media?parent=24515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}