LDAP – lightweight directory access)¶
lsf – LDAP session factory¶
Module lsf defines LdapSessionFactory class which is
central point for your LDAP database access.
Ananalogy to summer.sf.
-
class
summer.lsf.LdapSessionFactory(hostname: str, port: int, base: str, login: str, passwd: str)[source]¶ Bases:
objectThread safe ldap3 session provider. Analogy to
summer.sf.SessionFactory.-
class
Local(base: str)[source]¶ Bases:
_thread._localThread local session wrapper.
There is an active
ldap3.Connectioninstance inldap_sessionattribute.
-
LdapSessionFactory.__init__(hostname: str, port: int, base: str, login: str, passwd: str)[source]¶ Creates
LdapSessionFactoryinstance.Parameters: - hostname (str) – server hostname
- port (int) – server port
- base (str) – LDAP base dn
- login (str) – server login
- passwd (str) – server password in clear text
-
LdapSessionFactory.get_session()[source]¶ Get current thread-local ldap3 session wrapper (creating one, if non-existent).
Returns: existing or just created ldap3 session wrapper Return type: LdapSessionFactory.Local
-
LdapSessionFactory.get_ldap_session() → ldap3.core.connection.Connection[source]¶ Get current ldap3 session.
See
get_session()method.Returns: existing of just created ldap3 session. Return type: ldap3.Connection
-
LdapSessionFactory.__weakref__¶ list of weak references to the object (if defined)
-
class
ldapdao – LDAP data access object support¶
Provides LDAP DAO support. Analogy to summer.dao module.
Base LdapDao provides access to virtual important attributes:
LdapDao.sessionattribute referencingldap3.ConnectionLdapDao.baseattribute referencing:LdapSessionFactory.basedn value (useful for creating LDAP queries)
-
class
summer.ldapdao.LdapDao(ldap_session_factory: summer.lsf.LdapSessionFactory)[source]¶ Bases:
objectBase DAO class. Analogy to
summer.dao.Daoclass.Provides safe access to thread bound session/connection through
sessionattribute and base LDAP dn value throughbaseattribute.-
__init__(ldap_session_factory: summer.lsf.LdapSessionFactory)[source]¶ Creates
LdapDaoinstance.Parameters: ldap_session_factory (LdapSessionFactory) – ldap session factory to use
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
summer.ldapdao.LdapEntityDao(ldap_session_factory: summer.lsf.LdapSessionFactory, clazz: type)[source]¶ Bases:
summer.ldapdao.LdapDaoBase DAO class for persistent classes subclassed from
summer.domain.LdapEntity.-
__init__(ldap_session_factory: summer.lsf.LdapSessionFactory, clazz: type)[source]¶ Creates
EntityLdapDao.Parameters: - ldap_session_factory (LdapSessionFactory) – ldap session factory to use
- clazz (type) – reference to class type
-
lx – LDAP programmatic session management¶
Module lx contains support for programmatic ldap session/connection
management. Analogy to summer.tx module.
Declarative ldap session management is defined in summer.lxaop.
-
class
summer.lx.LdapCallback[source]¶ Bases:
objectCallback object called from within a
LdapWrapper. Analogy tosummer.tx.TransactionCallbackclass.-
lxrun(session: summer.lsf.LdapSessionFactory.Local, *args, **kwargs)[source]¶ Executed inside ldap session/connection.
This is a callback method. It is discouraged to use the
*argsand**kwargsmagic.Parameters: session (LdapSessionFactory.Local) – ldap3 session/connection Returns: whatever you want to get returned Return type: object
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
summer.lx.LdapWrapper(ldap_session_factory: summer.lsf.LdapSessionFactory)[source]¶ Bases:
objectWraps the code it executes inside a LDAP session/connection. Analogy to
summer.tx.TransactionWrapperclass.Caller provides a callback object (
LdapCallbackinstance) to be executed inside a session/connection; it gets passed in the current thread-boundLdapSessionFactory.Localinstance (which can access ldap3 session).It participates in current session/connection if there is one active or creates a new one.
-
execute(callback: summer.lx.LdapCallback, *args, **kwargs)[source]¶ Runs the callback provided (a
LdapCallbackinstance) in a new ldap session.Whatever other arguments are provided, they are passed to callback.
Parameters: callback (LdapCallback) – callback to be executed Returns: whatever the callback returns Return type: object
-
__weakref__¶ list of weak references to the object (if defined)
-
lxaop – LDAP declarative session management¶
Declarative LDAP session/connection management. Analogy to
summer.txaop module.
-
summer.lxaop.ldapaop(func: function)[source]¶ Method decorator marking method as transactional. Analogy to
summer.txaop.transactional().Use together with
LdapAdviceandLdapProxy.Methods decorated with
ldapaop()can be run within a LDAP session/connection if wrapped inLdapProxy.Intended use case for this decorator is to decorate
summer.ldapdao.LdapEntityDaomethods and then access current ldap3 session/connection by usingsummer.ldapdao.LdapDao.sessionfrom within the DAO method. Thus you can access ldap3 session/connection (and manipulate data), and still have the transaction boundaries defined on top of your business methods.Parameters: func (types.FunctionType) – function to be decorated
-
class
summer.lxaop.LdapAdvice(method: method, ldap_session_factory: summer.lsf.LdapSessionFactory)[source]¶ Bases:
summer.aop.AroundMethodAdviceTogether with
transactional()decorator forms a transaction aspect. Analogy tosummer.txaop.TransactionAdvice.Advice gets invoked if method is marked with
ldapaop()and if object is wrapped inLdapProxy.-
__init__(method: method, ldap_session_factory: summer.lsf.LdapSessionFactory)[source]¶ Creates
LdapAdviceinstance.Parameters: - method (types.MethodType) – instance method marked by
ldapaop()decorator - ldap_session_factory (LdapSessionFactory) – ldap session factory to be used
- method (types.MethodType) – instance method marked by
-
around(*args, **kwargs)[source]¶ Wraps the target method invocation within a ldap session/connection. If any exception is raised it gets re-thrown, see
summer.lx.LdapWrapper.
-
-
class
summer.lxaop.LdapProxy(target: object, ldap_session_factory: summer.lsf.LdapSessionFactory=None)[source]¶ Bases:
summer.aop.ProxyIntercepts method invocations on target object with ldap session/connection logic.
It either calls the target object’s method directly or invokes the
LdapAdviceif the method is marked byldapaop().-
__init__(target: object, ldap_session_factory: summer.lsf.LdapSessionFactory=None)[source]¶ Creates the
LdapProxyinstance.Searches the target object for
ldapaop()decorated methods. It creates aLdapAdviceobject for each method found. Invocation of such a method means invoking aLdapAdviceobject instead, wrapping the call with ldap session/connection.Parameters: - target (object) – any object that is searched for ldap methods
- ldap_session_factory (LdapSessionFactory) – ldap session factory
to be used; if
None, target object is searched forldap_session_factoryattribute which is used instead
-