LDAP requests work similarly to database requests and data sources. They can be used to retrieve data from an LDAP server dynamically.
If you need to filter the returned data, you can also add an appropriate LDAP filter.

Creating an LDAP query


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

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
  • Open the module "LDAP queries" and click "New" in the header of the list (see point 1 in figure).
  • Provide a name for the LDAP query, and optionally a description.
  • Select the LDAP connection to use; either client's LDAP connection or another custom LDAP connection.
  • Enter the base DN (distinguished name) for the query. This is the root path for the LDAP search.
  • Enter the LDAP query with the LDAP filter syntax in the editor, see here for a tutorial). You may also use placeholders (question mark, ?) that will be replaced with the values from a GET HTTP request for this LDAP query (see point 2 in figure).
  • 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).

Using LDAP queries

LDAP queries can also be accessed via a GET HTTP request. This allows you to access LDAP queries via JavaScript. The URL endpoint is:

http://<server>/formcycle/datenabfrageldap

The servlet URL will be displayed beneath the attribute filters (see point 5 in figure).
The following URL parameters are available:

Name of the parameterDescriptionRequired
nameThe name of the LDAP request.Yes
mandantNameThe name of the client who owns this LDAP query.Yes, when projektId was not specified.
projektIdThe ID of the form. The form ID can be accessed via the JavaScript object window.XFC_METADATA.currentProject.id.Yes, when mandantName was not specified.
queryParameterWhen the LDAP query contains placeholders (question marks, ?), a list of parameters must be supplied for each placeholder. The items are separated with the delimiter as defined by the URL parameter delimiter.No
delimiterThe delimiter for the placeholder values, see queryParameter. Defaults to a comma ,No

When you want to initiate an LDAP query from a form via JavaScript, use the URL provided by the JavaScript object XFC_METADATA.urls. The LDAP query URL can be accessed via window.XFC_METADATA.urls.datasource_ldap.

The LDAP queries returns a JSON object that can be parsed with JSON.parse(...)

Testing the query

For quick testing of the query the shortcut Ctrl + Enter is provided.

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).
In the header of the console there is a row of buttons for controling the query:

  • Perform query
    Runs the LDAP query. If query parameters (?) 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.

  •  Query parameters
    Mask for inputting values for query parameters. This option is only available if query parameters (?) are used in the LDAP query. The individual parameters will be enumerated in the query statement. Clicking "User parameters for query" executes the query with the given parameters. The result will be displayed in the source code view.


    Actual Query in the editor:

  •  Source code view
    Query result in JSON format

  •  Generated LDAP Query
    Displays the generated LDAP statement with input parameter values

Examples for LDAP queries

The following shows how to retrieve the result of an LDAP query via an HTTP request. The demo pages also include an example illustrating how to setup a select element with the result of an LDAP query.

Assuming an LDAP query has been created already and was named MyQuery.

((distinguishedName=?,?)

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:

http://<server>/formcycle/datenabfrageldap?name=MyQuery&mandantName=MyClient&queryParameter=Value,1;Value,2&delimiter=;

Within a form, the following code can be used to perform the LDAP query via an asynchronous HTTP request:

function ldapQuery(name, queryParameter, delimiter, callback) {
    $.ajax({
        url: XFC_METADATA.urls.dataquery_ldap,
        method: 'GET',
        async: true,
        cache: false,
        dataType: 'json',
        data: {
            name: name,
            mandantName: XFC_METADATA.currentClient.name,
            queryParameter: queryParameter,
            delimiter: delimiter || ','
        }
    }).success(callback);
}
Tags:
Copyright 2000-2024