1 # Copyright (C) 2012 Oregon State University
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 # LDAP Authentication via django-auth-ldap
19 # http://packages.python.org/django-auth-ldap/#reference
21 from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
24 # If you need to debug your configuration, see:
25 # http://packages.python.org/django-auth-ldap/#logging
27 logger = logging.getLogger('django_auth_ldap')
28 logger.addHandler(logging.StreamHandler())
29 logger.setLevel(logging.WARN)
32 'AUTH_LDAP_SERVER_URI',
34 'AUTH_LDAP_BIND_PASSWORD',
35 'AUTH_LDAP_USER_SEARCH',
36 'AUTH_LDAP_GROUP_SEARCH',
37 'AUTH_LDAP_USER_ATTR_MAP',
38 'AUTH_LDAP_GROUP_TYPE',
39 'AUTH_LDAP_USER_FLAGS_BY_GROUP',
40 'AUTH_LDAP_BIND_AS_AUTHENTICATING_USER',
41 'AUTH_LDAP_REQUIRE_GROUP',
42 'AUTH_LDAP_DENY_GROUP',
45 # The URI of the LDAP server. This can be any URI that is supported by
46 # your underlying LDAP libraries.
47 # Default: ldap://localhost
48 AUTH_LDAP_SERVER_URI = 'ldap://localhost'
50 # A dictionary of options to pass to each connection to the LDAP server
51 # via LDAPObject.set_option(). Keys are ldap.OPT_* constants.
53 #AUTH_LDAP_CONNECTION_OPTIONS = {}
55 # A dictionary of options to pass to ldap.set_option(). Keys are
56 # ldap.OPT_* constants.
58 #AUTH_LDAP_GLOBAL_OPTIONS = {}
60 # If True, authentication will leave the LDAP connection bound as the
61 # authenticating user, rather than forcing it to re-bind with the
62 # default credentials after authentication succeeds. This may be
63 # desirable if you do not have global credentials that are able to
64 # access the user's attributes. django-auth-ldap never stores the user's
65 # password, so this only applies to requests where the user is
66 # authenticated. Thus, the downside to this setting is that LDAP results
67 # may vary based on whether the user was authenticated earlier in the
68 # Django view, which could be surprising to code not directly concerned
69 # with authentication.
71 AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = False
73 # The distinguished name to use when binding to the LDAP server (with
74 # AUTH_LDAP_BIND_PASSWORD). Use the empty string (the default) for an
75 # anonymous bind. To authenticate a user, we will bind with that user's
76 # DN and password, but for all other LDAP operations, we will be bound
77 # as the DN in this setting. For example, if AUTH_LDAP_USER_DN_TEMPLATE
78 # is not set, we'll use this to search for the user. If
79 # AUTH_LDAP_FIND_GROUP_PERMS is True, we'll also use it to determine
81 # Default = '' (Empty string)
82 AUTH_LDAP_BIND_DN = ''
84 # The password to use with AUTH_LDAP_BIND_DN.
85 # Default: '' (Empty string)
86 AUTH_LDAP_BIND_PASSWORD = ''
88 # A string template that describes any user's distinguished name based on
89 # the username. This must contain the placeholder %(user)s.
91 #AUTH_LDAP_USER_DN_TEMPLATE = None
93 # An LDAPSearch object that will locate a user in the directory. The
94 # filter parameter should contain the placeholder %(user)s for the
95 # username. It must return exactly one result for authentication to
98 AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=People,dc=example,dc=org",
99 ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
101 # A mapping from user profile field names to LDAP attribute names. A
102 # user's profile will be populated from his LDAP attributes at login.
104 #AUTH_LDAP_PROFILE_ATTR_MAP = {}
106 # A mapping from User field names to LDAP attribute names. A users's User
107 # object will be populated from his LDAP attributes at login.
109 AUTH_LDAP_USER_ATTR_MAP = {
110 "fist_name": "givenName",
115 # An LDAPSearch object that finds all LDAP groups that users might
116 # belong to. If your configuration makes any references to LDAP groups,
117 # this and AUTH_LDAP_GROUP_TYPE must be set.
119 AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=Group,dc=example,dc=org",
121 "(objectClass=groupOfNames)")
123 # An LDAPGroupType instance describing the type of group returned by
124 # AUTH_LDAP_GROUP_SEARCH.
126 AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
128 # A mapping from boolean User field names to distinguished names of LDAP
129 # groups. The corresponding field is set to True or False according to
130 # whether the user is a member of the group.
132 AUTH_LDAP_USER_FLAGS_BY_GROUP = {
133 "is_active": "cn=group1,ou=Group,dc=example,dc=org",
134 "is_staff": "cn=group2,ou=Group,dc=example,dc=org",
135 "is_superuser": "cn=group3,ou=Group,dc=example,dc=org",
138 # If True, each connection to the LDAP server will call start_tls to
139 # enable TLS encryption over the standard LDAP port. There are a number of
140 # configuration options that can be given to AUTH_LDAP_GLOBAL_OPTIONS that
141 # affect the TLS connection. For example, ldap.OPT_X_TLS_REQUIRE_CERT can
142 # be set to ldap.OPT_X_TLS_NEVER to disable certificate verification,
143 # perhaps to allow self-signed certificates.
145 #AUTH_LDAP_START_TLS = False
147 # The distinguished name of a group; authentication will fail for any user
148 # that does not belong to this group.
150 AUTH_LDAP_REQUIRE_GROUP = "cn=enabled,ou=Group,dc=example,dc=org"
152 # The distinguished name of a group; authentication will fail for any user
153 # that belongs to this group.
155 AUTH_LDAP_DENY_GROUP = "cn=disabled,ou=Group,dc=example,dc=org"
157 # If True, LDAPBackend will mirror a user's LDAP group membership in the
158 # Django database. Any time a user authenticates, we will create all of
159 # his LDAP groups as Django groups and update his Django group
160 # membership to exactly match his LDAP group membership. If the LDAP
161 # server has nested groups, the Django database will end up with a
162 # flattened representation.
164 #AUTH_LDAP_MIRROR_GROUPS = False
166 # If True, the fields of a User object will be updated with the latest
167 # values from the LDAP directory every time the user logs in. Otherwise
168 # the User object will only be populated when it is automatically created.
170 AUTH_LDAP_ALWAYS_UPDATE_USER = True
172 # If True, LDAPBackend will be able furnish permissions for any Django
173 # user, regardless of which backend authenticated it.
175 #AUTH_LDAP_AUTHORIZE_ALL_USERS = False
177 # If True, LDAPBackend will furnish group permissions based on the LDAP
178 # groups the authenticated user belongs to. AUTH_LDAP_GROUP_SEARCH and
179 # AUTH_LDAP_GROUP_TYPE must also be set.
181 #AUTH_LDAP_FIND_GROUP_PERMS = False
183 # If True, LDAP group membership will be cached using Django's cache
184 # framework. The cache timeout can be customized with
185 # AUTH_LDAP_GROUP_CACHE_TIMEOUT.
187 AUTH_LDAP_CACHE_GROUPS = True
189 # If AUTH_LDAP_CACHE_GROUPS is True, this is the cache timeout for group
190 # memberships. If None, the global cache timeout will be used.
192 AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600