Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rixx
uffd
Commits
8fc5a7d5
Commit
8fc5a7d5
authored
4 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Refactored processing of LDAP_USER_DEFAULT_ATTRIBUTES
parent
de62f54d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
uffd/default_config.cfg
+4
-1
4 additions, 1 deletion
uffd/default_config.cfg
uffd/user/models.py
+18
-14
18 additions, 14 deletions
uffd/user/models.py
with
22 additions
and
15 deletions
uffd/default_config.cfg
+
4
−
1
View file @
8fc5a7d5
...
...
@@ -15,8 +15,11 @@ LDAP_USER_MAIL_ATTRIBUTE="mail"
LDAP_USER_MAIL_ALIASES
=
[]
LDAP_USER_DEFAULT_ATTRIBUTES
=
{
"sn":
"
",
# All string values are subject to python str.format-style format expansion. To insert literal braces use "{{" and "}}".
# Variables: uid, loginname, displayname, mail and possibly other attributes of the User class
"homeDirectory":
"/home/{loginname}",
"gidNumber":
LDAP_USER_GID
"gidNumber":
LDAP_USER_GID,
# "multiValueAttribute": ["value1", "value2"],
}
LDAP_GROUP_SEARCH_BASE
=
"ou=groups,dc=example,dc=com"
...
...
This diff is collapsed.
Click to expand it.
uffd/user/models.py
+
18
−
14
View file @
8fc5a7d5
...
...
@@ -17,13 +17,18 @@ def get_next_uid():
raise
Exception
(
'
No free uid found
'
)
return
next_uid
class
Dict
View
:
class
ObjectAttribute
Dict
:
def
__init__
(
self
,
obj
):
self
.
obj
=
obj
def
__getitem__
(
self
,
key
):
return
getattr
(
self
.
obj
,
key
)
def
format_with_attributes
(
fmtstr
,
obj
):
# Do str.format-style string formatting with the attributes of an object
# E.g. format_with_attributes("/home/{loginname}", obj) = "/home/foobar" if obj.loginname = "foobar"
return
fmtstr
.
format_map
(
ObjectAttributeDict
(
obj
))
class
BaseUser
(
ldap
.
Model
):
ldap_search_base
=
lazyconfig_str
(
'
LDAP_USER_SEARCH_BASE
'
)
ldap_filter_params
=
lazyconfig_list
(
'
LDAP_USER_SEARCH_FILTER
'
)
...
...
@@ -40,19 +45,18 @@ class BaseUser(ldap.Model):
groups
=
[]
# Shuts up pylint, overwritten by back-reference
roles
=
[]
# Shuts up pylint, overwritten by back-reference
def
dummy_attribute_defaults
(
self
):
for
name
,
patterns
in
current_app
.
config
[
'
LDAP_USER_DEFAULT_ATTRIBUTES
'
].
items
():
if
not
isinstance
(
patterns
,
list
):
patterns
=
[
patterns
]
values
=
[]
for
pattern
in
patterns
:
if
isinstance
(
pattern
,
str
):
values
.
append
(
pattern
.
format_map
(
DictView
(
self
)))
else
:
values
.
append
(
pattern
)
self
.
ldap_object
.
setattr
(
name
,
values
)
ldap_add_hooks
=
ldap
.
Model
.
ldap_add_hooks
+
(
dummy_attribute_defaults
,)
def
add_default_attributes
(
self
):
for
name
,
values
in
current_app
.
config
[
'
LDAP_USER_DEFAULT_ATTRIBUTES
'
].
items
():
if
not
isinstance
(
values
,
list
):
values
=
[
values
]
formatted_values
=
[]
for
value
in
values
:
if
isinstance
(
value
,
str
):
value
=
format_with_attributes
(
value
,
self
)
formatted_values
.
append
(
value
)
self
.
ldap_object
.
setattr
(
name
,
formatted_values
)
ldap_add_hooks
=
ldap
.
Model
.
ldap_add_hooks
+
(
add_default_attributes
,)
# Write-only property
def
password
(
self
,
value
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment