Directory implementation - part 3
This commit is contained in:
@@ -23,155 +23,63 @@
|
||||
|
||||
use crate::JMAP;
|
||||
|
||||
use super::{AclToken, AuthDatabase, SqlDatabase};
|
||||
use super::AclToken;
|
||||
|
||||
impl JMAP {
|
||||
pub async fn authenticate(&self, account: &str, secret: &str) -> Option<u32> {
|
||||
let account_id = self.get_account_id(account).await?;
|
||||
let account_secret = self.get_account_secret(account_id).await?;
|
||||
if secret == account_secret {
|
||||
account_id.into()
|
||||
} else {
|
||||
tracing::debug!(context = "auth", event = "failed", account = account);
|
||||
None
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn authenticate_with_token(&self, account: &str, secret: &str) -> Option<AclToken> {
|
||||
self.get_acl_token(self.authenticate(account, secret).await?)
|
||||
.await
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_acl_token(&self, account_id: u32) -> Option<AclToken> {
|
||||
self.update_acl_token(AclToken {
|
||||
primary_id: account_id,
|
||||
member_of: self.get_account_gids(account_id).await,
|
||||
access_to: Vec::new(),
|
||||
})
|
||||
.await
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_account_secret(&self, account_id: u32) -> Option<String> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql {
|
||||
db,
|
||||
query_secret_by_uid,
|
||||
..
|
||||
} => {
|
||||
db.fetch_uid_to_string(query_secret_by_uid, account_id as i64)
|
||||
.await
|
||||
}
|
||||
AuthDatabase::Ldap => None,
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_account_name(&self, account_id: u32) -> Option<String> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql {
|
||||
db,
|
||||
query_name_by_uid,
|
||||
..
|
||||
} => {
|
||||
db.fetch_uid_to_string(query_name_by_uid, account_id as i64)
|
||||
.await
|
||||
}
|
||||
AuthDatabase::Ldap => None,
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_account_id(&self, account: &str) -> Option<u32> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql {
|
||||
db,
|
||||
query_uid_by_login,
|
||||
..
|
||||
} => db
|
||||
.fetch_string_to_id(query_uid_by_login, account)
|
||||
.await
|
||||
.map(|id| id as u32),
|
||||
AuthDatabase::Ldap => None,
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_account_gids(&self, account_id: u32) -> Vec<u32> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql {
|
||||
db,
|
||||
query_gids_by_uid,
|
||||
..
|
||||
} => db
|
||||
.fetch_uid_to_uids(query_gids_by_uid, account_id as i64)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|id| id as u32)
|
||||
.collect(),
|
||||
AuthDatabase::Ldap => vec![],
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_account_login(&self, account_id: u32) -> Option<String> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql {
|
||||
db,
|
||||
query_login_by_uid,
|
||||
..
|
||||
} => {
|
||||
db.fetch_uid_to_string(query_login_by_uid, account_id as i64)
|
||||
.await
|
||||
}
|
||||
AuthDatabase::Ldap => None,
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_uids_by_address(&self, address: &str) -> Vec<u32> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql {
|
||||
db,
|
||||
query_uids_by_address,
|
||||
..
|
||||
} => db
|
||||
.fetch_string_to_uids(query_uids_by_address, address)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|id| id as u32)
|
||||
.collect(),
|
||||
AuthDatabase::Ldap => vec![],
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn get_addresses_by_uid(&self, account_id: u32) -> Vec<String> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql {
|
||||
db,
|
||||
query_addresses_by_uid,
|
||||
..
|
||||
} => {
|
||||
db.fetch_uid_to_strings(query_addresses_by_uid, account_id as i64)
|
||||
.await
|
||||
}
|
||||
AuthDatabase::Ldap => vec![],
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn vrfy_address(&self, address: &str) -> Vec<String> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql { db, query_vrfy, .. } => {
|
||||
db.fetch_string_to_strings(query_vrfy, address).await
|
||||
}
|
||||
AuthDatabase::Ldap => vec![],
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn expn_address(&self, address: &str) -> Vec<String> {
|
||||
match &self.auth_db {
|
||||
AuthDatabase::Sql { db, query_expn, .. } => {
|
||||
db.fetch_string_to_strings(query_expn, address).await
|
||||
}
|
||||
AuthDatabase::Ldap => vec![],
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct Remove {
|
||||
remove: bool,
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO abstract this
|
||||
impl SqlDatabase {
|
||||
pub async fn fetch_uid_to_string(&self, query: &str, uid: i64) -> Option<String> {
|
||||
@@ -447,3 +355,4 @@ impl AuthDatabase {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -41,29 +41,6 @@ pub mod authenticate;
|
||||
pub mod oauth;
|
||||
pub mod rate_limit;
|
||||
|
||||
pub enum AuthDatabase {
|
||||
Sql {
|
||||
db: SqlDatabase,
|
||||
query_uid_by_login: String,
|
||||
query_login_by_uid: String,
|
||||
query_secret_by_uid: String,
|
||||
query_name_by_uid: String,
|
||||
query_gids_by_uid: String,
|
||||
query_uids_by_address: String,
|
||||
query_addresses_by_uid: String,
|
||||
query_vrfy: String,
|
||||
query_expn: String,
|
||||
},
|
||||
Ldap,
|
||||
}
|
||||
|
||||
pub enum SqlDatabase {
|
||||
Postgres(sqlx::Pool<sqlx::Postgres>),
|
||||
MySql(sqlx::Pool<sqlx::MySql>),
|
||||
//MsSql(sqlx::Pool<sqlx::Mssql>),
|
||||
SqlLite(sqlx::Pool<sqlx::Sqlite>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AclToken {
|
||||
pub primary_id: u32,
|
||||
|
||||
@@ -28,7 +28,7 @@ use api::session::BaseCapabilities;
|
||||
use auth::{
|
||||
oauth::OAuthCode,
|
||||
rate_limit::{AnonymousLimiter, AuthenticatedLimiter, RemoteAddress},
|
||||
AclToken, AuthDatabase, SqlDatabase,
|
||||
AclToken,
|
||||
};
|
||||
use jmap_proto::{
|
||||
error::method::MethodError,
|
||||
@@ -45,7 +45,6 @@ use services::{
|
||||
state::{self, init_state_manager, spawn_state_manager},
|
||||
};
|
||||
use smtp::core::SMTP;
|
||||
use sqlx::{mysql::MySqlPoolOptions, postgres::PgPoolOptions, sqlite::SqlitePoolOptions};
|
||||
use store::{
|
||||
fts::Language,
|
||||
parking_lot::Mutex,
|
||||
@@ -55,7 +54,7 @@ use store::{
|
||||
BitmapKey, Deserialize, Serialize, Store, ValueKey,
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
use utils::{config::Rate, failed, ipc::DeliveryEvent, UnwrapFailure};
|
||||
use utils::{config::Rate, ipc::DeliveryEvent, UnwrapFailure};
|
||||
|
||||
pub mod api;
|
||||
pub mod auth;
|
||||
@@ -86,7 +85,6 @@ pub struct JMAP {
|
||||
pub rate_limit_unauth: LruCache<RemoteAddress, Arc<Mutex<AnonymousLimiter>>>,
|
||||
|
||||
pub oauth_codes: LruCache<String, Arc<OAuthCode>>,
|
||||
pub auth_db: AuthDatabase,
|
||||
|
||||
pub state_tx: mpsc::Sender<state::Event>,
|
||||
pub housekeeper_tx: mpsc::Sender<housekeeper::Event>,
|
||||
@@ -159,6 +157,8 @@ impl JMAP {
|
||||
delivery_rx: mpsc::Receiver<DeliveryEvent>,
|
||||
smtp: Arc<SMTP>,
|
||||
) -> Result<Arc<Self>, String> {
|
||||
let remove = "true";
|
||||
/*
|
||||
let auth_db = match config.value_require("jmap.auth.database.type")? {
|
||||
"ldap" => AuthDatabase::Ldap,
|
||||
"sql" => {
|
||||
@@ -243,7 +243,7 @@ impl JMAP {
|
||||
}
|
||||
}
|
||||
_ => failed("Invalid auth database type"),
|
||||
};
|
||||
};*/
|
||||
|
||||
// Init state manager and housekeeper
|
||||
let (state_tx, state_rx) = init_state_manager();
|
||||
@@ -271,7 +271,6 @@ impl JMAP {
|
||||
oauth_codes: LruCache::with_capacity(
|
||||
config.property("oauth.code.cache-size")?.unwrap_or(128),
|
||||
),
|
||||
auth_db,
|
||||
state_tx,
|
||||
housekeeper_tx,
|
||||
smtp,
|
||||
|
||||
Reference in New Issue
Block a user