# Path: zoe_lib/config.py
# def get_conf() -> Namespace:
#     """Returns the conf singleton."""
#     return _CONF


import logging
    import ldap
    import ldap.sasl
import zoe_api.auth.base
import zoe_api.exceptions
from zoe_lib.config import get_conf
try:
except ImportError:
    ldap = None
    LDAP_AVAILABLE = False
else:
    LDAP_AVAILABLE = True



log = logging.getLogger(__name__)


class LDAPAuthenticator:
    """A simple LDAP authenticator."""

    def __init__(self, conf, sasl):
        self.connection = ldap.initialize(conf.ldap_server_uri)
        self.base_dn = conf.ldap_base_dn
        self.sasl = sasl
        self.connection.protocol_version = ldap.VERSION3
        if self.sasl:
            self.sasl_auth = ldap.sasl.sasl({}, 'GSSAPI')

    def auth(self, username, password):
        """Authenticate the user or raise an exception."""
        search_filter = "uid=" + username
        try:
            if self.sasl:
                self.connection.sasl_interactive_bind_s('', self.sasl_auth)
            else:

# Path: zoe_lib/config.py
# def get_conf() -> Namespace:
#     """Returns the conf singleton."""
#     return _CONF


# Path: zoe_api/auth/ldap.py
import logging
    import ldap
    import ldap.sasl
import zoe_api.auth.base
import zoe_api.exceptions
from zoe_lib.config import get_conf

try:
except ImportError:
    ldap = None
    LDAP_AVAILABLE = False
else:
    LDAP_AVAILABLE = True



log = logging.getLogger(__name__)


class LDAPAuthenticator:
    """A simple LDAP authenticator."""

    def __init__(self, conf, sasl):
        self.connection = ldap.initialize(conf.ldap_server_uri)
        self.base_dn = conf.ldap_base_dn
        self.sasl = sasl
        self.connection.protocol_version = ldap.VERSION3
        if self.sasl:
            self.sasl_auth = ldap.sasl.sasl({}, 'GSSAPI')

    def auth(self, username, password):
        """Authenticate the user or raise an exception."""
        search_filter = "uid=" + username
        try:
            if self.sasl:
                self.connection.sasl_interactive_bind_s('', self.sasl_auth)
            else:

                self.connection.bind_s(get_conf().ldap_bind_user, get_conf().ldap_bind_password)