Show last authors
1 {{content/}}
2
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.
5
6 == Creating an LDAP query ==
7
8 {{id name="fig_data_ldap_query"/}}
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}}
10
11
12 {{html wiki="true"}}
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>
14 {{/html}}
15
16
17
18 {{html wiki="true"}}
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>
20 {{/html}}
21
22
23
24 {{html wiki="true"}}
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>
26 {{/html}}
27
28
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"]]).
35
36 == Using LDAP queries ==
37
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:
39
40 {{code language="none"}}
41 http://<server>/formcycle/datenabfrageldap
42 {{/code}}
43
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:
46
47 {{table dataTypeAlpha="0" preSort="0-asc"}}
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//.
53
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}}
57
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
59 {{/table}}
60
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}}.
62
63 The LDAP queries returns a JSON object that can be parsed with {{code language="javascript"}}JSON.parse(...){{/code}}
64
65 == Testing the query ==
66
67 {{info}}
68 For quick testing of the query the shortcut {{code language="none"}}Ctrl + Enter{{/code}} is provided.
69 {{/info}}
70
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:
73
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"/}}
84
85 == Examples for LDAP queries ==
86
87 The following shows how to retrieve the result of an LDAP query via an HTTP request.
88
89 Assuming an LDAP query has been created already and was named //MyQuery//.
90
91 {{code language="none"}}
92 ((distinguishedName=?,?)
93 {{/code}}
94
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:
96
97 {{code language="none"}}
98 http://<server>/formcycle/datenabfrageldap?name=MyQuery&mandantName=MyClient&queryParameterValues=Value,1&queryParameterValues=Value,2
99 {{/code}}
100
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:
102
103 {{code language="none"}}
104 http://<server>/formcycle/datenabfrageldap?name=MeineAbfrage&mandantName=MeinMandant&queryParameterValues=Wert,1&queryParameterValues=Wert,2
105 {{/code}}
106
107 Within a form, the following function can be used to perform the LDAP query via an asynchronous HTTP request:
108
109 {{code language="javascript"}}
110 $.xutil.getLdapQuery("MyQuery", ["Value1", "Value2"])
111 .then(function(data) {
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");
115 })
116 .catch(function(xhr, statusMessage, statusCode) {
117 console.log("Request failed:", statusMessage, statusCode);
118 // Add appropriate error handling...
119 });
120 {{/code}}
121
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:
123
124 {{code language="javascript"}}
125 function ldapQuery(name, queryParameter, delimiter, callback) {
126 $.ajax({
127 url: XFC_METADATA.urls.dataquery_ldap,
128 method: 'GET',
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 }
138 }).then(callback);
139 }
140
141 ldapQuery("MyQuery", "Value,1;Value,2", ";", function(data) {
142 // Process returned data...
143 });
144 {{/code}}
Copyright 2000-2024