-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ckan upgrade 2.8.0a - permit alternative DistinguishedName (dn) #49
Changes from all commits
005ad1b
e2ed35e
c8d66b1
7f91f1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -106,7 +106,7 @@ def _login_success(self, user_name, came_from): | |||||||||||
''' | ||||||||||||
session[u'ckanext-ldap-user'] = user_name | ||||||||||||
session.save() | ||||||||||||
toolkit.redirect_to(u'user.logged_in', came_from=came_from) | ||||||||||||
toolkit.redirect_to(controller=u'user', action=u'logged_in', came_from=came_from) | ||||||||||||
|
||||||||||||
|
||||||||||||
def _get_user_dict(user_id): | ||||||||||||
|
@@ -287,23 +287,29 @@ def _find_ldap_user(login): | |||||||||||
|
||||||||||||
filter_str = config[u'ckanext.ldap.search.filter'].format( | ||||||||||||
login=ldap.filter.escape_filter_chars(login)) | ||||||||||||
filter_str_alt = config[u'ckanext.ldap.search.alt'].format( | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
login=ldap.filter.escape_filter_chars(login)) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||
attributes = [config[u'ckanext.ldap.username']] | ||||||||||||
if u'ckanext.ldap.fullname' in config: | ||||||||||||
attributes.append(config[u'ckanext.ldap.fullname']) | ||||||||||||
if u'ckanext.ldap.email' in config: | ||||||||||||
attributes.append(config[u'ckanext.ldap.email']) | ||||||||||||
|
||||||||||||
try: | ||||||||||||
ret = _ldap_search(cnx, filter_str, attributes, non_unique=u'log') | ||||||||||||
ret = _ldap_search(cnx, filter_str, attributes, config[u'ckanext.ldap.base_dn'], non_unique=u'log') | ||||||||||||
if ret is None and u'ckanext.ldap.search.alt' in config: | ||||||||||||
filter_str = config[u'ckanext.ldap.search.alt'].format( | ||||||||||||
login=ldap.filter.escape_filter_chars(login)) | ||||||||||||
ret = _ldap_search(cnx, filter_str, attributes, non_unique=u'raise') | ||||||||||||
ret = _ldap_search(cnx, filter_str_alt, attributes, config[u'ckanext.ldap.base_dn'], non_unique=u'raise') | ||||||||||||
if ret is None and u'ckanext.ldap.base_dn_alt' in config: | ||||||||||||
ret = _ldap_search(cnx, filter_str, attributes, config[u'ckanext.ldap.base_dn_alt'], non_unique=u'log | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
if ret is None and u'ckanext.ldap.base_dn_alt' in config and u'ckanext.ldap.search.alt' in config: | ||||||||||||
ret = _ldap_search(cnx, filter_str_alt, attributes, config[u'ckanext.ldap.base_dn_alt'], non_unique=u'raise | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
finally: | ||||||||||||
cnx.unbind() | ||||||||||||
return ret | ||||||||||||
|
||||||||||||
|
||||||||||||
def _ldap_search(cnx, filter_str, attributes, non_unique=u'raise'): | ||||||||||||
def _ldap_search(cnx, filter_str, attributes, base_dn_str, non_unique=u'raise'): | ||||||||||||
'''Helper function to perform the actual LDAP search | ||||||||||||
|
||||||||||||
:param cnx: The LDAP connection object | ||||||||||||
|
@@ -321,14 +327,14 @@ def _ldap_search(cnx, filter_str, attributes, non_unique=u'raise'): | |||||||||||
|
||||||||||||
''' | ||||||||||||
try: | ||||||||||||
res = cnx.search_s(config[u'ckanext.ldap.base_dn'], ldap.SCOPE_SUBTREE, | ||||||||||||
res = cnx.search_s(base_dn_str, ldap.SCOPE_SUBTREE, | ||||||||||||
filterstr=filter_str, attrlist=attributes) | ||||||||||||
|
||||||||||||
except ldap.SERVER_DOWN: | ||||||||||||
log.error(u'LDAP server is not reachable') | ||||||||||||
return None | ||||||||||||
except ldap.OPERATIONS_ERROR as e: | ||||||||||||
log.error( | ||||||||||||
u'LDAP query failed. Maybe you need auth credentials for performing searches? Error returned by the server: ' + e.info) | ||||||||||||
log.error(u'LDAP query failed. Maybe you need auth credentials for performing searches?') | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the error info be added back in? Or another way or getting more information about the error for the logs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The e.info does not exist. I was getting a Notice in the error log, that says the info atribute is not available when it did enter in that except.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ldap library's doc isn't all that clear but I think from my quick look the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
return None | ||||||||||||
except (ldap.NO_SUCH_OBJECT, ldap.REFERRAL) as e: | ||||||||||||
log.error( | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reverts back to the old pylons syntax.