Skip to content
Snippets Groups Projects
Commit d71afc2f authored by Andrea Callia D'Iddio's avatar Andrea Callia D'Iddio
Browse files

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!12support impersonating other users.
Pipeline #329338 canceled
......@@ -24,7 +24,7 @@ login_manager.login_message = LOGIN_MANAGER_MESSAGE
def get_ldap_handler(env):
if env == "dev":
if env == "deeev":
return DummyLdapAuthenticator()
return DocLdapAuthenticator()
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment