reviewboard.accounts.backends¶
-
class
AuthBackend
[source]¶ Bases:
object
The base class for Review Board authentication backends.
-
authenticate
(username, password)[source]¶ Authenticate the user.
This will authenticate the username and return the appropriate User object, or None.
-
get_or_create_user
(username, request)[source]¶ Get an existing user, or create one if it does not exist.
-
update_password
(user, password)[source]¶ Update the userâs password on the backend.
Authentication backends can override this to update the password on the backend. This will only be called if
supports_change_password
isTrue
.By default, this will raise NotImplementedError.
-
update_name
(user)[source]¶ Update the userâs name on the backend.
The first name and last name will already be stored in the provided
user
object.Authentication backends can override this to update the name on the backend based on the values in
user
. This will only be called ifsupports_change_name
isTrue
.By default, this will do nothing.
-
update_email
(user)[source]¶ Update the userâs e-mail address on the backend.
The e-mail address will already be stored in the provided
user
object.Authentication backends can override this to update the e-mail address on the backend based on the values in
user
. This will only be called ifsupports_change_email
isTrue
.By default, this will do nothing.
-
query_users
(query, request)[source]¶ Search for users on the back end.
This call is executed when the User List web API resource is called, before the database is queried.
Authentication backends can override this to perform an external query. Results should be written to the database as standard Review Board users, which will be matched and returned by the web API call.
The
query
parameter contains the value of theq
search parameter of the web API call (e.g. /users/?q=foo), if any.Errors can be passed up to the web API layer by raising a reviewboard.accounts.errors.UserQueryError exception.
By default, this will do nothing.
-
search_users
(query, request)[source]¶ Custom user-database search.
This call is executed when the User List web API resource is called and the
q
search parameter is provided, indicating a search query.It must return either a django.db.models.Q object or None. All enabled backends are called until a Q object is returned. If one isnât returned, a default search is executed.
-
-
class
StandardAuthBackend
[source]¶ Bases:
reviewboard.accounts.backends.AuthBackend
,django.contrib.auth.backends.ModelBackend
Authenticate users against the local database.
This will authenticate a user against their entry in the database, if the user has a local password stored. This is the default form of authentication in Review Board.
This backend also handles permission checking for users on LocalSites. In Django, this is the responsibility of at least one auth backend in the list of configured backends.
Regardless of the specific type of authentication chosen for the installation, StandardAuthBackend will always be provided in the list of configured backends. Because of this, it will always be able to handle authentication against locally added users and handle LocalSite-based permissions for all configurations.
-
authenticate
(username, password)[source]¶ Authenticate the user.
This will authenticate the username and return the appropriate User object, or None.
-
get_or_create_user
(username, request)[source]¶ Get an existing user, or create one if it does not exist.
-
get_all_permissions
(user, obj=None)[source]¶ Get a list of all permissions for a user.
If a LocalSite instance is passed as
obj
, then the permissions returned will be those that the user has on that LocalSite. Otherwise, they will be their global permissions.It is not legal to pass any other object.
-
has_perm
(user, perm, obj=None)[source]¶ Get whether or not a user has the given permission.
If a LocalSite instance is passed as
obj
, then the permissions checked will be those that the user has on that LocalSite. Otherwise, they will be their global permissions.It is not legal to pass any other object.
-
-
class
HTTPDigestBackend
[source]¶ Bases:
reviewboard.accounts.backends.AuthBackend
Authenticate against a user in a digest password file.
-
class
NISBackend
[source]¶ Bases:
reviewboard.accounts.backends.AuthBackend
Authenticate against a user on an NIS server.
-
class
LDAPBackend
[source]¶ Bases:
reviewboard.accounts.backends.AuthBackend
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:
LDAP_ANON_BIND_UID
: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.
LDAP_ANON_BIND_PASSWD
:- The password used for the account specified in
LDAP_ANON_BIND_UID
. 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.
LDAP_BASE_DN
:- The base DN (distinguished name) used to perform LDAP searches.
LDAP_EMAIL_ATTRIBUTE
:- 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. LDAP_EMAIL_DOMAIN
:- 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 overLDAP_EMAIL_ATTRIBUTE
. LDAP_GIVEN_NAME_ATTRIBUTE
:- The attribute designating the given name (or first name) of a user
in the directory. This defaults to
givenName
if not provided. LDAP_SURNAME_ATTRIBUTE
:- The attribute designating the surname (or last name) of a user in the
directory. This defaults to
sn
if not provided. LDAP_TLS
:- Whether to use TLS to communicate with the LDAP server.
LDAP_UID
:- 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)
. LDAP_UID_MASK
:- 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)
. LDAP_URI
:- The URI to the LDAP server to connect to for all communication.
-
authenticate
(username, password)[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.Parameters: Returns: The resulting user, if authentication was successful. If unsuccessful,
None
is returned.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.
Parameters: - 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.
Returns: The resulting user, if it could be found either locally or in LDAP. If the user does not exist,
None
is returned.Return type:
-
class
ActiveDirectoryBackend
[source]¶ Bases:
reviewboard.accounts.backends.AuthBackend
Authenticate a user against an Active Directory server.
-
get_ldap_search_root
(userdomain=None)[source]¶ Return the search root(s) for users in the LDAP server.
-
find_domain_controllers_from_dns
(userdomain=None)[source]¶ Find and return the active domain controllers using DNS.
-
get_member_of
(con, search_results, seen=None, depth=0)[source]¶ Get the LDAP groups for the given users.
This iterates over the users specified in
search_results
and returns a set of groups of which those users are members.
-
get_ldap_connections
(userdomain=None)[source]¶ Get a set of connections to LDAP servers.
This returns an iterable of connections to the LDAP servers specified in AD_DOMAIN_CONTROLLER.
-
-
class
X509Backend
[source]¶ Bases:
reviewboard.accounts.backends.AuthBackend
Authenticate a user from a X.509 client certificate.
The certificate is passed in by the browser. This backend relies on the X509AuthMiddleware to extract a username field from the client certificate.
-
authenticate
(x509_field=uâ)[source]¶ Authenticate the user.
This will extract the username from the provided certificate and return the appropriate User object.
-
-
get_registered_auth_backends
()[source]¶ Return all registered Review Board authentication backends.
This will return all backends provided both by Review Board and by third parties that have properly registered with the âreviewboard.auth_backendsâ entry point.
-
get_registered_auth_backend
(backend_id)[source]¶ Return the authentication backends with the specified ID.
If the authentication backend could not be found, this will return None.
-
register_auth_backend
(backend_cls)[source]¶ Register an authentication backend.
This backend will appear in the list of available backends.
The backend class must have a backend_id attribute set, and can only be registerd once. A KeyError will be thrown if attempting to register a second time.
-
unregister_auth_backend
(backend_cls)[source]¶ Unregister a previously registered authentication backend.