Skip to content

Commit

Permalink
Enable debug output for ldap login
Browse files Browse the repository at this point in the history
  • Loading branch information
OzzieIsaacs committed Mar 26, 2023
1 parent d35e781 commit 9646b6e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
37 changes: 35 additions & 2 deletions cps/services/simpleldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from flask_simpleldap import LDAP, LDAPException
from flask_simpleldap import ldap as pyLDAP
from flask import current_app
from .. import constants, logger

try:
Expand All @@ -28,9 +29,41 @@
pass

log = logger.create()
_ldap = LDAP()


class mySimpleLDap(LDAP):

@staticmethod
def init_app(app):
super(mySimpleLDap, mySimpleLDap).init_app(app)
app.config.setdefault('LDAP_LOGLEVEL', 0)


@property
def initialize(self):
"""Initialize a connection to the LDAP server.
:return: LDAP connection object.
"""
try:
log_level = 2 if current_app.config['LDAP_LOGLEVEL'] == logger.logging.DEBUG else 0
conn = pyLDAP.initialize('{0}://{1}:{2}'.format(
current_app.config['LDAP_SCHEMA'],
current_app.config['LDAP_HOST'],
current_app.config['LDAP_PORT']), trace_level=log_level)
conn.set_option(pyLDAP.OPT_NETWORK_TIMEOUT,
current_app.config['LDAP_TIMEOUT'])
conn = self._set_custom_options(conn)
conn.protocol_version = pyLDAP.VERSION3
if current_app.config['LDAP_USE_TLS']:
conn.start_tls_s()
return conn
except pyLDAP.LDAPError as e:
raise LDAPException(self.error(e.args))


_ldap = mySimpleLDap()

def init_app(app, config):
if config.config_login_type != constants.LOGIN_LDAP:
return
Expand Down Expand Up @@ -70,7 +103,7 @@ def init_app(app, config):
app.config['LDAP_OPENLDAP'] = bool(config.config_ldap_openldap)
app.config['LDAP_GROUP_OBJECT_FILTER'] = config.config_ldap_group_object_filter
app.config['LDAP_GROUP_MEMBERS_FIELD'] = config.config_ldap_group_members_field

app.config['LDAP_LOGLEVEL'] = config.config_log_level
try:
_ldap.init_app(app)
except ValueError:
Expand Down
6 changes: 3 additions & 3 deletions optional-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# GDrive Integration
google-api-python-client>=1.7.11,<2.78.0
google-api-python-client>=1.7.11,<2.90.0
gevent>20.6.0,<23.0.0
greenlet>=0.4.17,<2.1.0
httplib2>=0.9.2,<0.22.0
httplib2>=0.9.2,<0.23.0
oauth2client>=4.0.0,<4.1.4
uritemplate>=3.0.0,<4.2.0
pyasn1-modules>=0.0.8,<0.3.0
Expand All @@ -13,7 +13,7 @@ rsa>=3.4.2,<4.10.0

# Gmail
google-auth-oauthlib>=0.4.3,<0.9.0
google-api-python-client>=1.7.11,<2.78.0
google-api-python-client>=1.7.11,<2.90.0

# goodreads
goodreads>=0.3.2,<0.4.0
Expand Down

0 comments on commit 9646b6e

Please sign in to comment.