How to use the ldaptor.protocols.ldap.distinguishedname.DistinguishedName function in ldaptor

To help you get started, we’ve selected a few ldaptor 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 twisted / ldaptor / docs / source / examples / ldap_parallelsearch.py View on Github external
l=[]
    for connection in xrange(0, numOfConnections):
        c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
        d=c.connectAnonymously(base, serviceLocationOverrides)

        d.addCallback(_search, base, connection, numOfSearches)
        d.addErrback(error)
        l.append(d)
    dl=defer.DeferredList(l)
    dl.addBoth(lambda dummy: reactor.stop())
    reactor.run()
    sys.exit(exitStatus)

if __name__ == "__main__":
    base='dc=example,dc=com'
    main(base=distinguishedname.DistinguishedName(base),
         serviceLocationOverrides={base: ('localhost', None)},
         numOfConnections=5,
         numOfSearches=10)
github twisted / ldaptor / docs / source / examples / addressbook / 03_webapp / addressbook.py View on Github external
def __init__(self,
                 baseDN,
                 serviceLocationOverrides=None):
        self.baseDN = distinguishedname.DistinguishedName(baseDN)
        self.serviceLocationOverrides = {}
        if serviceLocationOverrides is not None:
            for k,v in serviceLocationOverrides.items():
                dn = distinguishedname.DistinguishedName(k)
                self.serviceLocationOverrides[dn]=v
github twisted / ldaptor / ldaptor / protocols / ldap / ldapconnector.py View on Github external
def __init__(self, reactor, dn, factory,
                 overrides=None, bindAddress=None):
        if not isinstance(dn, distinguishedname.DistinguishedName):
            dn = distinguishedname.DistinguishedName(stringValue=dn)
        if overrides is None:
            overrides = {}
        self.override = self._findOverRide(dn, overrides)

        domain = dn.getDomainName() or ''
        SRVConnector.__init__(self, reactor,
                  'ldap', domain, factory,
                  connectFuncKwArgs={'bindAddress': bindAddress})
github twisted / ldaptor / ldaptor / apps / webui / gadget.py View on Github external
def locateChild(self, ctx, segments):
        ret = super(LdaptorWebUIGadget, self).locateChild(ctx, segments)
        if ret != rend.NotFound:
            return ret

        path = segments[0]
        unquoted=uriUnquote(path)
        try:
            dn = distinguishedname.DistinguishedName(stringValue=unquoted)
        except distinguishedname.InvalidRelativeDistinguishedName, e:
            # TODO There's no way to throw a FormException at this stage.
            u = url.URL.fromContext(ctx)

            # TODO protect against guard bug, see
            # http://divmod.org/users/roundup.twistd/nevow/issue74
            u = u.child('')

            # TODO freeform_post!configurableName!methodName
            u.add('basedn', path)
            return u, []

        r=LdaptorWebUIGadget2(baseObject=dn)
        ctx.remember(self.config, interfaces.ILDAPConfig)
        ctx.remember(dn, iwebui.ICurrentDN)
        return r, segments[1:]
github twisted / ldaptor / ldaptor / protocols / ldap / ldapserver.py View on Github external
def handle_LDAPSearchRequest(self, request, controls, reply):
        self.checkControls(controls)

        if (request.baseObject == b''
                and request.scope == pureldap.LDAP_SCOPE_baseObject
                and request.filter == pureldap.LDAPFilter_present('objectClass')):
            return self.getRootDSE(request, reply)
        dn = distinguishedname.DistinguishedName(request.baseObject)
        root = interfaces.IConnectedLDAPEntry(self.factory)
        d = root.lookup(dn)
        d.addCallback(self._cbSearchGotBase, dn, request, reply)
        d.addErrback(self._cbSearchLDAPError)
        d.addErrback(defer.logError)
        d.addErrback(self._cbSearchOtherError)
        return d
github twisted / ldaptor / ldaptor / config.py View on Github external
def __init__(self,
                 baseDN=None,
                 serviceLocationOverrides=None,
                 identityBaseDN=None,
                 identitySearch=None):
        if baseDN is not None:
            baseDN = distinguishedname.DistinguishedName(baseDN)
            self.baseDN = baseDN
        self.serviceLocationOverrides = {}
        if serviceLocationOverrides is not None:
            for k,v in serviceLocationOverrides.items():
                dn = distinguishedname.DistinguishedName(k)
                self.serviceLocationOverrides[dn]=v
        if identityBaseDN is not None:
            identityBaseDN = distinguishedname.DistinguishedName(identityBaseDN)
            self.identityBaseDN = identityBaseDN
        if identitySearch is not None:
            self.identitySearch = identitySearch
github twisted / ldaptor / docs / source / examples / addressbook / 02_script / addressbook.py View on Github external
def main():
    import sys
    from twisted.python import log
    log.startLogging(sys.stderr, setStdout=0)

    config = {
        'base':
          distinguishedname.DistinguishedName('ou=People,dc=example,dc=com'),
        'serviceLocationOverrides': {
          distinguishedname.DistinguishedName('dc=example,dc=com'):
            ('localhost', 10389),
          }
        }

    d = search(config)
    def _show(results):
        for item in results:
            print item
    d.addCallback(_show)
    d.addErrback(defer.logError)
    d.addBoth(lambda _: reactor.stop())
    reactor.run()