Make ldap3 requirement optional

This commit is contained in:
Amar Ramachandran 2017-08-09 10:06:59 -07:00
parent b9e08897ac
commit 588c868060
3 changed files with 15 additions and 7 deletions

View File

@ -1,20 +1,26 @@
import logging
logger = logging.getLogger('ldap_auth')
from redash import settings
from flask import flash, redirect, render_template, request, url_for, Blueprint
from flask_login import current_user, login_required, login_user, logout_user
from ldap3 import Server, Connection, SIMPLE
from redash import settings
try:
from ldap3 import Server, Connection, SIMPLE
except ImportError:
if settings.LDAP_LOGIN_ENABLED:
logger.error("The ldap3 library was not found. This is required to use LDAP authentication (see requirements.txt).")
exit()
from redash.authentication.google_oauth import create_and_login_user
from redash.authentication.org_resolving import current_org
logger = logging.getLogger('ldap_auth')
blueprint = Blueprint('ldap_auth', __name__)
@blueprint.route("/ldap_auth/login", methods=['GET', 'POST'])
@blueprint.route("/ldap/login", methods=['GET', 'POST'])
def login(org_slug=None):
index_url = url_for("redash.index", org_slug=org_slug)
next_path = request.args.get('next', index_url)

View File

@ -135,7 +135,7 @@ LDAP_BIND_DN_PASSWORD = os.environ.get('REDASH_LDAP_BIND_DN_PASSWORD', '')
LDAP_DISPLAY_NAME_KEY = os.environ.get('REDASH_LDAP_DISPLAY_NAME_KEY', 'displayName')
LDAP_EMAIL_KEY = os.environ.get('REDASH_LDAP_EMAIL_KEY', "mail")
# Prompt that should be shown above username/email field.
LDAP_CUSTOM_USERNAME_PROMPT = os.environ.get('REDASH_LDAP_LDAP_CUSTOM_USERNAME_PROMPT', 'LDAP/AD/SSO username:')
LDAP_CUSTOM_USERNAME_PROMPT = os.environ.get('REDASH_LDAP_CUSTOM_USERNAME_PROMPT', 'LDAP/AD/SSO username:')
# LDAP Search DN TEMPLATE (for AD this should be "(sAMAccountName=%(username)s)"")
LDAP_SEARCH_TEMPLATE = os.environ.get('REDASH_LDAP_SEARCH_TEMPLATE', '(cn=%(username)s)')
# The schema to bind to (ex. cn=users,dc=ORG,dc=local)

View File

@ -43,4 +43,6 @@ pystache==0.5.4
parsedatetime==2.1
cryptography==1.4
simplejson==3.10.0
ldap3==2.2.4
# Uncomment the requirement for ldap3 if using ldap.
# It is not included by default because of the GPL license conflict.
# ldap3==2.2.4