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: object

Thread safe ldap3 session provider. Analogy to summer.sf.SessionFactory.

class Local(base: str)[source]

Bases: _thread._local

Thread local session wrapper.

There is an active ldap3.Connection instance in ldap_session attribute.

LdapSessionFactory.__init__(hostname: str, port: int, base: str, login: str, passwd: str)[source]

Creates LdapSessionFactory instance.

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)

ldapdao – LDAP data access object support

Provides LDAP DAO support. Analogy to summer.dao module.

Base LdapDao provides access to virtual important attributes:

  1. LdapDao.session attribute referencing ldap3.Connection
  2. LdapDao.base attribute referencing :LdapSessionFactory.base dn value (useful for creating LDAP queries)
class summer.ldapdao.LdapDao(ldap_session_factory: summer.lsf.LdapSessionFactory)[source]

Bases: object

Base DAO class. Analogy to summer.dao.Dao class.

Provides safe access to thread bound session/connection through session attribute and base LDAP dn value through base attribute.

__init__(ldap_session_factory: summer.lsf.LdapSessionFactory)[source]

Creates LdapDao instance.

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.LdapDao

Base 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: object

Callback object called from within a LdapWrapper. Analogy to summer.tx.TransactionCallback class.

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 *args and **kwargs magic.

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: object

Wraps the code it executes inside a LDAP session/connection. Analogy to summer.tx.TransactionWrapper class.

Caller provides a callback object (LdapCallback instance) to be executed inside a session/connection; it gets passed in the current thread-bound LdapSessionFactory.Local instance (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 LdapCallback instance) 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 LdapAdvice and LdapProxy.

Methods decorated with ldapaop() can be run within a LDAP session/connection if wrapped in LdapProxy.

Intended use case for this decorator is to decorate summer.ldapdao.LdapEntityDao methods and then access current ldap3 session/connection by using summer.ldapdao.LdapDao.session from 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.AroundMethodAdvice

Together with transactional() decorator forms a transaction aspect. Analogy to summer.txaop.TransactionAdvice.

Advice gets invoked if method is marked with ldapaop() and if object is wrapped in LdapProxy.

__init__(method: method, ldap_session_factory: summer.lsf.LdapSessionFactory)[source]

Creates LdapAdvice instance.

Parameters:
  • method (types.MethodType) – instance method marked by ldapaop() decorator
  • ldap_session_factory (LdapSessionFactory) – ldap session factory to be used
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.Proxy

Intercepts method invocations on target object with ldap session/connection logic.

It either calls the target object’s method directly or invokes the LdapAdvice if the method is marked by ldapaop().

__init__(target: object, ldap_session_factory: summer.lsf.LdapSessionFactory=None)[source]

Creates the LdapProxy instance.

Searches the target object for ldapaop() decorated methods. It creates a LdapAdvice object for each method found. Invocation of such a method means invoking a LdapAdvice object 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 for ldap_session_factory attribute which is used instead