Fix LDAP error and url handling to be more clear for the end user

This commit is contained in:
Joseph Schorr 2015-03-16 14:33:53 -04:00
parent 6d7a95b019
commit 360aa69d92
2 changed files with 12 additions and 1 deletions

View file

@ -309,7 +309,13 @@
<table class="config-table" ng-if="config.AUTHENTICATION_TYPE == 'LDAP'">
<tr>
<td>LDAP URI:</td>
<td><span class="config-string-field" binding="config.LDAP_URI"></span></td>
<td>
<span class="config-string-field" binding="config.LDAP_URI"
pattern="ldap(s)?://.+"></span>
<div class="help-text">
The full LDAP URI, including the ldap:// or ldaps:// prefix.
</div>
</td>
</tr>
<tr>
<td>Administrator DN:</td>

View file

@ -232,12 +232,17 @@ def _validate_ldap(config):
raise Exception('Missing Admin Password for LDAP configuration')
ldap_uri = config.get('LDAP_URI', 'ldap://localhost')
if not ldap_uri.startswith('ldap://') and not ldap_uri.startswith('ldaps://'):
raise Exception('LDAP URI must start with ldap:// or ldaps://')
try:
with LDAPConnection(ldap_uri, admin_dn, admin_passwd):
pass
except ldap.LDAPError as ex:
values = ex.args[0] if ex.args else {}
if not isinstance(values, dict):
raise Exception(str(ex.args))
raise Exception(values.get('desc', 'Unknown error'))