Skip to content

Migrate from python-ldap to ldap3#179

Merged
thatarchguy merged 7 commits intomasterfrom
ldap3-migration
Nov 11, 2016
Merged

Migrate from python-ldap to ldap3#179
thatarchguy merged 7 commits intomasterfrom
ldap3-migration

Conversation

@mprahl
Copy link
Member

@mprahl mprahl commented Nov 4, 2016

  • Turn off logging during tests
  • Replace python-ldap code with ldap3
  • Simplifies the check_nested_group_membership function so that the membership checking is done in AD and not in Python
  • Since ldap3 allows NTLM authentication against AD, this was added as a config option
  • Unit tests greatly simplified

This is a big PR, I think it'd be easier for you to review on a per commit basis (I tried to make those neat and concise changes).

postmaster/ad.py Outdated
elif re.match(extract_username_regex, username):
# Parse the username from the UPN
username_search = re.search(extract_username_regex, username)
return self.domain + '\\' + username_search.group('username')
Copy link
Member

Choose a reason for hiding this comment

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

Either use .format or .join to format strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll fix this tonight.

postmaster/ad.py Outdated
# If the authentication method is not NTLM, then distinguished names are valid usernames
return username
else:
return self.domain + '\\' + username
Copy link
Member

Choose a reason for hiding this comment

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

Either use .format or .join to format strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll fix this tonight.

""" Validates the password from a wtforms object
"""
# Prevent circular import on json_logger by importing here
from postmaster.ad import AD, ADException
Copy link
Member

Choose a reason for hiding this comment

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

How does this create a circular import on json_logger?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because AD relies on json_logger which is defined in utils.py. If I import AD at the top of the file, it tries to import json_logger which is not yet defined.

Is this okay or should we separate the files out somehow?

Copy link
Member

Choose a reason for hiding this comment

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

We may run into this in the future. It may be better to separate the logger out into its own logger.py file.

@@ -0,0 +1,912 @@
{
"entries": [
Copy link
Member

Choose a reason for hiding this comment

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

My oh my I hope this was exported from somewhere!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fortunately, yes :)

Here's an example from the docs:

from ldap3 import Server, Connection, ALL_ATTRIBUTES
server = Server('my_real_server')
connection = Connection(server, 'cn=my_real_user,ou=test,o=lab', 'my_real_password', auto_bind=True)
if connection.search('ou=test,o=lab', '(objectclass=*)', attributes=ALL_ATTRIBUTES):
    connection.response_to_file('my_entries.json', raw=True)

@thatarchguy
Copy link
Member

Beautiful merge request. I can only really nitpick at one or two small things. The tests are good and the code is good. I really appreciate the hard work you put into that merge.

I think the way we are handling config stuff in the database is getting a bit big. Controllable though, just something we may need to keep an eye on in the future.

@mprahl
Copy link
Member Author

mprahl commented Nov 11, 2016

@thatarchguy thoughts on the last commit?

@thatarchguy
Copy link
Member

LGTM

👍

@thatarchguy thatarchguy merged commit 7b16acd into master Nov 11, 2016
@mprahl mprahl deleted the ldap3-migration branch November 12, 2016 03:08
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.

2 participants

Comments