How to use sasl - 10 common examples

To help you get started, we’ve selected a few sasl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thisismedium / message-db / mdb / db / tests.py View on Github external
def setUp(self):
        import logging

        sasl.log.setLevel(logging.CRITICAL)
        self.zs = init('test', 'memory:', create=self._create)
github thisismedium / message-db / mdb / db / tests.py View on Github external
def _client(self, user, pwd):
        return sasl.SimpleAuth(
            sasl.DigestMD5Password,
            {},
            lambda: user,
            lambda: pwd,
            lambda: authenticator().service_type(),
            lambda: authenticator().host()
        )
github thisismedium / message-db / mdb / db / tests.py View on Github external
def _client(self, user, pwd):
        return sasl.SimpleAuth(
            sasl.DigestMD5Password,
            {},
            lambda: user,
            lambda: pwd,
            lambda: authenticator().service_type(),
            lambda: authenticator().host()
        )
github thisismedium / message-db / mdb / db / tests.py View on Github external
def _login(self, user, pwd, mech=None):
        client = self._client(user, pwd)
        mech = mech or sasl.DigestMD5
        return self._negotiate(mech(authenticator()), mech(client))
github cloudera / hue / desktop / core / src / desktop / lib / thrift_util.py View on Github external
def sasl_factory():
      saslc = sasl.Client()
      saslc.setAttr("host", str(conf.host))
      saslc.setAttr("service", str(conf.kerberos_principal))
      if conf.mechanism == 'PLAIN':
        saslc.setAttr("username", str(conf.username))
        saslc.setAttr("password", str(conf.password)) # Defaults to 'hue' for a non-empty string unless using LDAP
      else:
        saslc.setAttr("maxbufsize", SASL_MAX_BUFFER.get())
      saslc.init()
      return saslc
    transport = TSaslClientTransport(sasl_factory, conf.mechanism, mode)
github cloudera / impyla / impala / _thrift_api.py View on Github external
def sasl_factory():
            sasl_client = sasl.Client()
            sasl_client.setAttr('host', host)
            sasl_client.setAttr('service', kerberos_service_name)
            if auth_mechanism.upper() in ['PLAIN', 'LDAP']:
                sasl_client.setAttr('username', user)
                sasl_client.setAttr('password', password)
            sasl_client.init()
            return sasl_client
    except ImportError:
github cloudera / hue / desktop / core / ext-py / kazoo-2.0 / kazoo / protocol / connection.py View on Github external
def _authenticate_with_sasl(self, host, timeout):
        saslc = sasl.Client()
        saslc.setAttr('host', str(host))
        saslc.setAttr('service', str(self.sasl_server_principal))
        saslc.init()

        ret, chosen_mech, initial_response = saslc.start('GSSAPI')
        if not ret:
            raise SaslException(saslc.getError())

        response = initial_response

        xid = 0

        while True:
            xid += 1

            request = SASL(response)
github cloudera / impyla / impala / _rpc / hiveserver2.py View on Github external
def sasl_factory():
        sasl_client = sasl.Client()
        sasl_client.setAttr("host", host)
        if use_ldap:
            sasl_client.setAttr("username", ldap_user)
            sasl_client.setAttr("password", ldap_password)
        else:
            sasl_client.setAttr("service", kerberos_service_name)
        sasl_client.init()
        return sasl_client
github spotify / snakebite / snakebite / rpc_sasl.py View on Github external
def connect(self):
        # use service name component from principal
        service = re.split('[\/@]', str(self.hdfs_namenode_principal))[0]

        negotiate = RpcSaslProto()
        negotiate.state = 1
        self._send_sasl_message(negotiate)

        self.sasl = sasl.Client()
        self.sasl.setAttr("service", service)
        self.sasl.setAttr("host", self._trans.host)
        self.sasl.init()

        # do while true
        while True:
          res = self._recv_sasl_message()
          # TODO: check mechanisms
          if res.state == 1:
            mechs = []
            for auth in res.auths:
                mechs.append(auth.mechanism)

            log.debug("Available mechs: %s" % (",".join(mechs)))
            s_mechs = str(",".join(mechs))
            ret, chosen_mech, initial_response = self.sasl.start(s_mechs)
github devinstevenson / pure-transport / puretransport / factory.py View on Github external
def sasl_factory():
            sasl_client = sasl.Client()
            sasl_client.setAttr('host', host)
            if sasl_auth == 'GSSAPI':
                sasl_client.setAttr('service', kerberos_service_name)
            elif sasl_auth == 'PLAIN':
                sasl_client.setAttr('username', username)
                sasl_client.setAttr('password', password)
            else:
                raise AssertionError
            sasl_client.init()
            return sasl_client