Issue
I connected my Flask application with an Active Directory Server using ms_active_directory library. Is it possible to delete an user account? Something like this:
import os
from ms_active_directory import ADDomain
domain = ADDomain(os.environ["domain"])
session = domain.create_session_as_user(os.environ["userAd"], os.environ["passAd"])
user = session.find_user_by_sam_name('John Liniker')
I would like to delete this user account. The object session
only has methods to disable account or remove users from groups.
How can I delete this user account? Is it possible?
I was expecting something like:
if not session.remove_account(user):
raise Exception(resBibliotecaPassAD["messageError"])
Solution
I researched and discovered that there is no such implementation in the ms_active_directory library, however there is pull request #54 (implement delete for users and groups) that will include this and other new features.
When analyzing the pull request, I was able to delete the user as follows:
import ms_active_directory.environment.ldap.ldap_format_utils as ldap_utils
object_dn = ldap_utils.construct_object_distinguished_name(user.common_name, user.location, user.domain.domain)
result_delete = session.ldap_connection.delete(object_dn)[0]
Answered By - pvfreitas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.