Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kontr 2.0
Portal API Backend
Commits
9e696e87
Unverified
Commit
9e696e87
authored
Sep 18, 2018
by
Peter Stanko
Browse files
Better Logging for LDAP search and ldap integration
parent
d0ce30c1
Pipeline
#13211
failed with stage
in 31 minutes and 55 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
portal/service/users.py
View file @
9e696e87
...
...
@@ -38,6 +38,7 @@ class UserLdapService:
Returns(int): User's uco
"""
username
=
self
.
user
.
username
log
.
info
(
f
"[LDAP] Extracting uco for:
{
self
.
user
.
log_name
}
"
)
user_entity
=
self
.
ldap
.
search
(
f
"uid=
{
username
}
,ou=People"
)
log
.
debug
(
f
"[LDAP] User (
{
username
}
):
{
user_entity
}
"
)
if
not
user_entity
:
...
...
@@ -88,6 +89,7 @@ class UserService:
def
__update_uco_using_ldap
(
self
,
data
):
if
self
.
ldap
.
is_enabled
:
log
.
debug
(
"[LDAP] Ldap is enabled, extracting UCO"
)
uco
=
self
.
ldap
.
extract_uco
()
if
uco
:
data
[
'uco'
]
=
uco
...
...
portal/tools/ldap_client.py
View file @
9e696e87
...
...
@@ -54,6 +54,7 @@ class LDAPWrapper(object):
"""
if
not
self
.
_ldap_server
and
self
.
is_enabled
:
self
.
_ldap_server
=
ldap3
.
Server
(
self
.
ldap_url
,
get_info
=
ldap3
.
ALL
)
log
.
info
(
f
"[LDAP] Creating LDAP server instance
{
self
.
ldap_url
}
:
{
self
.
_ldap_server
}
"
)
return
self
.
_ldap_server
@
property
...
...
@@ -61,11 +62,18 @@ class LDAPWrapper(object):
connection
=
None
if
self
.
ldap
is
not
None
:
connection
=
ldap3
.
Connection
(
self
.
ldap
,
auto_bind
=
True
)
log
.
debug
(
f
"[LDAP] Creating LDAP connection instance:
{
connection
}
}"
)
return
connection
def
search
(
self
,
selector
:
str
):
selector
=
selector
+
self
.
selector_base
log
.
debug
(
f
"[LDAP] Search
{
self
.
ldap_url
}
: (
{
selector
}
)"
)
self
.
ldap_connection
.
search
(
selector
,
'(objectclass=*)'
,
attributes
=
ldap3
.
ALL_ATTRIBUTES
)
result
=
self
.
ldap_connection
.
entries
[
0
]
log
.
debug
(
f
"[LDAP] Search (
{
selector
}
):
{
result
}
"
)
return
result
entries
=
self
.
ldap_connection
.
entries
if
entries
:
result
=
entries
[
0
]
log
.
debug
(
f
"[LDAP] Search (
{
selector
}
):
{
result
}
"
)
return
result
else
:
log
.
warning
(
f
"[LDAP] Not found any entry for selector:
{
selector
}
"
)
return
None
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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