Skip to content

Commit

Permalink
Merge branch 'add_custom_options'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Ferland committed Jun 8, 2016
2 parents 37a41ee + 8a3fae8 commit f97cc5a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pyldap==2.4.25.1
-r requirements.txt
Sphinx==1.4.3

4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def __getattr__(cls, name):
# built documents.
#
# The short X.Y version.
version = '1.0.0'
version = '1.1.0'
# The full version, including alpha/beta/rc tags.
release = '1.0.0'
release = '1.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ directives:
Default: '*'
``LDAP_GROUP_MEMBER_FILTER_FIELD`` The group member filter field to use when using OpenLDAP.
Default: '*'
``LDAP_CUSTOM_OPTIONS`` ``dict`` of ldap options you want to set in this format: {option: value}.
Default: ``None``
================================== ================================================================


Expand All @@ -114,6 +116,10 @@ History

Changes:

- 1.1.0 June 7, 2016

- Add the ability the pass any valid pyldap config options via the LDAP_CUSTOM_OPTIONS configuration directive.

- 1.0.1 June 5, 2016

- Fix ldap filter import.
Expand Down
4 changes: 4 additions & 0 deletions examples/blueprints/blueprints/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import ldap


class BaseConfig(object):
PROJECT = 'foo'
SECRET_KEY = 'dev key'
Expand All @@ -9,3 +12,4 @@ class BaseConfig(object):
LDAP_USERNAME = 'CN=user,OU=Users,DC=example,DC=org'
LDAP_PASSWORD = 'password'
LDAP_LOGIN_VIEW = 'core.login'
LDAP_CUSTOM_OPTIONS = {ldap.OPT_REFERRALS: 0}
2 changes: 2 additions & 0 deletions examples/groups/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ldap as l
from flask import Flask, g, request, session, redirect, url_for
from flask_simpleldap import LDAP

Expand All @@ -9,6 +10,7 @@
app.config['LDAP_BASE_DN'] = 'OU=users,dc=example,dc=org'
app.config['LDAP_USERNAME'] = 'CN=user,OU=Users,DC=example,DC=org'
app.config['LDAP_PASSWORD'] = 'password'
app.config['LDAP_CUSTOM_OPTIONS'] = {l.OPT_REFERRALS: 0}

ldap = LDAP(app)

Expand Down
10 changes: 10 additions & 0 deletions flask_simpleldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def init_app(app):
app.config.setdefault('LDAP_OPENLDAP', False)
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER', '*')
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER_FIELD', '*')
app.config.setdefault('LDAP_CUSTOM_OPTIONS', None)

if app.config['LDAP_USE_SSL'] or app.config['LDAP_USE_TLS']:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,
Expand All @@ -74,6 +75,14 @@ def init_app(app):
if app.config['LDAP_{0}'.format(option)] is None:
raise LDAPException('LDAP_{0} cannot be None!'.format(option))

@staticmethod
def _set_custom_options(conn):
options = current_app.config['LDAP_CUSTOM_OPTIONS']
if options:
for k, v in options.items():
conn.set_option(k, v)
return conn

@property
def initialize(self):
"""Initialize a connection to the LDAP server.
Expand All @@ -88,6 +97,7 @@ def initialize(self):
current_app.config['LDAP_PORT']))
conn.set_option(ldap.OPT_NETWORK_TIMEOUT,
current_app.config['LDAP_TIMEOUT'])
conn = self._set_custom_options(conn)
conn.protocol_version = ldap.VERSION3
if current_app.config['LDAP_USE_TLS']:
conn.start_tls_s()
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Flask==0.11
mock==2.0.0
mock==2.0.0 # for ci
pyldap==2.4.25.1

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='Flask-SimpleLDAP',
version='1.0.1',
version='1.1.0',
url='https://github.com/admiralobvious/flask-simpleldap',
license='MIT',
author='Alexandre Ferland',
Expand Down

0 comments on commit f97cc5a

Please sign in to comment.