# `Arcadic.Security`
[🔗](https://github.com/baselabs/arcadic/blob/baselabs_arcadic-v4.0.1/lib/arcadic/security.ex#L5)

Server security & auth admin: session login/logout, active sessions, and user/group/API-token
management — over ArcadeDB's HTTP admin surface. Reads (`users`/`groups`/`api_tokens`/`sessions`)
use the read-only REST endpoints; mutations (`create_user`/`drop_user`) use server commands (the
REST paths are read-only — `POST /server/users` → 400). Tenant-blind.

`create_user/2` is the one place a caller VALUE (the password) reaches a statement: server commands
cannot bind params (probed), so the user spec is `Jason.encode`d into `create user <json>` — the
JSON backslash-escaping round-trips exactly against ArcadeDB's `create user` lexer (live-verified).
The encode uses the NON-raising `Jason.encode/1`: a non-UTF8 binary password passes the `is_binary`
guard but would make `Jason.encode!` raise a `Jason.EncodeError` that renders the raw bytes, so an
unencodable spec is rejected value-free as `{:error, :invalid_user_spec}` (the Jason error, which
holds the bytes, is discarded) before any wire call. The password NEVER enters an error, log, or
telemetry line (the server error is name-only; arcadic only ever emits valid JSON; `Arcadic.Error`
quarantines `detail`; the admin span is value-free).

# `api_tokens`

```elixir
@spec api_tokens(Arcadic.Conn.t()) :: {:ok, [map()]} | {:error, Exception.t()}
```

List server API tokens (`GET /api/v1/server/api-tokens`).

# `api_tokens!`

```elixir
@spec api_tokens!(Arcadic.Conn.t()) :: [map()]
```

# `create_user`

```elixir
@spec create_user(Arcadic.Conn.t(), map()) :: :ok | {:error, atom() | Exception.t()}
```

Create a server user from `%{name:, password:, databases: %{db => [roles]}}` (`databases` optional).
`name` is `Identifier`-validated; the spec is `Jason.encode`d into the command. The password is never
echoed. An unencodable spec such as a non-UTF-8 binary returns
`{:error, :invalid_user_spec}`. Returns `:ok` or a typed error.

# `create_user!`

```elixir
@spec create_user!(Arcadic.Conn.t(), map()) :: :ok
```

# `drop_user`

```elixir
@spec drop_user(Arcadic.Conn.t(), String.t()) ::
  :ok | {:error, atom() | Exception.t()}
```

Drop a server user. Validates `name`.

# `drop_user!`

```elixir
@spec drop_user!(Arcadic.Conn.t(), String.t()) :: :ok
```

# `groups`

```elixir
@spec groups(Arcadic.Conn.t()) :: {:ok, map()} | {:error, Exception.t()}
```

The server security-groups map (`GET /api/v1/server/groups`).

# `groups!`

```elixir
@spec groups!(Arcadic.Conn.t()) :: map()
```

# `login`

```elixir
@spec login(Arcadic.Conn.t()) :: {:ok, String.t()} | {:error, Exception.t()}
```

Mint a session token from the conn's credentials (`POST /api/v1/login`).

# `login!`

```elixir
@spec login!(Arcadic.Conn.t()) :: String.t()
```

# `logout`

```elixir
@spec logout(Arcadic.Conn.t()) :: :ok | {:error, Exception.t()}
```

Revoke the current session (`POST /api/v1/logout`).

# `logout!`

```elixir
@spec logout!(Arcadic.Conn.t()) :: :ok
```

# `sessions`

```elixir
@spec sessions(Arcadic.Conn.t()) :: {:ok, [map()]} | {:error, Exception.t()}
```

List active sessions (`GET /api/v1/sessions`). Rows carry caller-owned tokens — do not log them.

# `sessions!`

```elixir
@spec sessions!(Arcadic.Conn.t()) :: [map()]
```

# `users`

```elixir
@spec users(Arcadic.Conn.t()) :: {:ok, [map()]} | {:error, Exception.t()}
```

List server users (`GET /api/v1/server/users`).

# `users!`

```elixir
@spec users!(Arcadic.Conn.t()) :: [map()]
```

---

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