Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fountain
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
urz-django
fountain
Commits
2d9db56f
Commit
2d9db56f
authored
Mar 13, 2020
by
Daniel Klaffenbach
🐍
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle LDAP errors
parent
3eeeebf3
Pipeline
#31469
passed with stage
in 53 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
fountain/ldap.py
fountain/ldap.py
+12
-4
No files found.
fountain/ldap.py
View file @
2d9db56f
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
import
logging
import
ssl
import
ldap3
from
ldap3
import
Server
,
Connection
,
SYNC
,
OFFLINE_SLAPD_2_4
,
MOCK_SYNC
...
...
@@ -11,7 +12,7 @@ from django.conf import settings
from
django.contrib.auth
import
get_user_model
from
django.utils.functional
import
cached_property
DEFAULT_LDAP_TIMEOUT
=
3
DEFAULT_LDAP_TIMEOUT
=
3
DEFAULT_LDAP_SYNC_URI
=
'ldaps://ldap.tu-chemnitz.de/ou=Users,dc=tu-chemnitz,dc=de'
DEFAULT_LDAP_SYNC_USER_ATTRIBUTES
=
{
...
...
@@ -20,6 +21,8 @@ DEFAULT_LDAP_SYNC_USER_ATTRIBUTES = {
'mail'
:
'email'
,
}
logger
=
logging
.
getLogger
(
__name__
)
class
Ldap
(
object
):
def
__init__
(
self
):
...
...
@@ -64,7 +67,7 @@ class Ldap(object):
server_kwargs
[
'use_ssl'
]
=
True
server_kwargs
[
'tls'
]
=
Tls
(
ca_certs_file
=
self
.
LDAP_CA_CERT
,
validate
=
ssl
.
CERT_REQUIRED
)
s
=
Server
(
**
server_kwargs
)
s
=
Server
(
**
server_kwargs
)
connection_kwargs
=
{
'server'
:
s
,
'auto_bind'
:
True
,
...
...
@@ -72,8 +75,11 @@ class Ldap(object):
'password'
:
self
.
LDAP_SYNC_BASE_PASS
,
'client_strategy'
:
SYNC
,
}
return
Connection
(
**
connection_kwargs
)
try
:
return
Connection
(
**
connection_kwargs
)
except
LDAPException
:
logger
.
warning
(
"LDAP connection failed, LDAP updates will not be available."
)
return
None
def
get_attributes
(
self
,
username
):
"""
...
...
@@ -105,6 +111,8 @@ class Ldap(object):
}
conn
=
self
.
connection
if
not
conn
:
return
{}
try
:
result
=
conn
.
search
(
**
search_kwargs
)
except
LDAPException
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment