Jump to >


LDAP authentication backend.

class LDAPBackend[source]

Bases: reviewboard.accounts.backends.base.BaseAuthBackend

Authentication backend for LDAP servers.

This allows the use of LDAP servers for authenticating users in Review Board, and for importing individual users on-demand. It allows for a lot of customization in terms of how the LDAP server is queried, providing compatibility with most open source and commercial LDAP servers.

The following Django settings are supported:


The full DN (distinguished name) of a user account with sufficient access to perform lookups of users and groups in the LDAP server. This is treated as a general or “anonymous” user for servers requiring authentication, and will not be otherwise imported into the Review Board server (unless attempting to log in with the same name).

This can be unset if the LDAP server supports actual anonymous binds without a DN.


The password used for the account specified in LDAP_ANON_BIND_UID.


The full distinguished name of a user account with sufficient access to perform lookups of users and groups in the LDAP server. This can be unset if the LDAP server supports anonymous binds.


The base DN (distinguished name) used to perform LDAP searches.


The attribute designating the e-mail address of a user in the directory. E-mail attributes are only used if this is set and if LDAP_EMAIL_DOMAIN is not set.


The domain name to use for e-mail addresses. If set, users imported from LDAP will have an e-mail address in the form of username@LDAP_EMAIL_DOMAIN. This takes priority over LDAP_EMAIL_ATTRIBUTE.


The attribute designating the given name (or first name) of a user in the directory. This defaults to givenName if not provided.


The attribute designating the surname (or last name) of a user in the directory. This defaults to sn if not provided.


Whether to use TLS to communicate with the LDAP server.


The attribute indicating a user’s unique ID in the directory. This is used to compute a user lookup filter in the format of (LDAP_UID=username).


A mask defining a filter for looking up users. This must contain %s somewhere in the string, representing the username. For example: (something_special=%s).


The URI to the LDAP server to connect to for all communication.

backend_id = 'ldap'[source]

The unique ID for the authentication backend.

name = 'LDAP'[source]

The display name for the authentication backend.

This will be shown in the list of backends in the administration UI.


alias of reviewboard.accounts.forms.auth.LDAPSettingsForm

login_instructions = 'Use your standard LDAP username and password.'[source]

Authentication instructions to display above the Login form.

authenticate(request, username, password, **kwargs)[source]

Authenticate a user.

This will attempt to authenticate the user against the LDAP server. If the username and password are valid, a user will be returned, and added to the database if it doesn’t already exist.

Changed in version 4.0: The request argument is now mandatory as the first positional argument, as per requirements in Django.

  • request (django.http.HttpRequest) – The HTTP request from the caller. This may be None.

  • username (unicode) – The username used to authenticate.

  • password (unicode) – The password used to authenticate.

  • **kwargs (dict, unused) – Additional keyword arguments supplied by the caller.


The authenticated user, or None if the user could not be authenticated for any reason.

Return type


get_or_create_user(username, request=None, ldapo=None, userdn=None)[source]

Return a user account, importing from LDAP if necessary.

If the user already exists in the database, it will be returned directly. Otherwise, this will attempt to look up the user in LDAP and create a local user account representing that user.

  • username (unicode) – The username to look up.

  • request (django.http.HttpRequest, optional) – The optional HTTP request for this operation.

  • ldapo (ldap.LDAPObject, optional) – The existing LDAP connection, if the caller has one. If not provided, a new connection will be created.

  • userdn (unicode, optional) – The DN for the user being looked up, if the caller knows it. If not provided, the DN will be looked up.


The resulting user, if it could be found either locally or in LDAP. If the user does not exist, None is returned.

Return type


__annotations__ = {}