Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
b7910738
Commit
b7910738
authored
May 23, 2019
by
xiaomao
Committed by
老广
May 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 解决ldap映射is_active等字段为bool值的问题 (#2716) (#2721)
parent
45cb39e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
ldap.py
apps/authentication/backends/ldap.py
+12
-2
utils.py
apps/settings/utils.py
+9
-0
No files found.
apps/authentication/backends/ldap.py
View file @
b7910738
...
...
@@ -86,7 +86,18 @@ class LDAPUser(_LDAPUser):
return
user_dn
def
_populate_user_from_attributes
(
self
):
super
()
.
_populate_user_from_attributes
()
for
field
,
attr
in
self
.
settings
.
USER_ATTR_MAP
.
items
():
try
:
value
=
self
.
attrs
[
attr
][
0
]
except
LookupError
:
logger
.
warning
(
"{} does not have a value for the attribute {}"
.
format
(
self
.
dn
,
attr
))
else
:
if
not
hasattr
(
self
.
_user
,
field
):
continue
if
isinstance
(
getattr
(
self
.
_user
,
field
),
bool
):
value
=
bool
(
int
(
value
==
'true'
))
setattr
(
self
.
_user
,
field
,
value
)
if
not
hasattr
(
self
.
_user
,
'email'
)
or
'@'
not
in
self
.
_user
.
email
:
if
'@'
not
in
self
.
_user
.
username
:
email
=
'{}@{}'
.
format
(
self
.
_user
.
username
,
settings
.
EMAIL_SUFFIX
)
...
...
@@ -95,4 +106,3 @@ class LDAPUser(_LDAPUser):
setattr
(
self
.
_user
,
'email'
,
email
)
apps/settings/utils.py
View file @
b7910738
...
...
@@ -60,6 +60,8 @@ class LDAPUtil:
for
field
,
value
in
user_item
.
items
():
if
not
hasattr
(
user
,
field
):
continue
if
isinstance
(
getattr
(
user
,
field
),
bool
):
value
=
bool
(
int
(
value
==
'true'
))
setattr
(
user
,
field
,
value
)
user
.
save
()
...
...
@@ -82,6 +84,13 @@ class LDAPUtil:
@staticmethod
def
create_user
(
user_item
):
user
=
User
()
for
field
,
value
in
user_item
.
items
():
if
not
hasattr
(
user
,
field
):
continue
if
isinstance
(
getattr
(
user
,
field
),
bool
):
value
=
bool
(
int
(
value
==
'true'
))
user_item
[
field
]
=
value
user_item
[
'source'
]
=
User
.
SOURCE_LDAP
try
:
User
.
objects
.
create
(
**
user_item
)
...
...
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