Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions flask_ldap3_login/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def init_config(self, config):
self.config.setdefault('LDAP_PORT', 389)
self.config.setdefault('LDAP_HOST', None)
self.config.setdefault('LDAP_USE_SSL', False)
self.config.setdefault('LDAP_USE_STARTTLS', False)
self.config.setdefault('LDAP_READONLY', True)
self.config.setdefault('LDAP_CHECK_NAMES', True)
self.config.setdefault('LDAP_BIND_DIRECT_CREDENTIALS', False)
Expand Down Expand Up @@ -160,8 +161,7 @@ def add_server(self, hostname, port, use_ssl, tls_ctx=None):
Returns:
ldap3.Server: The freshly created server object.
"""
if not use_ssl and tls_ctx:
raise ValueError("Cannot specify a TLS context and not use SSL!")

server = ldap3.Server(
hostname,
port=port,
Expand Down Expand Up @@ -791,6 +791,8 @@ def _make_connection(self, bind_user=None, bind_password=None,
raise_exceptions=True,
**kwargs
)
if self.config.get('LDAP_USE_STARTTLS'):
connection.start_tls()

if contextualise:
self._contextualise_connection(connection)
Expand Down
8 changes: 4 additions & 4 deletions flask_ldap3_login/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class LDAPLoginForm(FlaskForm):

"""

username = wtforms.StringField('Username', validators=[validators.Required()])
password = wtforms.PasswordField('Password', validators=[validators.Required()])
username = wtforms.StringField('Username', validators=[validators.DataRequired()])
password = wtforms.PasswordField('Password', validators=[validators.DataRequired()])
submit = wtforms.SubmitField('Submit')
remember_me = wtforms.BooleanField('Remember Me', default=True)

def validate_ldap(self):
logging.debug('Validating LDAPLoginForm against LDAP')
log.debug('Validating LDAPLoginForm against LDAP')
'Validate the username/password data against ldap directory'
ldap_mgr = current_app.ldap3_login_manager
username = self.username.data
Expand Down Expand Up @@ -62,7 +62,7 @@ def validate(self, *args, **kwargs):

valid = FlaskForm.validate(self, *args, **kwargs)
if not valid:
logging.debug("Form validation failed before we had a chance to "
log.debug("Form validation failed before we had a chance to "
"check ldap. Reasons: '{0}'".format(self.errors))
return valid

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_version():
except Exception:
version = '0.0.0-dev'

requires = ['ldap3>=2.0.7', 'Flask', 'Flask-wtf']
requires = ["ldap3>=2.0.7", "Flask", "Flask-wtf", "WTForms>=1.0.2"]

try:
import enum # noqa
Expand Down