# `Macaw.Auth.Native.Source.Ldap.Filter`
[🔗](https://github.com/dcoai/macaw_auth/blob/v0.4.1/lib/macaw/auth/native/source/ldap/filter.ex#L1)

RFC 4515 search filters as `:eldap` terms, built with the username as
data. Ported from exio's parser, with one change in how the username gets
in.

`:eldap` takes a filter as a term, not a string, so the configured
`search.filter` (`(&(objectClass=person)(uid={username}))`) is parsed
here. exio and macaw escaped the username into the filter's *text* and
then parsed the result, so the escaping was all that stood between a
username and the filter's structure. Here the template is parsed with
`{username}` as a placeholder and the username's bytes go straight into
the assertion value of the term: a `*`, `(` or `\` in a username is a
byte of the value, never syntax, whatever the escaping would have done.

`\hh` escapes in the template decode to their bytes, so an escaped `*`
is a literal asterisk, never a wildcard. Supported: `&`, `|`, `!`,
equality, presence (`attr=*`), substrings, `>=`, `<=` and `~=`.
Extensible matches are not.

# `build`

```elixir
@spec build(String.t(), binary()) :: {:ok, term()} | :error
```

Parses a filter template with `username` in place of `{username}`:
`{:ok, eldap_filter}` or `:error`.

# `valid_template?`

```elixir
@spec valid_template?(term()) :: boolean()
```

Whether `template` is a filter that uses `{username}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
