Skip to content
Snippets Groups Projects
Commit f97cc5a2 authored by Alexandre Ferland's avatar Alexandre Ferland
Browse files

Merge branch 'add_custom_options'

parents 37a41ee5 8a3fae83
Branches
Tags v1.1.0
No related merge requests found
pyldap==2.4.25.1 -r requirements.txt
Sphinx==1.4.3
...@@ -63,9 +63,9 @@ copyright = u'2016, Alexandre Ferland' ...@@ -63,9 +63,9 @@ copyright = u'2016, Alexandre Ferland'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '1.0.0' version = '1.1.0'
# The full version, including alpha/beta/rc tags. # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
......
...@@ -96,6 +96,8 @@ directives: ...@@ -96,6 +96,8 @@ directives:
Default: '*' Default: '*'
``LDAP_GROUP_MEMBER_FILTER_FIELD`` The group member filter field to use when using OpenLDAP. ``LDAP_GROUP_MEMBER_FILTER_FIELD`` The group member filter field to use when using OpenLDAP.
Default: '*' Default: '*'
``LDAP_CUSTOM_OPTIONS`` ``dict`` of ldap options you want to set in this format: {option: value}.
Default: ``None``
================================== ================================================================ ================================== ================================================================
...@@ -114,6 +116,10 @@ History ...@@ -114,6 +116,10 @@ History
Changes: 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 - 1.0.1 June 5, 2016
- Fix ldap filter import. - Fix ldap filter import.
......
import ldap
class BaseConfig(object): class BaseConfig(object):
PROJECT = 'foo' PROJECT = 'foo'
SECRET_KEY = 'dev key' SECRET_KEY = 'dev key'
...@@ -9,3 +12,4 @@ class BaseConfig(object): ...@@ -9,3 +12,4 @@ class BaseConfig(object):
LDAP_USERNAME = 'CN=user,OU=Users,DC=example,DC=org' LDAP_USERNAME = 'CN=user,OU=Users,DC=example,DC=org'
LDAP_PASSWORD = 'password' LDAP_PASSWORD = 'password'
LDAP_LOGIN_VIEW = 'core.login' LDAP_LOGIN_VIEW = 'core.login'
LDAP_CUSTOM_OPTIONS = {ldap.OPT_REFERRALS: 0}
import ldap as l
from flask import Flask, g, request, session, redirect, url_for from flask import Flask, g, request, session, redirect, url_for
from flask_simpleldap import LDAP from flask_simpleldap import LDAP
...@@ -9,6 +10,7 @@ app.config['LDAP_HOST'] = 'ldap.example.org' ...@@ -9,6 +10,7 @@ app.config['LDAP_HOST'] = 'ldap.example.org'
app.config['LDAP_BASE_DN'] = 'OU=users,dc=example,dc=org' 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_USERNAME'] = 'CN=user,OU=Users,DC=example,DC=org'
app.config['LDAP_PASSWORD'] = 'password' app.config['LDAP_PASSWORD'] = 'password'
app.config['LDAP_CUSTOM_OPTIONS'] = {l.OPT_REFERRALS: 0}
ldap = LDAP(app) ldap = LDAP(app)
......
...@@ -59,6 +59,7 @@ class LDAP(object): ...@@ -59,6 +59,7 @@ class LDAP(object):
app.config.setdefault('LDAP_OPENLDAP', False) app.config.setdefault('LDAP_OPENLDAP', False)
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER', '*') app.config.setdefault('LDAP_GROUP_MEMBER_FILTER', '*')
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER_FIELD', '*') 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']: if app.config['LDAP_USE_SSL'] or app.config['LDAP_USE_TLS']:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,
...@@ -74,6 +75,14 @@ class LDAP(object): ...@@ -74,6 +75,14 @@ class LDAP(object):
if app.config['LDAP_{0}'.format(option)] is None: if app.config['LDAP_{0}'.format(option)] is None:
raise LDAPException('LDAP_{0} cannot be None!'.format(option)) 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 @property
def initialize(self): def initialize(self):
"""Initialize a connection to the LDAP server. """Initialize a connection to the LDAP server.
...@@ -88,6 +97,7 @@ class LDAP(object): ...@@ -88,6 +97,7 @@ class LDAP(object):
current_app.config['LDAP_PORT'])) current_app.config['LDAP_PORT']))
conn.set_option(ldap.OPT_NETWORK_TIMEOUT, conn.set_option(ldap.OPT_NETWORK_TIMEOUT,
current_app.config['LDAP_TIMEOUT']) current_app.config['LDAP_TIMEOUT'])
conn = self._set_custom_options(conn)
conn.protocol_version = ldap.VERSION3 conn.protocol_version = ldap.VERSION3
if current_app.config['LDAP_USE_TLS']: if current_app.config['LDAP_USE_TLS']:
conn.start_tls_s() conn.start_tls_s()
......
Flask==0.11 Flask==0.11
mock==2.0.0 mock==2.0.0 # for ci
pyldap==2.4.25.1
...@@ -9,7 +9,7 @@ from setuptools import setup ...@@ -9,7 +9,7 @@ from setuptools import setup
setup( setup(
name='Flask-SimpleLDAP', name='Flask-SimpleLDAP',
version='1.0.1', version='1.1.0',
url='https://github.com/admiralobvious/flask-simpleldap', url='https://github.com/admiralobvious/flask-simpleldap',
license='MIT', license='MIT',
author='Alexandre Ferland', author='Alexandre Ferland',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment