Wiki source code of LDAP-Abfragen


Hide last authors
gru 1.1 1 {{content/}}
2
Release Notes 13.1 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
Release Notes 13.1 6 == Creating an LDAP query ==
gru 1.1 7
8 {{id name="fig_data_ldap_query"/}}
Release Notes 13.1 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}}
gru 1.1 10
Release Notes 13.1 11 * 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"]]).
12 * Provide a name for the LDAP query, and optionally a description.
13 * Select the LDAP connection to use; either [[client>>doc:Formcycle.UserInterface.Client.WebHome]]'s LDAP connection or another custom [[LDAP connection>>doc:LDAPConnections]].
14 * Enter the base DN (distinguished name) for the query. This is the root path for the LDAP search.
15 * 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"]]).
16 * 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"]]).
gru 1.1 17
Release Notes 13.1 18 == Using LDAP queries ==
gru 1.1 19
Release Notes 13.1 20 LDAP queries can also be accessed via a GET HTTP request. This allows you to access LDAP queries via JavaScript. The URL endpoint is:
gru 1.1 21
22 {{code language="none"}}
23 http://<server>/formcycle/datenabfrageldap
24 {{/code}}
25
Release Notes 13.1 26 The servlet URL will be displayed beneath the attribute filters (see point 5 in [[figure>>||anchor="fig_data_ldap_query"]]).
27 The following URL parameters are available:
gru 1.1 28
29 {{table dataTypeAlpha="0" preSort="0-asc"}}
Release Notes 13.1 30 |=Name of the parameter|=Description|=Required
31 |name|The name of the LDAP request.|Yes
32 |mandantName|The name of the client who owns this LDAP query.|Yes, when //projektId// was not specified.
33 |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.
34 |queryParameterValues|//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
35 |delimiter|The delimiter for the placeholder values, see //queryParameter//. Defaults to a comma {{code language="none"}},{{/code}}
36 |jsonPath {{version major="7" minor="3"/}}|This parameter allows specifying a JSON path expression which will be applied to the returned result of the query on the server side. The example //$.returnValue[0]// returns the values of the first result of the query.|No
37
38 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 39 {{/table}}
40
Release Notes 13.1 41 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 42
Release Notes 13.1 43 The LDAP queries returns a JSON object that can be parsed with {{code language="javascript"}}JSON.parse(...){{/code}}
gru 1.1 44
Release Notes 13.1 45 == Testing the query ==
gru 1.1 46
47 {{info}}
Release Notes 13.1 48 For quick testing of the query the shortcut {{code language="none"}}Ctrl + Enter{{/code}} is provided.
gru 1.1 49 {{/info}}
50
Release Notes 13.1 51 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"]]).
52 In the header of the console there is a row of buttons for controling the query:
gru 1.1 53
Release Notes 13.1 54 * {{ficon name="database-search"/}}**Perform query**
55 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"/}}
56 * {{icon name="question"/}}**Query parameters**
57 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//.
58 {{lightbox image="data_ldap_query_test_param_en.png" title="Query parameters are enumerated"/}}
59 Actual Query in the editor:{{lightbox image="data_ldap_query_example.png" title="Example query"/}}
60 * {{icon name="code"/}}**Source code view**
61 Query result in JSON format{{lightbox image="data_ldap_query_test_code_en.png" title="Query result in JSON format"/}}
62 * {{icon name="Terminal"/}}**Generated LDAP Query**
63 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"/}}
gru 1.1 64
Release Notes 13.1 65 == Examples for LDAP queries ==
gru 1.1 66
Release Notes 13.1 67 The following shows how to retrieve the result of an LDAP query via an HTTP request.
gru 1.1 68
Release Notes 13.1 69 Assuming an LDAP query has been created already and was named //MyQuery//.
gru 1.1 70
71 {{code language="none"}}
72 ((distinguishedName=?,?)
73 {{/code}}
74
Release Notes 13.1 75 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 76
77 {{code language="none"}}
78 http://<server>/formcycle/datenabfrageldap?name=MeineAbfrage&mandantName=MeinMandant&queryParameterValues=Wert,1&queryParameterValues=Wert,2
79 {{/code}}
80
Release Notes 13.1 81 Within a form, the following function can be used to perform the LDAP query via an asynchronous HTTP request:
gru 1.1 82
83 {{code language="javascript"}}
Release Notes 13.1 84 $.xutil.getLdapQuery("MyQuery", ["Value1", "Value2"])
gru 1.1 85 .then(function(data) {
Release Notes 13.1 86 // Callback function that is invoked once the request succeeds
87 // The variable "data" now contains the returned entries from the active directory
88 console.log(data.length, "entries found");
gru 1.1 89 })
90 .catch(function(xhr, statusMessage, statusCode) {
Release Notes 13.1 91 console.log("Request failed:", statusMessage, statusCode);
92 // Add appropriate error handling...
gru 1.1 93 });
94 {{/code}}
95
Release Notes 13.1 96 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:
gru 1.1 97
98 {{code language="javascript"}}
99 function ldapQuery(name, queryParameter, delimiter, callback) {
100 $.ajax({
101 url: XFC_METADATA.urls.dataquery_ldap,
102 method: 'GET',
103 async: true,
104 cache: false,
105 dataType: 'json',
106 data: {
107 name: name,
108 mandantName: XFC_METADATA.currentClient.name,
109 queryParameter: queryParameter,
110 delimiter: delimiter || ','
111 }
112 }).then(callback);
113 }
114
Release Notes 13.1 115 ldapQuery("MyQuery", "Value,1;Value,2", ";", function(data) {
116 // Process returned data...
gru 1.1 117 });
118 {{/code}}