cfelder / ldap3-orm Goto Github PK
View Code? Open in Web Editor NEWldap3-orm, object-relational mapping for ldap3
License: GNU Lesser General Public License v3.0
ldap3-orm, object-relational mapping for ldap3
License: GNU Lesser General Public License v3.0
Hi,
When I print an EntryType I created I get the following output
OBJ : top, person, organizationalPerson, inetOrgPerson, educationnationale, FrEduFederation
AUX : <None>
OID: top (Abstract) 2.5.6.0, person (Structural) 2.5.6.6, top (Abstract) 2.5.6.0, organizationalPerson (Structural) 2.5.6.7, person (Structural) 2.5.6.6, top (Abstract) 2.5.6.0, inetOrgPerson (Structural) 2.16.840.1.113730.3.2.2, organizationalPerson (Structural) 2.5.6.7, person (Structural) 2.5.6.6, top (Abstract) 2.5.6.0, educationnationale (Structural) 1.3.6.1.4.1.20326.20.999.2.1, top (Abstract) 2.5.6.0, FrEduFederation (Auxiliary) FrEduFederation-oid, top (Abstract) 2.5.6.0
MUST: cn, objectClass, sn
MAY : FrEduAca, FrEduCodCom, FrEduDatFin, FrEduFonctAdm, FrEduGestResp, FrEduOTP, FrEduOTPResp, FrEduOTPinfo1, FrEduOTPinfo2, FrEduResDel, FrEduRne, FrEduRneGeres, FrEduRneResp, FrEduUrlRetour, adminou, audio, businessCategory, carLicense, circonscription, clepublique, codaca, codecivilite, codenature, dateFF, datenaissance, departmentNumber, dermaj, description, destinationIndicator, diffusion, discim, discipline, displayName, employeeNumber, employeeType, facsimileTelephoneNumber, finfonction, fonctm, gestion, gestion1, givenName, grade, grpdisc, homePhone, homePostalAddress, initials, internationaliSDNNumber, jpegPhoto, l, labeledUri, mail, mailmondossier, manager, mobile, mondossier, nompatro, o, ou, pager, photo, physicalDeliveryOfficeName, postOfficeBox, postalAddress, postalCode, preferredDeliveryMethod, preferredLanguage, profilbv, registeredAddress, rne, rneextract, roomNumber, secretary, seeAlso, st, street, telephoneNumber, teletexTerminalIdentifier, telexNumber, textelibre, title, typensi, uid, userCertificate, userPKCS12, userPassword, userSMIMECertificate, x121Address, x500UniqueIdentifier
So we can see that the attribute FrEduDatFin is not mandatory (MAY)
But when I try to create a user without this attribute, I get the following Error
File "ProxiRHManager/cli.py", line 122, in <module>
main()
File "/home/julien/anaconda3/lib/python3.7/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/julien/anaconda3/lib/python3.7/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/julien/anaconda3/lib/python3.7/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/julien/anaconda3/lib/python3.7/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "ProxiRHManager/cli.py", line 112, in main
ldap_directory.test()
File "/home/julien/WorkSpace/ProxiRHManager/models/directory.py", line 277, in test
for u in self.iterate_users(f1 & f2):
File "/home/julien/WorkSpace/ProxiRHManager/models/directory.py", line 190, in iterate_users
yield self.user_entry_type(**entry.entry_attributes_as_dict)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3_orm/entry.py", line 387, in __call__
entry.__init__(**kwargs)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3_orm/entry.py", line 243, in __init__
self._create_attribute_or_parameter(attrdef, v)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3_orm/entry.py", line 310, in _create_attribute_or_parameter
self._create_attribute(attrdef, value)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3_orm/entry.py", line 295, in _create_attribute
self._create(attrdef, value, Attribute, self._state.attributes)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3_orm/entry.py", line 288, in _create
attribute.value))
TypeError: Validation failed for attribute 'FrEduDatFin' and value 'None'
Hi,
Using code below, I get no entry in reader, what I don't get is that bind status change before and after calling the Reader search method. Is that normal? I'm not sure it is the cause of no entry result, but I suspect it is as anonymous search retrieve schema but cannot retrieve users. Thanks.
from config import connection, user_entry_type, base_dn, user_search_filter
def search_users():
reader = Reader(
connection,
user_entry_type._objDef,
base_dn,
user_search_filter
)
reader.search(attributes=ALL_ATTRIBUTES)
return reader
print(connection)
r = search_users()
print(connection)
ldap://id-devops-7.in.ac-orleans-tours.fr:12154 - cleartext - user: Directory manager - lazy - deferred bind - deferred open - <no socket> - tls not started - not listening - RestartableStrategy - internal decoder
ldap://id-devops-7.in.ac-orleans-tours.fr:12154 - cleartext - user: Directory manager - lazy - unbound - open - <local: 172.30.146.185:47662 - remote: 172.30.159.116:12154> - tls not started - listening - RestartableStrategy - internal decoder
Hi, I've created an EntryType with this code
from ldap3_orm import EntryType
from config.connection import CONNECTION,BASE_DN
proxirhUser = EntryType(
'uid={uid},ou=people,%s' % (BASE_DN),
['person','organizationalPerson','inetOrgPerson','educationnationale'],
CONNECTION
)
Works perfectly, I can add thousands of users like this with the add function.
When I create an instance of proxiUser in a script, it has several methods that I can't use, is there a way to avoid that? I can't use the entry_to_ldif() for example
user1 = proxiUser(**data) # data is a dict, not important
print(user1.entry_to_ldif())
Raises the error
Traceback (most recent call last):
File "<ipython-input-24-8a6fd88903be>", line 1, in <module>
ldap_user0.entry_to_ldif()
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/abstract/entry.py", line 339, in entry_to_ldif
ldif_lines = operation_to_ldif('searchResponse', [self._state.response], all_base64, sort_order=sort_order)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/protocol/rfc2849.py", line 209, in operation_to_ldif
lines = search_response_to_ldif(entries, all_base64, sort_order)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/protocol/rfc2849.py", line 127, in search_response_to_ldif
if 'dn' in entry:
TypeError: argument of type 'NoneType' is not iterable
Hello,
I've been trying to use ldap3-orm in a flask app to read and modify ldap entries from a live ldap server.
I initialise the object:
UserDef = ObjectDef(["posixAccount","PureFTPdUser"], conn)
search_base = base_dn
r = Reader(conn, UserDef, search_base )
users = r.search() # Users are correctly returned (can see in the debugger)
But when an attribute has no value, i get
File "C:\Python37\lib\site-packages\ldap3\abstract\entry.py", line 196, in __getattr__
raise LDAPCursorError(error_message)
ldap3.core.exceptions.LDAPCursorError: attribute '__getstate__' not found
when i try to convert the data to send the data back using
return pickle.dumps(users) if users is not None else ('Not found', 404)
Is this an issue with upstream ldap3 like #2 or am I doing something wrong ?
Thanks in advance for your help.
Hi,
I created a reader, checked all info, also checked direct connection with Apache Directory studio.
The Reader says LAST OPERATION FAILED. How can I check what went wrong?
Thanks
I put *** to hide some words but the real code is correct.
<models.directory.LdapDirectory object at 0x7f2d4bfacc88>
CURSOR : Reader
CONN : ldap://***.fr:12154 - cleartext - user: Directory manager - lazy - unbound - open - <local: 172.30.146.185:35824 - remote: 172.30.159.116:12154> - tls not started - listening - RestartableStrategy - internal decoder
DEFS : top, person, organizationalPerson, inetOrgPerson, educationnationale
ATTRS : [***]
BASE : 'ou=***,ou=***,o=gouv,c=fr' [SUB]
FILTER : '(&(objectClass=top)(objectClass=person)(objectClass=organizationalPerson)(objectClass=inetOrgPerson)(objectClass=***))'
ENTRIES: 0 [executed at: 2019-10-24T14:46:44.703392]
LAST OPERATION FAILED [1 failure at operation 0]
Hi,
It's not a real issue, we use your Framework to make validation of entries before exporting an ldif. With a code that looks like this
ldif_connection = Connection(server=None,client_strategy='LDIF')
user_entry_type = EntryType('...') #Put whatever data here, dn is a template using uid attribute
for user_data in users_data: # users_data is a list of dict containing more than 10 attributes
user = user_entry_type(user_data) # It takes about 0.001 for each user
ldif_connection.add( # This too takes about 0.001 for each user
user.entry_dn,
user.object_classes,
user.entry_attributes_as_dict
)
We found that each of the two operations in the loop cost 0.001 s.
Are there some parameters we could use to speed up one of those operations?
Is it possible to make it much faster with more CPU or RAM?
Can multprocessing help here?
Thanks.
Hi, Some problem here, looks like one method makes infinite loop or waits for a response that never comes, here is the code, did I forget something?
from ldap3_orm import EntryType
from ldap3_orm.config import config
from ldap3_orm.connection import conn
FrEduCtUser = EntryType(
'uid={uid},'+ config.base_dn,
['person','organizationalPerson','inetOrgPerson','FrEduCtPerson'],
conn
)
class FrEduCtLdapSession(object):
connection = conn
def getObjectClassesAndAttributes(self,entry):
attributes = entry.entry_attributes_as_dict
object_classes = attributes['objectClass']
del attributes['objectClass']
return object_classes,attributes
def addUser(self,user):
object_classes,attributes = self.getObjectClassesAndAttributes(user)
return self.connection.add(
user.entry_dn,
object_classes,
attributes
)
from I2HM_Console import FrEduCtUser, FrEduCtPolicy, FrEduCtLdapSession
from ldap3 import HASHED_SALTED_SHA
from ldap3.utils.hashed import hashed
session = FrEduCtLdapSession()
bozo = FrEduCtUser(
uid='bleclown',
givenName='Bozo',
sn='Le Clown',
cn='Bozo Le Clown',
userPassword=hashed(HASHED_SALTED_SHA, 'Ohlalalala')
)
b1 = session.addUser(bozo)
Traceback (most recent call last):
File "<ipython-input-24-10fcec10856d>", line 1, in <module>
runfile('/home/julien/WorkSpace/LDAP/LdapConsole/test.py', wdir='/home/julien/WorkSpace/LDAP/LdapConsole')
File "/home/julien/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "/home/julien/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/julien/WorkSpace/LDAP/LdapConsole/test.py", line 24, in <module>
b1 = session.addUser(bozo)
File "/home/julien/WorkSpace/LDAP/LdapConsole/I2HM_Console/tools/session.py", line 19, in addUser
attributes
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/core/connection.py", line 936, in add
response = self.post_send_single_response(self.send('addRequest', request, controls))
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/strategy/sync.py", line 121, in post_send_single_response
responses, result = self.get_response(message_id)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/strategy/base.py", line 325, in get_response
responses = self._get_response(message_id)
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/strategy/sync.py", line 157, in _get_response
responses = self.receiving()
File "/home/julien/anaconda3/lib/python3.7/site-packages/ldap3/strategy/sync.py", line 82, in receiving
data = self.connection.socket.recv(self.socket_size)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.