Skip to content
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

Conversation

lucasbenevides
Copy link

Includes a new parameter, called ckanext.ldap.base_dn_alt with permits a new Distinguished Name to be searched when a login operation is performed.
It uses the same logic implemented in the parameter ckanext.ldap.search_alt that already existed.
This was implemented because the forest of my organization has two organizational units (OU) and the CKAN must be acessed from users from both OUs.

Adds to the description the alternative base Distinguished Name (DN) in case the forest has two Organizational Units (OU) to look for. The way the python-ldap package is built, it needs the DN to have an OU. The original ldap library in C does not need it. Although, as a corner case solution, a new parameter of the alternative DN was created.
Include the alternative Distinguished Name (dn) parameter. It seems (needs confirmation) like the way the python-ldap package was built, it does not accept a DN wit only the Domain Component (DC), it must have a OU. So the parameter ckanext.ldap.base_dn_alt will be useful in case the Active Directory (AD) forest has two Organizational Units. Although, the best solution would be changing the python-ldap package so that the search functions worked with a DN without an OU.
This modification permits the use of two base Distinguished Names that will be searched for. It works along with the ckanext.ldap.search_alt, using the same logic. It there was already a way to use two Organizational Units in the cnakext.ldap.base_dn this change would be dull.
Copy link
Member

@jrdh jrdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of minor queries. Apologies for the delay getting this reviewed!

ckanext/ldap/controllers/user.py Outdated Show resolved Hide resolved
ckanext/ldap/controllers/user.py Outdated Show resolved Hide resolved
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?')
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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.
I don't know how I could get more information to de logs.

Copy link
Member

Choose a reason for hiding this comment

The 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 info attribute is optional and dependant on whether the server returned an extra info or not. Perhaps we could check if there is an info attribute available or not and then log it or not based on that?

Removes commented like as indicated by @jrdh.
Corrects the case when alternative filter search is changed and distinguished name alternative must be tested.
@lucasbenevides
Copy link
Author

I committed to my respository branch. I think it automatically brings the changes.

@@ -287,6 +287,8 @@ 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(
login=ldap.filter.escape_filter_chars(login))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ckanext.ldap.search.alt is optional so I'm pretty sure this will raise an exception if it's not defined in the config.

@jrdh jrdh reopened this Feb 15, 2019
@@ -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)
Copy link
Member

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.

Suggested change
toolkit.redirect_to(controller=u'user', action=u'logged_in', came_from=came_from)
toolkit.redirect_to(u'user.logged_in', came_from=came_from)

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?')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.error(u'LDAP query failed. Maybe you need auth credentials for performing searches?')
error_msg = u'LDAP query failed. Maybe you need auth credentials for performing searches?'
if hasattr(e, u'info'):
error_msg += u' Error returned by the server: ' + e.info
log.error(error_msg)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret = _ldap_search(cnx, filter_str, attributes, config[u'ckanext.ldap.base_dn_alt'], non_unique=u'log
ret = _ldap_search(cnx, filter_str, attributes, config[u'ckanext.ldap.base_dn_alt'], non_unique=u'log')

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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret = _ldap_search(cnx, filter_str_alt, attributes, config[u'ckanext.ldap.base_dn_alt'], non_unique=u'raise
ret = _ldap_search(cnx, filter_str_alt, attributes, config[u'ckanext.ldap.base_dn_alt'], non_unique=u'raise')

@@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filter_str_alt = config[u'ckanext.ldap.search.alt'].format(
filter_str_alt = config.get(u'ckanext.ldap.search.alt', u'').format(

@alycejenni alycejenni deleted the branch NaturalHistoryMuseum:ckan-upgrade-2.8.0a March 14, 2022 10:58
@alycejenni alycejenni closed this Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants