LDAP – lightweight directory access)

lsf – LDAP session factory

Module lsf defines LdapSessionFactory class which is central point for your LDAP database access.

Analogy to summer.sf.

class summer.lsf.LdapConnectionProvider(base: str)[source]

Bases: object

Class to be used as based for providing LDAP session.

See default implementation in summer.lsf.DefaultLdapConnectionProvider.

__init__(base: str)[source]

Initialize self. See help(type(self)) for accurate signature.

property server

LDAP server property.

Returns

LDAP server instance

Return type

ldap3.Server

property base

LDAP base property – convenience value defining portion of a LDAP subtree of interest.

Returns

Optional property, can be left empty; LDAP base DN for a subtree of interest to be used by queries

Return type

str

create_connection() → ldap3.core.connection.Connection[source]

Each call produces a new connection.

Returns

new instance of LDAP connection

Return type

ldap3.Connection

__weakref__

list of weak references to the object (if defined)

class summer.lsf.DefaultLdapConnectionProvider(host: str, port: int, login: str, password: str, base: str)[source]

Bases: summer.lsf.LdapConnectionProvider

__init__(host: str, port: int, login: str, password: str, base: str)[source]
Parameters
  • host (str) – LDAP base dn

  • port (int) – server port

  • login (str) – server login

  • password (str) – server password in clear text

  • base (str) – see LdapConnectionProvider.base()

property server

LDAP server property.

Returns

LDAP server instance

Return type

ldap3.Server

create_connection() → ldap3.core.connection.Connection[source]

Each call produces a new connection.

Returns

new instance of LDAP connection

Return type

ldap3.Connection

class summer.lsf.LdapSessionFactory(ldap_connection_provider: summer.lsf.LdapConnectionProvider)[source]

Bases: object

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

class Local(ldap_connection_provider: summer.lsf.LdapConnectionProvider)[source]

Bases: _thread._local

Thread local session wrapper.

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

__init__(ldap_connection_provider: summer.lsf.LdapConnectionProvider)[source]

Initialize self. See help(type(self)) for accurate signature.

property base

Delegates to LdapConnectionProvider.base().

property active

Get status of current ldap session.

Returns

True if session is bound, False otherwise.

Return type

bool

__init__(ldap_connection_provider: summer.lsf.LdapConnectionProvider)[source]

Creates LdapSessionFactory instance.

Parameters
property base

Delegates to LdapSessionFactory.Local.base()

property session

Get current thread-local ldap3 session wrapper (creating one, if non-existent).

Returns

existing or just created ldap3 session wrapper

Return type

LdapSessionFactory.Local

property connection

Delegates to LdapSessionFactory.Local.connection()

__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 important properties:

  1. LdapDao.connection() property referencing ldap3.Connection

  2. LdapDao.base() property referencing summer.lsf.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() property and base LDAP dn value through base() property.

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

Creates LdapDao instance.

Parameters

ldap_session_factory (LdapSessionFactory) – ldap session factory to use

property connection

Delegates to summer.lsf.LdapSessionFactory.connection().

property session

Compatibility alias for LdapDao.connection

property base

Delegates to summer.lsf.LdapSessionFactory.base().

__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 LdapEntityDao.

Parameters
  • ldap_session_factory (LdapSessionFactory) – ldap session factory to use

  • clazz (type) – reference to class type

property clazz

Get class type for this dao.

Returns

class for this EntityDao

Return type

type