Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Project Allocator
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
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
edtech
Project Allocator
Commits
d71afc2f
Commit
d71afc2f
authored
2 years ago
by
Andrea Callia D'Iddio
Browse files
Options
Downloads
Patches
Plain Diff
Style: use regular expressions to be more precise and elegant (suggested by Ivan).
parent
1fecd1e6
No related branches found
No related tags found
1 merge request
!12
support impersonating other users.
Pipeline
#329338
canceled
2 years ago
Stage: lint
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/__init__.py
+1
-1
1 addition, 1 deletion
app/__init__.py
app/ldap_authentication/authenticator.py
+8
-6
8 additions, 6 deletions
app/ldap_authentication/authenticator.py
with
9 additions
and
7 deletions
app/__init__.py
+
1
−
1
View file @
d71afc2f
...
...
@@ -24,7 +24,7 @@ login_manager.login_message = LOGIN_MANAGER_MESSAGE
def
get_ldap_handler
(
env
):
if
env
==
"
dev
"
:
if
env
==
"
de
ee
v
"
:
return
DummyLdapAuthenticator
()
return
DocLdapAuthenticator
()
...
...
This diff is collapsed.
Click to expand it.
app/ldap_authentication/authenticator.py
+
8
−
6
View file @
d71afc2f
...
...
@@ -9,7 +9,7 @@ from ldap.ldapobject import SimpleLDAPObject
from
app.protocols
import
Authenticator
# Impersonation constants
IMPERSONATION_
OPERATOR
=
"
.as.
"
IMPERSONATION_
PATTERN
=
r
"
([a-z0-9]+) as ([a-z0-9]+)
"
IMPERSONATORS
=
[
"
ac4014
"
,
"
infosys
"
,
"
ip914
"
,
"
jsbailey
"
,
"
ld507
"
,
"
rbc
"
]
...
...
@@ -77,11 +77,13 @@ class DocLdapAuthenticator(Authenticator):
:return: attr_name -> attr_value dict for given username
"""
logging_in_as
=
username
if
IMPERSONATION_OPERATOR
in
username
:
users
=
username
.
split
(
IMPERSONATION_OPERATOR
)
if
users
[
0
]
in
IMPERSONATORS
:
username
=
users
[
0
]
logging_in_as
=
users
[
1
]
users
=
re
.
match
(
IMPERSONATION_PATTERN
,
username
)
if
users
:
impersonator
=
users
.
groups
()[
0
]
impersonated
=
users
.
groups
()[
1
]
if
impersonator
in
IMPERSONATORS
:
username
=
impersonator
logging_in_as
=
impersonated
connection
=
ldap
.
initialize
(
self
.
server_url
)
connection
.
set_option
(
ldap
.
OPT_X_TLS_REQUIRE_CERT
,
ldap
.
OPT_X_TLS_ALLOW
)
connection
.
set_option
(
ldap
.
OPT_X_TLS_NEWCTX
,
0
)
...
...
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