require Logger
alias Wampex.Roles.Dealer.{Invocation, Result}
alias Wampex.Roles.Peer.Error
- alias Wampex.Router.Authentication.{User, Realm}
+ alias Wampex.Router.Authentication.{Peer, Realm}
alias Wampex.Router.{Realms, Session}
@procedures [
- "admin.create_user",
+ "admin.create_peer",
"admin.create_realm"
]
{req_id,
%Invocation{
arg_kw: %{"realm" => realm, "authid" => authid, "password" => password},
- options: %{"procedure" => "admin.create_user"}
+ options: %{"procedure" => "admin.create_peer"}
} = event, {pid, node}},
%{proxy: proxy} = state
) do
with realm <- Realm.get(uri: realm),
- %User{id: id} <- User.create(authid: authid, password: password, realm: realm) do
+ %Peer{id: id} <- Peer.create(authid: authid, password: password, realm: realm) do
Logger.info("Admin handled event: #{inspect(event)}")
send({proxy, node}, {%Result{request_id: req_id, arg_list: [id]}, pid})
alias Wampex.Crypto
alias Wampex.Serializers.JSON
- alias Wampex.Router.Authentication.{Realm, User}
+ alias Wampex.Router.Authentication.{Realm, Peer}
@wampcra "wampcra"
@auth_provider "userdb"
def challenge(realm, authid, session_id) do
%Realm{} = realm = Realm.get(uri: realm)
- %User{} = user = User.get(authid: authid, realm: realm)
+ %Peer{} = user = Peer.get(authid: authid, realm: realm)
now = DateTime.to_iso8601(DateTime.utc_now())
%{
defp get_secret(authid, uri) do
realm = Realm.get(uri: uri)
- %User{password: password} = User.get(authid: authid, realm: realm)
+ %Peer{password: password} = Peer.get(authid: authid, realm: realm)
password
end
require Logger
use GenServer
- alias Wampex.Router.Authentication.{Realm, User}
+ alias Wampex.Router.Authentication.{Realm, Peer}
def start_link(uri: uri, authid: authid, password: password) do
GenServer.start_link(__MODULE__, {uri, authid, password})
def init({uri, authid, password}) do
%Realm{} = realm = Realm.create(uri: uri)
- %User{} = user = User.create(authid: authid, password: password, realm: realm)
- Logger.info("Realm: #{inspect(realm)}")
- Logger.info("User: #{inspect(user)}")
+ %Peer{} = user = Peer.create(authid: authid, password: password, realm: realm)
+ Logger.debug("Realm: #{inspect(realm)}")
+ Logger.debug("Peer: #{inspect(user)}")
:ignore
end
end
-defmodule Wampex.Router.Authentication.User do
+defmodule Wampex.Router.Authentication.Peer do
@moduledoc """
- CREATE TABLE authentication.users (
+ CREATE TABLE authentication.peers (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
authid STRING(255) NOT NULL,
password STRING NOT NULL,
salt STRING NOT NULL,
iterations INT NOT NULL,
keylen INT NOT NULL,
+ cidr STRING,
realm_id UUID NOT NULL REFERENCES authentication.realms (id) ON DELETE CASCADE,
inserted_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
@primary_key {:id, :binary_id, autogenerate: false, read_after_writes: true}
@foreign_key_type :binary_id
- schema "users" do
+ schema "peers" do
field(:authid, :string)
field(:password, :string)
field(:salt, :string)
field(:iterations, :integer)
field(:keylen, :integer)
+ field(:cidr, :string)
belongs_to(:realm, Realm)
timestamps()
end
end
def get(authid: authid, realm: realm) do
- Repo.get_by(User, authid: authid, realm_id: realm.id)
+ Repo.get_by(Peer, authid: authid, realm_id: realm.id)
end
def create(authid: authid, password: password, realm: realm) do
password = Crypto.pbkdf2(password, salt, iterations, keylen)
{:ok, u} =
- %User{
+ %Peer{
authid: authid,
password: password,
realm: realm,
{DynamicSupervisor, strategy: :one_for_one, name: realm_supervisor_name(name)}
]
- Logger.info("Starting Realms Supervisor: #{inspect(children)}")
Supervisor.init(children, strategy: :one_for_one)
end
create(unique_index(:realms, [:uri]))
- create table("users", primary_key: false) do
+ create table("peers", primary_key: false) do
add(:id, :binary_id, primary_key: true, default: fragment("gen_random_uuid()"))
add(:authid, :string, null: false)
add(:password, :string, null: false)
add(:salt, :string, null: false)
add(:iterations, :integer, null: false)
add(:keylen, :integer, null: false)
+ add(:cidr, :string)
add(:realm_id, references(:realms, type: :binary_id, on_delete: :delete_all), null: false)
timestamps()
end
- create(index(:users, [:authid]))
- create(unique_index(:users, [:authid, :realm_id]))
+ create(index(:peers, [:authid]))
+ create(unique_index(:peers, [:authid, :realm_id]))
end
end
Client.send_request(
caller_name,
Caller.call(%Call{
- procedure: "admin.create_user",
+ procedure: "admin.create_peer",
arg_kw: %{authid: "chris", password: "woot!", realm: @realm_uri}
})
)
Client.send_request(
caller_name,
Caller.call(%Call{
- procedure: "admin.create_user",
+ procedure: "admin.create_peer",
arg_kw: %{authid: "chris", password: "woot!", realm: "not.real"}
})
)