How to use the ldaptor.ldapfilter.parseFilter 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 / addressbook / 02_script / addressbook.py View on Github external
def _doSearch(proto, config):
        searchFilter = ldapfilter.parseFilter('(gn=j*)')
        baseEntry = ldapsyntax.LDAPEntry(client=proto, dn=config['base'])
        d=baseEntry.search(filterObject=searchFilter)
        return d
github twisted / ldaptor / ldaptor / checkers.py View on Github external
def requestAvatarId(self, credentials):
        try:
            baseDN = self.config.getIdentityBaseDN()
        except config.MissingBaseDNError, e:
            return failure.Failure(error.UnauthorizedLogin("Disabled due configuration error: %s." % e))
        if not credentials.username:
            return failure.Failure(error.UnauthorizedLogin("I don't support anonymous"))
        filtText = self.config.getIdentitySearch(credentials.username)
        try:
            filt = ldapfilter.parseFilter(filtText)
        except ldapfilter.InvalidLDAPFilter:
            return failure.Failure(error.UnauthorizedLogin("Couldn't create filter"))

        c = ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
        d = c.connect(baseDN, self.config.getServiceLocationOverrides())
        d.addCallback(self._connected, filt, credentials)
        def _err(reason):
            reason.trap(ldaperrors.LDAPInvalidCredentials,

                        # this happens with slapd 2.1.30 when binding
                        # with DN but no password
                        ldaperrors.LDAPUnwillingToPerform)
            return failure.Failure(error.UnauthorizedLogin())
        d.addErrback(_err)
        return d
github twisted / ldaptor / ldaptor / protocols / ldap / ldapsyntax.py View on Github external
sizeLimitIsNonFatal=False,
               timeLimit=0,
               typesOnly=0,
               callback=None,
               controls=None,
               return_controls=False):
        self._checkState()
        d = defer.Deferred()
        if filterObject is None and filterText is None:
            filterObject = pureldap.LDAPFilterMatchAll
        elif filterObject is None and filterText is not None:
            filterObject = ldapfilter.parseFilter(filterText)
        elif filterObject is not None and filterText is None:
            pass
        elif filterObject is not None and filterText is not None:
            f = ldapfilter.parseFilter(filterText)
            filterObject = pureldap.LDAPFilter_and((f, filterObject))

        if scope is None:
            scope = pureldap.LDAP_SCOPE_wholeSubtree
        if derefAliases is None:
            derefAliases = pureldap.LDAP_DEREF_neverDerefAliases

        if attributes is None:
            attributes = ['1.1']

        results = []
        if callback is None:
            cb = results.append
        else:
            cb = callback
        try:
github twisted / ldaptor / ldaptor / entryhelpers.py View on Github external
filterObject=None,
               attributes=(),
               scope=None,
               derefAliases=None,
               sizeLimit=0,
               timeLimit=0,
               typesOnly=0,
               callback=None):
        if filterObject is None and filterText is None:
            filterObject = pureldap.LDAPFilterMatchAll
        elif filterObject is None and filterText is not None:
            filterObject = ldapfilter.parseFilter(filterText)
        elif filterObject is not None and filterText is None:
            pass
        elif filterObject is not None and filterText is not None:
            f = ldapfilter.parseFilter(filterText)
            filterObject = pureldap.LDAPFilter_and((f, filterObject))

        if scope is None:
            scope = pureldap.LDAP_SCOPE_wholeSubtree
        if derefAliases is None:
            derefAliases = pureldap.LDAP_DEREF_neverDerefAliases

        # choose iterator: base/children/subtree
        if scope == pureldap.LDAP_SCOPE_wholeSubtree:
            iterator = self.subtree
        elif scope == pureldap.LDAP_SCOPE_singleLevel:
            iterator = self.children
        elif scope == pureldap.LDAP_SCOPE_baseObject:
            def iterateSelf(callback):
                callback(self)
                return defer.succeed(None)
github twisted / ldaptor / ldaptor / apps / webui / search.py View on Github external
filt=[]
        for k,v in kw.items():
            assert k.startswith('search_')
            if not k.startswith("search_"):
                continue
            k=k[len("search_"):]
            if v is None:
                continue
            v=v.strip()
            if v=='':
                continue

            # TODO escape ) in v
            # TODO handle unknown filter name right (old form open in browser etc)
            filter_ = config.getSearchFieldByName(k, vars={'input': v})
            filt.append(ldapfilter.parseFilter(filter_))
        if searchfilter:
            try:
                filt.append(ldapfilter.parseFilter(searchfilter))
            except ldapfilter.InvalidLDAPFilter, e:
                raise annotate.ValidateError(
                    {'searchfilter': str(e), },
                    partialForm=inevow.IRequest(ctx).args)

        if filt:
            if len(filt)==1:
                query=filt[0]
            else:
                query=pureldap.LDAPFilter_and(filt)
        else:
            query=pureldap.LDAPFilterMatchAll
github twisted / ldaptor / docs / source / examples / addressbook / 05_form / addressbook.py View on Github external
def coerce(self, *a, **kw):
        val = super(LDAPSearchFilter, self).coerce(*a, **kw)
        try:
            f = ldapfilter.parseFilter(val)
        except ldapfilter.InvalidLDAPFilter, e:
            raise annotate.InputError, \
                  "%r is not a valid LDAP search filter: %s" % (val, e)
        return f
github twisted / ldaptor / ldaptor / entryhelpers.py View on Github external
def search(self,
               filterText=None,
               filterObject=None,
               attributes=(),
               scope=None,
               derefAliases=None,
               sizeLimit=0,
               timeLimit=0,
               typesOnly=0,
               callback=None):
        if filterObject is None and filterText is None:
            filterObject = pureldap.LDAPFilterMatchAll
        elif filterObject is None and filterText is not None:
            filterObject = ldapfilter.parseFilter(filterText)
        elif filterObject is not None and filterText is None:
            pass
        elif filterObject is not None and filterText is not None:
            f = ldapfilter.parseFilter(filterText)
            filterObject = pureldap.LDAPFilter_and((f, filterObject))

        if scope is None:
            scope = pureldap.LDAP_SCOPE_wholeSubtree
        if derefAliases is None:
            derefAliases = pureldap.LDAP_DEREF_neverDerefAliases

        # choose iterator: base/children/subtree
        if scope == pureldap.LDAP_SCOPE_wholeSubtree:
            iterator = self.subtree
        elif scope == pureldap.LDAP_SCOPE_singleLevel:
            iterator = self.children
github twisted / ldaptor / docs / source / examples / addressbook / 04_dynamic / addressbook.py View on Github external
def _doSearch(proto, searchFilter):
            searchFilter = ldapfilter.parseFilter(searchFilter)
            baseEntry = ldapsyntax.LDAPEntry(client=proto,
                                             dn=self.config.getBaseDN())
            d=baseEntry.search(filterObject=searchFilter)
            return d