Esempio n. 1
0
    def __init__(self, options):
        self.options = options
        self.src_options = options['source'].get()
        self.tgt_options = options['target'].get()
        self.attribute_mapping = options['attribute_mapping'].get()
        self.user_rdn = options['user_rdn'].get()
        self.src_auto_bind = (AUTO_BIND_TLS_BEFORE_BIND
                              if self.src_options.get('start_tls', False) else
                              AUTO_BIND_DEFAULT)
        self.tgt_auto_bind = (AUTO_BIND_TLS_BEFORE_BIND
                              if self.tgt_options.get('start_tls', False) else
                              AUTO_BIND_DEFAULT)

        if "directory_type" not in self.src_options:
            self.src_options["directory_type"] = "AD"
        if self.src_options["directory_type"] not in supported_directory_types:
            raise ValueError("Source directory type not supported")

        self.src_server = Server(
            self.src_options['server'],
            port=self.src_options['port'],
            use_ssl=self.src_options.get('use_ssl', False),
            get_info=ALL,
        )
        with Connection(
                self.src_server,
                self.src_options['bind_dn'],
                self.src_options['bind_password'],
                auto_bind=self.src_auto_bind,
        ) as conn:
            conn.bind()
            if not conn.bind():
                raise LDAPBindError("Could not connect to source")

        self.tgt_server = Server(
            self.tgt_options['server'],
            port=self.tgt_options['port'],
            use_ssl=self.tgt_options.get('use_ssl', False),
            get_info=ALL,
        )
        with Connection(
                self.tgt_server,
                self.tgt_options['bind_dn'],
                self.tgt_options['bind_password'],
                auto_bind=self.tgt_auto_bind,
        ) as conn:
            if not conn.bind():
                raise LDAPBindError("Could not connect to target")

        self._src_users = None
        self._tgt_users = None
Esempio n. 2
0
    def test_bind_ldap_bad_creds(self, fake_ldap3):
        """_bind_ldap returns 401 when a invalid user creds are supplied"""
        fake_ldap3.Connection.side_effect = LDAPBindError("testing")

        _, status = token._bind_ldap('bob', 'iLoveCats', log=MagicMock())

        self.assertEqual(status, 401)
Esempio n. 3
0
 def __init__(self):
     self.s = Server(host=self._server_name,
                     port=self._port,
                     use_ssl=False,
                     get_info='ALL')
     self.c = Connection(self.s, user=self._user, password=self._password)
     if not self.c.bind():
         raise LDAPBindError('bind() error')
Esempio n. 4
0
 def test_bind_dn(self):
     try:
         self._test_bind_dn()
     except LDAPUserNameIsMandatoryError as e:
         error = _('Please enter Bind DN: {}').format(e)
     except LDAPPasswordIsMandatoryError as e:
         error = _('Please enter Password: {}').format(e)
     except LDAPInvalidDnError as e:
         error = _('Please enter correct Bind DN and Password: {}').format(e)
     except Exception as e:
         error = _('Unknown error: {}').format(e)
     else:
         return
     raise LDAPBindError(error)