Hide last authors
gru 1.1 1 {{content/}}
2
gru 33.15 3 LDAP requests work similarly to [[database requests>>doc:Formcycle.UserInterface.Data.DBQueries]] and [[data sources>>doc:Sources]]. They can be used to retrieve data from an LDAP server dynamically.
4 If you need to filter the returned data, you can also add an appropriate LDAP filter.
gru 1.1 5
gru 33.15 6 == Creating an LDAP query ==
gru 1.1 7
nlo 17.1 8 {{id name="fig_data_ldap_query"/}}
gru 33.15 9 {{figure image="data_ldap_query_en.png"}}Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query{{/figure}}
nlo 17.1 10
awa 32.2 11
12 {{html wiki="true"}}
gru 33.15 13 <div class='xm-figure xm-float-right xm-clear-h2' data-alt='Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query'><div class='xm-figure-inner' style='width:310px'>{{lightbox image='data_ldap_query_en.png' width='300' group='$height' group='$group' title='Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query'/}}<div class='xm-figure-caption'>Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query</div></div></div>
awa 32.2 14 {{/html}}
15
16
sas 32.8 17
18 {{html wiki="true"}}
gru 33.15 19 <div class='xm-figure xm-float-right xm-clear-h2' data-alt='Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query'><div class='xm-figure-inner' style='width:310px'>{{lightbox image='data_ldap_query_en.png' width='300' group='$height' group='$group' title='Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query'/}}<div class='xm-figure-caption'>Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query</div></div></div>
sas 32.8 20 {{/html}}
21
22
23
24 {{html wiki="true"}}
gru 33.15 25 <div class='xm-figure xm-float-right xm-clear-h2' data-alt='Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query'><div class='xm-figure-inner' style='width:310px'>{{lightbox image='data_ldap_query_en.png' width='300' group='$height' group='$group' title='Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query'/}}<div class='xm-figure-caption'>Configuration screen for creating LDAP queries: (1) list of existing LDAP queries, (2) editor for defining the query, (3) settings panel of the query, (4) attribute filters for the query, (5) Generated servlet URL for using the LDAP query, (6) console for testing the query</div></div></div>
sas 32.8 26 {{/html}}
27
28
gru 33.15 29 * Open the module "LDAP queries" and click "New" {{ficon name="plus-circle-outline"/}} in the header of the list (see point 1 in [[figure>>||anchor="fig_data_ldap_query"]]).
30 * Provide a name for the LDAP query, and optionally a description.
31 * Select the LDAP connection to use; either [[client>>doc:Formcycle.UserInterface.Client.WebHome]]'s LDAP connection or another custom [[LDAP connection>>doc:LDAPConnections]].
32 * Enter the base DN (distinguished name) for the query. This is the root path for the LDAP search.
33 * Enter the LDAP query with the //LDAP// filter syntax in the editor, [[see here for a tutorial>>url:http://www.selfadsi.de/ldap-filter.htm#FilterDef||rel="__blank"]]). You may also use placeholders (question mark, {{code language="none"}}?{{/code}}) that will be replaced with the values from a GET HTTP request for this LDAP query (see point 2 in [[figure>>||anchor="fig_data_ldap_query"]]).
34 * Optionally, enter a list of attributes. The query will return only those attributes, filtered on the server. When no parameters are specified, all attributes will be returned (see point 4 in [[figure>>||anchor="fig_data_ldap_query"]]).
sas 33.1 35
gru 33.15 36 == Using LDAP queries ==
sas 33.1 37
gru 33.15 38 LDAP queries can also be accessed via a GET HTTP request. This allows you to access LDAP queries via JavaScript. The URL endpoint is:
sas 33.1 39
gru 32.5 40 {{code language="none"}}
gru 1.1 41 http://<server>/formcycle/datenabfrageldap
42 {{/code}}
43
gru 33.15 44 The servlet URL will be displayed beneath the attribute filters (see point 5 in [[figure>>||anchor="fig_data_ldap_query"]]).
45 The following URL parameters are available:
gru 1.1 46
47 {{table dataTypeAlpha="0" preSort="0-asc"}}
gru 33.15 48 |=Name of the parameter|=Description|=Required
49 |name|The name of the LDAP request.|Yes
50 |mandantName|The name of the client who owns this LDAP query.|Yes, when //projektId// was not specified.
51 |projektId|The ID of the form. The form ID can be accessed via the JavaScript object {{code language="none"}}window.XFC_METADATA.currentProject.id{{/code}}.|Yes, when //mandantName// was not specified.
52 |queryParameter|When the LDAP query contains placeholders (question marks, {{code language="none"}}?{{/code}}), a list of parameters must be supplied for each placeholder. The items are separated with the delimiter as defined by the URL parameter //delimiter//.
gru 33.13 53
gru 33.15 54 If possible the parameter //queryParameterValues// should be used for new projects instead of //queryParameter// because //queryParameter// will not be supported in a future version of {{formcycle/}}.|No
55 |queryParameterValues|{{version major="6" minor="6" patch="3"/}}Starting with {{formcycle/}} Version 6.6.3 this parameter can be used as an alternative to the parameters //queryParameter// and //delimiter//. Like these parameters, //queryParameterValues// is only required if placeholders in the form of a question mark {{code language="none"}}?{{/code}} are used within the LDAP query. If this is the case, the individual query parameters are passed one after the other as a separate parameter //queryParameterValues//, which also eliminates the use of the parameter //delimiter//.|No
56 |delimiter|The delimiter for the placeholder values, see //queryParameter//. Defaults to a comma {{code language="none"}},{{/code}}
gru 33.13 57
gru 33.15 58 If possible the parameter //queryParameterValues// should be used for new projects instead of //delimiter// and //queryParameter// because //delimiter// will not be supported in a future version of {{formcycle/}}.|No
gru 1.1 59 {{/table}}
60
gru 33.15 61 When you want to initiate an LDAP query from a form via JavaScript, use the URL provided by the JavaScript object {{jsdoc page="metadata" name="urls"}}XFC_METADATA.urls{{/jsdoc}}. The LDAP query URL can be accessed via {{code language="javascript"}}window.XFC_METADATA.urls.datasource_ldap{{/code}}.
gru 1.1 62
gru 33.15 63 The LDAP queries returns a JSON object that can be parsed with {{code language="javascript"}}JSON.parse(...){{/code}}
gru 1.1 64
gru 33.15 65 == Testing the query ==
nlo 18.2 66
67 {{info}}
gru 33.15 68 For quick testing of the query the shortcut {{code language="none"}}Ctrl + Enter{{/code}} is provided.
nlo 18.2 69 {{/info}}
70
gru 33.15 71 LDAP queries can be tested directly from the configuration UI. For this purpose a test console is provided below the editor (see point 6 in [[figure>>||anchor="fig_data_db_query"]]).
72 In the header of the console there is a row of buttons for controling the query:
nlo 18.2 73
gru 33.15 74 * {{ficon name="database-search"/}}**Perform query**
75 Runs the LDAP query. If //query parameters// ({{code language="none"}}?{{/code}}) are provided the user will be prompted to input values vor those parameters. Otherwise the result of the query will be displayed directly in the //source code view//.{{lightbox image="data_ldap_query_test_en.png" title="Run the given query"/}}
76 * {{icon name="question"/}}**Query parameters**
77 Mask for inputting values for query parameters. This option is only available if query parameters ({{code language="none"}}?{{/code}}) are used in the LDAP query. The individual parameters will be enumerated in the query statement. Clicking "User parameters for query" {{ficon name="arrow-right-bold-circle-outline2"/}} executes the query with the given parameters. The result will be displayed in the //source code view//.
78 {{lightbox image="data_ldap_query_test_param_en.png" title="Query parameters are enumerated"/}}
79 Actual Query in the editor:{{lightbox image="data_ldap_query_example.png" title="Example query"/}}
80 * {{icon name="code"/}}**Source code view**
81 Query result in JSON format{{lightbox image="data_ldap_query_test_code_en.png" title="Query result in JSON format"/}}
82 * {{icon name="Terminal"/}}**Generated LDAP Query**
83 Displays the generated LDAP statement with input parameter values{{lightbox image="data_ldap_query_test_gen_en.png" title="Displays the generated LDAP statement with input parameter values"/}}
nlo 18.2 84
gru 33.15 85 == Examples for LDAP queries ==
gru 1.1 86
gru 33.15 87 The following shows how to retrieve the result of an LDAP query via an HTTP request.
gru 1.1 88
gru 33.15 89 Assuming an LDAP query has been created already and was named //MyQuery//.
gru 1.1 90
gru 32.5 91 {{code language="none"}}
gru 1.1 92 ((distinguishedName=?,?)
93 {{/code}}
94
gru 33.15 95 You need to provide two values for the the two placeholders (question marks). Send a GET request to the following URL to perform the LDAP query:
gru 1.1 96
gru 32.5 97 {{code language="none"}}
gru 33.15 98 http://<server>/formcycle/datenabfrageldap?name=MyQuery&mandantName=MyClient&queryParameterValues=Value,1&queryParameterValues=Value,2
gru 1.1 99 {{/code}}
100
gru 33.15 101 {{version major="6" minor="6" patch="3"/}}Starting with {{formcycle/}} Version 6.6.3, the same LDAP query can also be perform with the following URL, which is recommended for new projects:
gru 33.12 102
103 {{code language="none"}}
104 http://<server>/formcycle/datenabfrageldap?name=MeineAbfrage&mandantName=MeinMandant&queryParameterValues=Wert,1&queryParameterValues=Wert,2
105 {{/code}}
106
gru 33.15 107 Within a form, the following function can be used to perform the LDAP query via an asynchronous HTTP request:
gru 1.1 108
109 {{code language="javascript"}}
gru 33.15 110 $.xutil.getLdapQuery("MyQuery", ["Value1", "Value2"])
awa 33.8 111 .then(function(data) {
gru 33.15 112 // Callback function that is invoked once the request succeeds
113 // The variable "data" now contains the returned entries from the active directory
114 console.log(data.length, "entries found");
awa 33.8 115 })
116 .catch(function(xhr, statusMessage, statusCode) {
gru 33.15 117 console.log("Request failed:", statusMessage, statusCode);
118 // Add appropriate error handling...
awa 33.8 119 });
awa 33.2 120 {{/code}}
121
gru 33.15 122 Before {{formcycle/}} version 6.6.3, a comma was always used as the separator for the query parameters in the code shown above. If you need to use a different separator for {{formcycle/}}} versions prior to 6.6.3, the AJAX request has to be started manually:
awa 33.2 123
124 {{code language="javascript"}}
gru 1.1 125 function ldapQuery(name, queryParameter, delimiter, callback) {
126 $.ajax({
127 url: XFC_METADATA.urls.dataquery_ldap,
awa 33.2 128 method: 'GET',
gru 1.1 129 async: true,
130 cache: false,
131 dataType: 'json',
132 data: {
133 name: name,
134 mandantName: XFC_METADATA.currentClient.name,
135 queryParameter: queryParameter,
136 delimiter: delimiter || ','
137 }
awa 33.6 138 }).then(callback);
gru 1.1 139 }
awa 33.2 140
gru 33.15 141 ldapQuery("MyQuery", "Value,1;Value,2", ";", function(data) {
142 // Process returned data...
awa 33.2 143 });
gru 1.1 144 {{/code}}
Copyright 2000-2024