mirror of
https://github.com/lldap/lldap.git
synced 2026-03-31 15:07:48 +01:00
server: move domain::types to separate domain crate (#1086)
Preparation for using basic type definitions in other upcoming modules, in particular for plugins.
This commit is contained in:
committed by
GitHub
parent
417abc54e4
commit
1b26859141
+12
-11
@@ -40,7 +40,6 @@ orion = "0.17"
|
||||
rand_chacha = "0.3"
|
||||
rustls-pemfile = "1"
|
||||
serde = "*"
|
||||
serde_bytes = "0.11"
|
||||
serde_json = "1"
|
||||
sha2 = "0.10"
|
||||
thiserror = "*"
|
||||
@@ -85,6 +84,13 @@ version = "0.10.1"
|
||||
path = "../auth"
|
||||
features = ["opaque_server", "opaque_client", "sea_orm"]
|
||||
|
||||
[dependencies.lldap_domain]
|
||||
path = "../crates/domain"
|
||||
|
||||
[dev-dependencies.lldap_domain]
|
||||
path = "../crates/domain"
|
||||
features = ["test"]
|
||||
|
||||
[dependencies.lldap_validation]
|
||||
path = "../validation"
|
||||
|
||||
@@ -119,20 +125,15 @@ version = "^0.1.6"
|
||||
features = ["default", "rustls"]
|
||||
version = "3"
|
||||
|
||||
[dependencies.image]
|
||||
features = ["jpeg"]
|
||||
default-features = false
|
||||
version = "0.24"
|
||||
|
||||
[dependencies.sea-orm]
|
||||
version = "0.12"
|
||||
default-features = false
|
||||
features = [
|
||||
"macros",
|
||||
"with-chrono",
|
||||
"with-uuid",
|
||||
"sqlx-all",
|
||||
"runtime-actix-rustls",
|
||||
"macros",
|
||||
"with-chrono",
|
||||
"with-uuid",
|
||||
"sqlx-all",
|
||||
"runtime-actix-rustls",
|
||||
]
|
||||
|
||||
[dependencies.reqwest]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::domain::types::{AttributeType, JpegPhoto, Serialized};
|
||||
use anyhow::{bail, Context as AnyhowContext};
|
||||
use lldap_domain::types::{AttributeType, JpegPhoto, Serialized};
|
||||
|
||||
pub fn deserialize_attribute_value(
|
||||
value: &[String],
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use crate::domain::{
|
||||
error::Result,
|
||||
use crate::domain::{error::Result, model::UserColumn};
|
||||
use async_trait::async_trait;
|
||||
use lldap_domain::{
|
||||
requests::{
|
||||
CreateAttributeRequest, CreateGroupRequest, CreateUserRequest, UpdateGroupRequest,
|
||||
UpdateUserRequest,
|
||||
},
|
||||
schema::Schema,
|
||||
types::{
|
||||
AttributeName, AttributeType, AttributeValue, Email, Group, GroupDetails, GroupId,
|
||||
GroupName, JpegPhoto, LdapObjectClass, Serialized, User, UserAndGroups, UserColumn, UserId,
|
||||
Uuid,
|
||||
AttributeName, Group, GroupDetails, GroupId, GroupName, LdapObjectClass, Serialized, User,
|
||||
UserAndGroups, UserId, Uuid,
|
||||
},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -99,90 +103,6 @@ impl From<bool> for GroupRequestFilter {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct CreateUserRequest {
|
||||
// Same fields as User, but no creation_date, and with password.
|
||||
pub user_id: UserId,
|
||||
pub email: Email,
|
||||
pub display_name: Option<String>,
|
||||
pub first_name: Option<String>,
|
||||
pub last_name: Option<String>,
|
||||
pub avatar: Option<JpegPhoto>,
|
||||
pub attributes: Vec<AttributeValue>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct UpdateUserRequest {
|
||||
// Same fields as CreateUserRequest, but no with an extra layer of Option.
|
||||
pub user_id: UserId,
|
||||
pub email: Option<Email>,
|
||||
pub display_name: Option<String>,
|
||||
pub first_name: Option<String>,
|
||||
pub last_name: Option<String>,
|
||||
pub avatar: Option<JpegPhoto>,
|
||||
pub delete_attributes: Vec<AttributeName>,
|
||||
pub insert_attributes: Vec<AttributeValue>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct CreateGroupRequest {
|
||||
pub display_name: GroupName,
|
||||
pub attributes: Vec<AttributeValue>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct UpdateGroupRequest {
|
||||
pub group_id: GroupId,
|
||||
pub display_name: Option<GroupName>,
|
||||
pub delete_attributes: Vec<AttributeName>,
|
||||
pub insert_attributes: Vec<AttributeValue>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AttributeSchema {
|
||||
pub name: AttributeName,
|
||||
//TODO: pub aliases: Vec<String>,
|
||||
pub attribute_type: AttributeType,
|
||||
pub is_list: bool,
|
||||
pub is_visible: bool,
|
||||
pub is_editable: bool,
|
||||
pub is_hardcoded: bool,
|
||||
pub is_readonly: bool,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CreateAttributeRequest {
|
||||
pub name: AttributeName,
|
||||
pub attribute_type: AttributeType,
|
||||
pub is_list: bool,
|
||||
pub is_visible: bool,
|
||||
pub is_editable: bool,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AttributeList {
|
||||
pub attributes: Vec<AttributeSchema>,
|
||||
}
|
||||
|
||||
impl AttributeList {
|
||||
pub fn get_attribute_schema(&self, name: &AttributeName) -> Option<&AttributeSchema> {
|
||||
self.attributes.iter().find(|a| a.name == *name)
|
||||
}
|
||||
|
||||
pub fn get_attribute_type(&self, name: &AttributeName) -> Option<(AttributeType, bool)> {
|
||||
self.get_attribute_schema(name)
|
||||
.map(|a| (a.attribute_type, a.is_list))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Schema {
|
||||
pub user_attributes: AttributeList,
|
||||
pub group_attributes: AttributeList,
|
||||
pub extra_user_object_classes: Vec<LdapObjectClass>,
|
||||
pub extra_group_object_classes: Vec<LdapObjectClass>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait LoginHandler: Send + Sync {
|
||||
async fn bind(&self, request: BindRequest) -> Result<()>;
|
||||
@@ -257,6 +177,7 @@ pub trait BackendHandler:
|
||||
mod tests {
|
||||
use super::*;
|
||||
use base64::Engine;
|
||||
use lldap_domain::types::JpegPhoto;
|
||||
use pretty_assertions::assert_ne;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -17,7 +17,9 @@ use crate::domain::{
|
||||
},
|
||||
},
|
||||
schema::{PublicSchema, SchemaGroupAttributeExtractor},
|
||||
types::{AttributeName, AttributeType, Group, GroupId, LdapObjectClass, UserId, Uuid},
|
||||
};
|
||||
use lldap_domain::types::{
|
||||
AttributeName, AttributeType, Group, GroupId, LdapObjectClass, UserId, Uuid,
|
||||
};
|
||||
|
||||
pub fn get_group_attribute(
|
||||
|
||||
@@ -16,11 +16,11 @@ use crate::domain::{
|
||||
LdapInfo, UserFieldType,
|
||||
},
|
||||
},
|
||||
model::UserColumn,
|
||||
schema::{PublicSchema, SchemaUserAttributeExtractor},
|
||||
types::{
|
||||
AttributeName, AttributeType, GroupDetails, LdapObjectClass, User, UserAndGroups,
|
||||
UserColumn, UserId,
|
||||
},
|
||||
};
|
||||
use lldap_domain::types::{
|
||||
AttributeName, AttributeType, GroupDetails, LdapObjectClass, User, UserAndGroups, UserId,
|
||||
};
|
||||
|
||||
pub fn get_user_attribute(
|
||||
|
||||
@@ -7,10 +7,11 @@ use tracing::{debug, instrument, warn};
|
||||
use crate::domain::{
|
||||
handler::SubStringFilter,
|
||||
ldap::error::{LdapError, LdapResult},
|
||||
model::UserColumn,
|
||||
schema::{PublicSchema, SchemaAttributeExtractor},
|
||||
types::{
|
||||
AttributeName, AttributeType, AttributeValue, GroupName, JpegPhoto, UserColumn, UserId,
|
||||
},
|
||||
};
|
||||
use lldap_domain::types::{
|
||||
AttributeName, AttributeType, AttributeValue, GroupName, JpegPhoto, UserId,
|
||||
};
|
||||
|
||||
impl From<LdapSubstringFilter> for SubStringFilter {
|
||||
|
||||
@@ -12,4 +12,3 @@ pub mod sql_opaque_handler;
|
||||
pub mod sql_schema_backend_handler;
|
||||
pub mod sql_tables;
|
||||
pub mod sql_user_backend_handler;
|
||||
pub mod types;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::{
|
||||
handler::AttributeSchema,
|
||||
use lldap_domain::{
|
||||
schema::AttributeSchema,
|
||||
types::{AttributeName, AttributeType},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::{AttributeName, AttributeValue, GroupId, Serialized};
|
||||
use lldap_domain::types::{AttributeName, AttributeValue, GroupId, Serialized};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "group_attributes")]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::LdapObjectClass;
|
||||
use lldap_domain::types::LdapObjectClass;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "group_object_classes")]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::{GroupId, GroupName, Uuid};
|
||||
use lldap_domain::types::{GroupId, GroupName, Uuid};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "groups")]
|
||||
@@ -30,7 +30,7 @@ impl Related<super::memberships::Entity> for Entity {
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for crate::domain::types::Group {
|
||||
impl From<Model> for lldap_domain::types::Group {
|
||||
fn from(group: Model) -> Self {
|
||||
Self {
|
||||
id: group.group_id,
|
||||
@@ -43,7 +43,7 @@ impl From<Model> for crate::domain::types::Group {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Model> for crate::domain::types::GroupDetails {
|
||||
impl From<Model> for lldap_domain::types::GroupDetails {
|
||||
fn from(group: Model) -> Self {
|
||||
Self {
|
||||
group_id: group.group_id,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::UserId;
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "jwt_refresh_storage")]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::UserId;
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "jwt_storage")]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::{GroupId, UserId};
|
||||
use lldap_domain::types::{GroupId, UserId};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "memberships")]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::UserId;
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "password_reset_tokens")]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::{
|
||||
handler::AttributeSchema,
|
||||
use lldap_domain::{
|
||||
schema::AttributeSchema,
|
||||
types::{AttributeName, AttributeType},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::{AttributeName, AttributeValue, Serialized, UserId};
|
||||
use lldap_domain::types::{AttributeName, AttributeValue, Serialized, UserId};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user_attributes")]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::LdapObjectClass;
|
||||
use lldap_domain::types::LdapObjectClass;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user_object_classes")]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use sea_orm::{entity::prelude::*, sea_query::BlobSize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::types::{Email, UserId, Uuid};
|
||||
use lldap_domain::types::{Email, UserId, Uuid};
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
@@ -112,7 +112,7 @@ impl Related<super::password_reset_tokens::Entity> for Entity {
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for crate::domain::types::User {
|
||||
impl From<Model> for lldap_domain::types::User {
|
||||
fn from(user: Model) -> Self {
|
||||
Self {
|
||||
user_id: user.user_id,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::domain::{error::Result, types::UserId};
|
||||
use crate::domain::error::Result;
|
||||
use async_trait::async_trait;
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
pub use lldap_auth::{login, registration};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::domain::{
|
||||
handler::{AttributeList, AttributeSchema, Schema},
|
||||
use lldap_domain::{
|
||||
schema::{AttributeList, AttributeSchema, Schema},
|
||||
types::AttributeType,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -23,15 +23,18 @@ pub mod tests {
|
||||
use crate::{
|
||||
domain::{
|
||||
handler::{
|
||||
CreateGroupRequest, CreateUserRequest, GroupBackendHandler, UserBackendHandler,
|
||||
UserListerBackendHandler, UserRequestFilter,
|
||||
GroupBackendHandler, UserBackendHandler, UserListerBackendHandler,
|
||||
UserRequestFilter,
|
||||
},
|
||||
sql_tables::init_table,
|
||||
types::{GroupId, UserId},
|
||||
},
|
||||
infra::configuration::ConfigurationBuilder,
|
||||
};
|
||||
use lldap_auth::{opaque, registration};
|
||||
use lldap_domain::{
|
||||
requests::{CreateGroupRequest, CreateUserRequest},
|
||||
types::{GroupId, UserId},
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
use sea_orm::Database;
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::domain::{
|
||||
error::{DomainError, Result},
|
||||
handler::{
|
||||
CreateGroupRequest, GroupBackendHandler, GroupListerBackendHandler, GroupRequestFilter,
|
||||
UpdateGroupRequest,
|
||||
},
|
||||
handler::{GroupBackendHandler, GroupListerBackendHandler, GroupRequestFilter},
|
||||
model::{self, GroupColumn, MembershipColumn},
|
||||
sql_backend_handler::SqlBackendHandler,
|
||||
types::{AttributeName, AttributeValue, Group, GroupDetails, GroupId, Serialized, Uuid},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use lldap_domain::{
|
||||
requests::{CreateGroupRequest, UpdateGroupRequest},
|
||||
types::{AttributeName, AttributeValue, Group, GroupDetails, GroupId, Serialized, Uuid},
|
||||
};
|
||||
use sea_orm::{
|
||||
sea_query::{Alias, Cond, Expr, Func, IntoCondition, OnConflict, SimpleExpr},
|
||||
ActiveModelTrait, ColumnTrait, DatabaseTransaction, EntityTrait, QueryFilter, QueryOrder,
|
||||
@@ -314,8 +314,11 @@ impl SqlBackendHandler {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::domain::{
|
||||
handler::{CreateAttributeRequest, SchemaBackendHandler, SubStringFilter},
|
||||
handler::{SchemaBackendHandler, SubStringFilter},
|
||||
sql_backend_handler::tests::*,
|
||||
};
|
||||
use lldap_domain::{
|
||||
requests::CreateAttributeRequest,
|
||||
types::{AttributeType, GroupName, Serialized, UserId},
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use crate::domain::{
|
||||
sql_tables::{DbConnection, SchemaVersion, LAST_SCHEMA_VERSION},
|
||||
types::{AttributeType, GroupId, JpegPhoto, Serialized, UserId, Uuid},
|
||||
};
|
||||
use crate::domain::sql_tables::{DbConnection, SchemaVersion, LAST_SCHEMA_VERSION};
|
||||
use itertools::Itertools;
|
||||
use lldap_domain::types::{AttributeType, GroupId, JpegPhoto, Serialized, UserId, Uuid};
|
||||
use sea_orm::{
|
||||
sea_query::{
|
||||
self, all, BinOper, BlobSize::Blob, ColumnDef, Expr, ForeignKey, ForeignKeyAction, Func,
|
||||
|
||||
@@ -4,11 +4,11 @@ use super::{
|
||||
model::{self, UserColumn},
|
||||
opaque_handler::{login, registration, OpaqueHandler},
|
||||
sql_backend_handler::SqlBackendHandler,
|
||||
types::UserId,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use base64::Engine;
|
||||
use lldap_auth::opaque;
|
||||
use lldap_domain::types::UserId;
|
||||
use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, QuerySelect};
|
||||
use secstr::SecUtf8;
|
||||
use tracing::{debug, info, instrument, warn};
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
use crate::domain::{
|
||||
error::{DomainError, Result},
|
||||
handler::{
|
||||
AttributeList, AttributeSchema, CreateAttributeRequest, ReadSchemaBackendHandler, Schema,
|
||||
SchemaBackendHandler,
|
||||
},
|
||||
handler::{ReadSchemaBackendHandler, SchemaBackendHandler},
|
||||
model,
|
||||
sql_backend_handler::SqlBackendHandler,
|
||||
types::{AttributeName, LdapObjectClass},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use lldap_domain::{
|
||||
requests::CreateAttributeRequest,
|
||||
schema::{AttributeList, AttributeSchema, Schema},
|
||||
types::{AttributeName, LdapObjectClass},
|
||||
};
|
||||
use sea_orm::{
|
||||
ActiveModelTrait, DatabaseTransaction, EntityTrait, QueryOrder, Set, TransactionTrait,
|
||||
};
|
||||
@@ -175,10 +176,12 @@ impl SqlBackendHandler {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::domain::{
|
||||
handler::{AttributeList, UpdateUserRequest, UserBackendHandler, UserRequestFilter},
|
||||
handler::{UserBackendHandler, UserRequestFilter},
|
||||
sql_backend_handler::tests::*,
|
||||
types::{AttributeType, AttributeValue, Serialized},
|
||||
};
|
||||
use lldap_domain::requests::UpdateUserRequest;
|
||||
use lldap_domain::schema::AttributeList;
|
||||
use lldap_domain::types::{AttributeType, AttributeValue, Serialized};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -123,10 +123,8 @@ pub async fn set_private_key_info(pool: &DbConnection, info: PrivateKeyInfo) ->
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::domain::{
|
||||
sql_migrations,
|
||||
types::{GroupId, JpegPhoto, Serialized, Uuid},
|
||||
};
|
||||
use crate::domain::sql_migrations;
|
||||
use lldap_domain::types::{GroupId, JpegPhoto, Serialized, Uuid};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
@@ -254,11 +252,11 @@ mod tests {
|
||||
vec![
|
||||
SimpleUser {
|
||||
display_name: None,
|
||||
uuid: crate::uuid!("a02eaf13-48a7-30f6-a3d4-040ff7c52b04")
|
||||
uuid: lldap_domain::uuid!("a02eaf13-48a7-30f6-a3d4-040ff7c52b04")
|
||||
},
|
||||
SimpleUser {
|
||||
display_name: Some("John Doe".to_owned()),
|
||||
uuid: crate::uuid!("986765a5-3f03-389e-b47b-536b2d6e1bec")
|
||||
uuid: lldap_domain::uuid!("986765a5-3f03-389e-b47b-536b2d6e1bec")
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use crate::domain::{
|
||||
error::{DomainError, Result},
|
||||
handler::{
|
||||
CreateUserRequest, UpdateUserRequest, UserBackendHandler, UserListerBackendHandler,
|
||||
UserRequestFilter,
|
||||
},
|
||||
handler::{UserBackendHandler, UserListerBackendHandler, UserRequestFilter},
|
||||
model::{self, GroupColumn, UserColumn},
|
||||
sql_backend_handler::SqlBackendHandler,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use lldap_domain::{
|
||||
requests::{CreateUserRequest, UpdateUserRequest},
|
||||
types::{
|
||||
AttributeName, AttributeValue, GroupDetails, GroupId, Serialized, User, UserAndGroups,
|
||||
UserId, Uuid,
|
||||
},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use sea_orm::{
|
||||
sea_query::{
|
||||
query::OnConflict, Alias, Cond, Expr, Func, IntoColumnRef, IntoCondition, SimpleExpr,
|
||||
@@ -430,10 +430,9 @@ impl UserBackendHandler for SqlBackendHandler {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::domain::{
|
||||
handler::SubStringFilter,
|
||||
sql_backend_handler::tests::*,
|
||||
types::{JpegPhoto, UserColumn},
|
||||
handler::SubStringFilter, model::UserColumn, sql_backend_handler::tests::*,
|
||||
};
|
||||
use lldap_domain::types::JpegPhoto;
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -1,578 +0,0 @@
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use base64::Engine;
|
||||
use chrono::{NaiveDateTime, TimeZone};
|
||||
use lldap_auth::types::CaseInsensitiveString;
|
||||
use sea_orm::{
|
||||
entity::IntoActiveValue,
|
||||
sea_query::{value::ValueType, ArrayType, BlobSize, ColumnType, Nullable, ValueTypeErr},
|
||||
DbErr, DeriveValueType, QueryResult, TryFromU64, TryGetError, TryGetable, Value,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{EnumString, IntoStaticStr};
|
||||
|
||||
pub use super::model::UserColumn;
|
||||
pub use lldap_auth::types::UserId;
|
||||
|
||||
#[derive(
|
||||
PartialEq,
|
||||
Hash,
|
||||
Eq,
|
||||
Clone,
|
||||
Default,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
DeriveValueType,
|
||||
derive_more::Debug,
|
||||
derive_more::Display,
|
||||
)]
|
||||
#[serde(try_from = "&str")]
|
||||
#[sea_orm(column_type = "String(Some(36))")]
|
||||
#[debug(r#""{_0}""#)]
|
||||
#[display("{_0}")]
|
||||
pub struct Uuid(String);
|
||||
|
||||
impl Uuid {
|
||||
pub fn from_name_and_date(name: &str, creation_date: &NaiveDateTime) -> Self {
|
||||
Uuid(
|
||||
uuid::Uuid::new_v3(
|
||||
&uuid::Uuid::NAMESPACE_X500,
|
||||
&[
|
||||
name.as_bytes(),
|
||||
chrono::Utc
|
||||
.from_utc_datetime(creation_date)
|
||||
.to_rfc3339()
|
||||
.as_bytes(),
|
||||
]
|
||||
.concat(),
|
||||
)
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> String {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> std::convert::TryFrom<&'a str> for Uuid {
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(s: &'a str) -> anyhow::Result<Self> {
|
||||
Ok(Uuid(uuid::Uuid::parse_str(s)?.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_export]
|
||||
macro_rules! uuid {
|
||||
($s:literal) => {
|
||||
<$crate::domain::types::Uuid as std::convert::TryFrom<_>>::try_from($s).unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveValueType)]
|
||||
#[sea_orm(column_type = "Binary(BlobSize::Long)", array_type = "Bytes")]
|
||||
pub struct Serialized(Vec<u8>);
|
||||
|
||||
const SERIALIZED_I64_LEN: usize = 8;
|
||||
|
||||
impl std::fmt::Debug for Serialized {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("Serialized")
|
||||
.field(
|
||||
&self
|
||||
.convert_to()
|
||||
.and_then(|s| {
|
||||
String::from_utf8(s)
|
||||
.map_err(|_| Box::new(bincode::ErrorKind::InvalidCharEncoding))
|
||||
})
|
||||
.or_else(|e| {
|
||||
if self.0.len() == SERIALIZED_I64_LEN {
|
||||
self.convert_to::<i64>()
|
||||
.map(|i| i.to_string())
|
||||
.map_err(|_| Box::new(bincode::ErrorKind::InvalidCharEncoding))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|_| {
|
||||
format!("hash: {:#016X}", {
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
std::hash::Hash::hash(&self.0, &mut hasher);
|
||||
std::hash::Hasher::finish(&hasher)
|
||||
})
|
||||
}),
|
||||
)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Serialize + ?Sized> From<&'a T> for Serialized {
|
||||
fn from(t: &'a T) -> Self {
|
||||
Self(bincode::serialize(&t).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialized {
|
||||
fn convert_to<'a, T: Deserialize<'a>>(&'a self) -> bincode::Result<T> {
|
||||
bincode::deserialize(&self.0)
|
||||
}
|
||||
|
||||
pub fn unwrap<'a, T: Deserialize<'a>>(&'a self) -> T {
|
||||
self.convert_to().unwrap()
|
||||
}
|
||||
|
||||
pub fn expect<'a, T: Deserialize<'a>>(&'a self, message: &str) -> T {
|
||||
self.convert_to().expect(message)
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_str_case_insensitive(s1: &str, s2: &str) -> Ordering {
|
||||
let mut it_1 = s1.chars().flat_map(|c| c.to_lowercase());
|
||||
let mut it_2 = s2.chars().flat_map(|c| c.to_lowercase());
|
||||
loop {
|
||||
match (it_1.next(), it_2.next()) {
|
||||
(Some(c1), Some(c2)) => {
|
||||
let o = c1.cmp(&c2);
|
||||
if o != Ordering::Equal {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
(None, Some(_)) => return Ordering::Less,
|
||||
(Some(_), None) => return Ordering::Greater,
|
||||
(None, None) => return Ordering::Equal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! make_case_insensitive_comparable_string {
|
||||
($c:ident) => {
|
||||
#[derive(
|
||||
Clone,
|
||||
Default,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
DeriveValueType,
|
||||
derive_more::Debug,
|
||||
derive_more::Display,
|
||||
)]
|
||||
#[debug(r#""{_0}""#)]
|
||||
#[display("{_0}")]
|
||||
pub struct $c(String);
|
||||
|
||||
impl PartialEq for $c {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
compare_str_case_insensitive(&self.0, &other.0) == Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for $c {}
|
||||
|
||||
impl PartialOrd for $c {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for $c {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
compare_str_case_insensitive(&self.0, &other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::hash::Hash for $c {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.0.to_lowercase().hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl $c {
|
||||
pub fn new(raw: &str) -> Self {
|
||||
Self(raw.to_owned())
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.0.as_str()
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> String {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for $c {
|
||||
fn from(s: String) -> Self {
|
||||
Self(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for $c {
|
||||
fn from(s: &str) -> Self {
|
||||
Self::new(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&$c> for Value {
|
||||
fn from(user_id: &$c) -> Self {
|
||||
user_id.as_str().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFromU64 for $c {
|
||||
fn try_from_u64(_n: u64) -> Result<Self, DbErr> {
|
||||
Err(DbErr::ConvertFromU64("$c cannot be constructed from u64"))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Clone,
|
||||
Debug,
|
||||
Default,
|
||||
Hash,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
DeriveValueType,
|
||||
)]
|
||||
#[serde(from = "CaseInsensitiveString")]
|
||||
pub struct AttributeName(CaseInsensitiveString);
|
||||
|
||||
impl AttributeName {
|
||||
pub fn new(s: &str) -> Self {
|
||||
s.into()
|
||||
}
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.0.as_str()
|
||||
}
|
||||
pub fn into_string(self) -> String {
|
||||
self.0.into_string()
|
||||
}
|
||||
}
|
||||
impl<T> From<T> for AttributeName
|
||||
where
|
||||
T: Into<CaseInsensitiveString>,
|
||||
{
|
||||
fn from(s: T) -> Self {
|
||||
Self(s.into())
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for AttributeName {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0.as_str())
|
||||
}
|
||||
}
|
||||
impl From<&AttributeName> for Value {
|
||||
fn from(attribute_name: &AttributeName) -> Self {
|
||||
attribute_name.as_str().into()
|
||||
}
|
||||
}
|
||||
impl TryFromU64 for AttributeName {
|
||||
fn try_from_u64(_n: u64) -> Result<Self, DbErr> {
|
||||
Err(DbErr::ConvertFromU64(
|
||||
"AttributeName cannot be constructed from u64",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
make_case_insensitive_comparable_string!(LdapObjectClass);
|
||||
make_case_insensitive_comparable_string!(Email);
|
||||
make_case_insensitive_comparable_string!(GroupName);
|
||||
|
||||
impl AsRef<GroupName> for GroupName {
|
||||
fn as_ref(&self) -> &GroupName {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, DeriveValueType)]
|
||||
#[sea_orm(column_type = "Binary(BlobSize::Long)", array_type = "Bytes")]
|
||||
pub struct JpegPhoto(#[serde(with = "serde_bytes")] Vec<u8>);
|
||||
|
||||
impl From<&JpegPhoto> for Value {
|
||||
fn from(photo: &JpegPhoto) -> Self {
|
||||
photo.0.as_slice().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&[u8]> for JpegPhoto {
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(bytes: &[u8]) -> anyhow::Result<Self> {
|
||||
if bytes.is_empty() {
|
||||
return Ok(JpegPhoto::null());
|
||||
}
|
||||
// Confirm that it's a valid Jpeg, then store only the bytes.
|
||||
image::io::Reader::with_format(std::io::Cursor::new(bytes), image::ImageFormat::Jpeg)
|
||||
.decode()?;
|
||||
Ok(JpegPhoto(bytes.to_vec()))
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for JpegPhoto {
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(bytes: Vec<u8>) -> anyhow::Result<Self> {
|
||||
if bytes.is_empty() {
|
||||
return Ok(JpegPhoto::null());
|
||||
}
|
||||
// Confirm that it's a valid Jpeg, then store only the bytes.
|
||||
image::io::Reader::with_format(
|
||||
std::io::Cursor::new(bytes.as_slice()),
|
||||
image::ImageFormat::Jpeg,
|
||||
)
|
||||
.decode()?;
|
||||
Ok(JpegPhoto(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for JpegPhoto {
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(string: &str) -> anyhow::Result<Self> {
|
||||
// The String format is in base64.
|
||||
<Self as TryFrom<_>>::try_from(base64::engine::general_purpose::STANDARD.decode(string)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&JpegPhoto> for String {
|
||||
fn from(val: &JpegPhoto) -> Self {
|
||||
base64::engine::general_purpose::STANDARD.encode(&val.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for JpegPhoto {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut encoded = base64::engine::general_purpose::STANDARD.encode(&self.0);
|
||||
if encoded.len() > 100 {
|
||||
encoded.truncate(100);
|
||||
encoded.push_str(" ...");
|
||||
};
|
||||
f.debug_tuple("JpegPhoto")
|
||||
.field(&format!("b64[{}]", encoded))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl JpegPhoto {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
pub fn null() -> Self {
|
||||
Self(vec![])
|
||||
}
|
||||
|
||||
pub fn into_bytes(self) -> Vec<u8> {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn for_tests() -> Self {
|
||||
use image::{ImageOutputFormat, Rgb, RgbImage};
|
||||
let img = RgbImage::from_fn(32, 32, |x, y| {
|
||||
if (x + y) % 2 == 0 {
|
||||
Rgb([0, 0, 0])
|
||||
} else {
|
||||
Rgb([255, 255, 255])
|
||||
}
|
||||
});
|
||||
let mut bytes: Vec<u8> = Vec::new();
|
||||
img.write_to(
|
||||
&mut std::io::Cursor::new(&mut bytes),
|
||||
ImageOutputFormat::Jpeg(0),
|
||||
)
|
||||
.unwrap();
|
||||
Self(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl Nullable for JpegPhoto {
|
||||
fn null() -> Value {
|
||||
JpegPhoto::null().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoActiveValue<Serialized> for JpegPhoto {
|
||||
fn into_active_value(self) -> sea_orm::ActiveValue<Serialized> {
|
||||
if self.is_empty() {
|
||||
sea_orm::ActiveValue::NotSet
|
||||
} else {
|
||||
sea_orm::ActiveValue::Set(Serialized::from(&self))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, Hash)]
|
||||
pub struct AttributeValue {
|
||||
pub name: AttributeName,
|
||||
pub value: Serialized,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
pub user_id: UserId,
|
||||
pub email: Email,
|
||||
pub display_name: Option<String>,
|
||||
pub creation_date: NaiveDateTime,
|
||||
pub uuid: Uuid,
|
||||
pub attributes: Vec<AttributeValue>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl Default for User {
|
||||
fn default() -> Self {
|
||||
let epoch = chrono::Utc.timestamp_opt(0, 0).unwrap().naive_utc();
|
||||
User {
|
||||
user_id: UserId::default(),
|
||||
email: Email::default(),
|
||||
display_name: None,
|
||||
creation_date: epoch,
|
||||
uuid: Uuid::from_name_and_date("", &epoch),
|
||||
attributes: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Hash,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
DeriveValueType,
|
||||
derive_more::Debug,
|
||||
)]
|
||||
#[debug("{_0}")]
|
||||
pub struct GroupId(pub i32);
|
||||
|
||||
impl TryFromU64 for GroupId {
|
||||
fn try_from_u64(n: u64) -> Result<Self, DbErr> {
|
||||
Ok(GroupId(i32::try_from_u64(n)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&GroupId> for Value {
|
||||
fn from(id: &GroupId) -> Self {
|
||||
(*id).into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
Copy,
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Hash,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
EnumString,
|
||||
IntoStaticStr,
|
||||
juniper::GraphQLEnum,
|
||||
)]
|
||||
pub enum AttributeType {
|
||||
String,
|
||||
Integer,
|
||||
JpegPhoto,
|
||||
DateTime,
|
||||
}
|
||||
|
||||
impl From<AttributeType> for Value {
|
||||
fn from(attribute_type: AttributeType) -> Self {
|
||||
Into::<&'static str>::into(attribute_type).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryGetable for AttributeType {
|
||||
fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, index: I) -> Result<Self, TryGetError> {
|
||||
use std::str::FromStr;
|
||||
Ok(AttributeType::from_str(&String::try_get_by(res, index)?).expect("Invalid enum value"))
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueType for AttributeType {
|
||||
fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
|
||||
use std::str::FromStr;
|
||||
Ok(
|
||||
AttributeType::from_str(&<String as ValueType>::try_from(v)?)
|
||||
.expect("Invalid enum value"),
|
||||
)
|
||||
}
|
||||
|
||||
fn type_name() -> String {
|
||||
"AttributeType".to_owned()
|
||||
}
|
||||
|
||||
fn array_type() -> ArrayType {
|
||||
ArrayType::String
|
||||
}
|
||||
|
||||
fn column_type() -> ColumnType {
|
||||
ColumnType::String(Some(64))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
pub struct Group {
|
||||
pub id: GroupId,
|
||||
pub display_name: GroupName,
|
||||
pub creation_date: NaiveDateTime,
|
||||
pub uuid: Uuid,
|
||||
pub users: Vec<UserId>,
|
||||
pub attributes: Vec<AttributeValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct GroupDetails {
|
||||
pub group_id: GroupId,
|
||||
pub display_name: GroupName,
|
||||
pub creation_date: NaiveDateTime,
|
||||
pub uuid: Uuid,
|
||||
pub attributes: Vec<AttributeValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct UserAndGroups {
|
||||
pub user: User,
|
||||
pub groups: Option<Vec<GroupDetails>>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_serialized_debug_string() {
|
||||
assert_eq!(
|
||||
&format!("{:?}", Serialized::from("abcd")),
|
||||
"Serialized(\"abcd\")"
|
||||
);
|
||||
assert_eq!(
|
||||
&format!("{:?}", Serialized::from(&1234i64)),
|
||||
"Serialized(\"1234\")"
|
||||
);
|
||||
assert_eq!(
|
||||
&format!("{:?}", Serialized::from(&JpegPhoto::for_tests())),
|
||||
"Serialized(\"hash: 0xB947C77A16F3C3BD\")"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialized_i64_len() {
|
||||
assert_eq!(SERIALIZED_I64_LEN, Serialized::from(&0i64).0.len());
|
||||
assert_eq!(SERIALIZED_I64_LEN, Serialized::from(&i64::MAX).0.len());
|
||||
assert_eq!(SERIALIZED_I64_LEN, Serialized::from(&i64::MIN).0.len());
|
||||
assert_eq!(SERIALIZED_I64_LEN, Serialized::from(&-1000i64).0.len());
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,18 @@ use tracing::info;
|
||||
use crate::domain::{
|
||||
error::Result,
|
||||
handler::{
|
||||
AttributeSchema, BackendHandler, CreateAttributeRequest, CreateGroupRequest,
|
||||
CreateUserRequest, GroupBackendHandler, GroupListerBackendHandler, GroupRequestFilter,
|
||||
ReadSchemaBackendHandler, Schema, SchemaBackendHandler, UpdateGroupRequest,
|
||||
UpdateUserRequest, UserBackendHandler, UserListerBackendHandler, UserRequestFilter,
|
||||
BackendHandler, GroupBackendHandler, GroupListerBackendHandler, GroupRequestFilter,
|
||||
ReadSchemaBackendHandler, SchemaBackendHandler, UserBackendHandler,
|
||||
UserListerBackendHandler, UserRequestFilter,
|
||||
},
|
||||
schema::PublicSchema,
|
||||
};
|
||||
use lldap_domain::{
|
||||
requests::{
|
||||
CreateAttributeRequest, CreateGroupRequest, CreateUserRequest, UpdateGroupRequest,
|
||||
UpdateUserRequest,
|
||||
},
|
||||
schema::{AttributeSchema, Schema},
|
||||
types::{
|
||||
AttributeName, Group, GroupDetails, GroupId, GroupName, LdapObjectClass, User,
|
||||
UserAndGroups, UserId,
|
||||
|
||||
@@ -22,13 +22,14 @@ use time::ext::NumericalDuration;
|
||||
use tracing::{debug, info, instrument, warn};
|
||||
|
||||
use lldap_auth::{login, password_reset, registration, JWTClaims};
|
||||
use lldap_domain::types::{GroupDetails, GroupName, UserId};
|
||||
|
||||
use crate::{
|
||||
domain::{
|
||||
error::DomainError,
|
||||
handler::{BackendHandler, BindRequest, LoginHandler, UserRequestFilter},
|
||||
model::UserColumn,
|
||||
opaque_handler::OpaqueHandler,
|
||||
types::{GroupDetails, GroupName, UserColumn, UserId},
|
||||
},
|
||||
infra::{
|
||||
access_control::{ReadonlyBackendHandler, UserReadableBackendHandler, ValidationResults},
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::{
|
||||
domain::{
|
||||
sql_tables::{ConfigLocation, PrivateKeyHash, PrivateKeyInfo, PrivateKeyLocation},
|
||||
types::{AttributeName, UserId},
|
||||
},
|
||||
domain::sql_tables::{ConfigLocation, PrivateKeyHash, PrivateKeyInfo, PrivateKeyLocation},
|
||||
infra::{
|
||||
cli::{
|
||||
GeneralConfigOpts, LdapsOpts, RunOpts, SmtpEncryption, SmtpOpts, TestEmailOpts,
|
||||
@@ -20,6 +17,7 @@ use figment::{
|
||||
};
|
||||
use figment_file_provider_adapter::FileAdapter;
|
||||
use lldap_auth::opaque::{server::ServerSetup, KeyPair};
|
||||
use lldap_domain::types::{AttributeName, UserId};
|
||||
use secstr::SecUtf8;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
@@ -623,7 +621,7 @@ where
|
||||
Either set the `jwt_secret` config value or the `LLDAP_JWT_SECRET` environment variable. \
|
||||
You can generate the value by running\n\
|
||||
LC_ALL=C tr -dc 'A-Za-z0-9!#%&'\\''()*+,-./:;<=>?@[\\]^_{{|}}~' </dev/urandom | head -c 32; echo ''\n\
|
||||
or you can use this random value: {}",
|
||||
or you can use this random value: {}",
|
||||
rand::thread_rng()
|
||||
.sample_iter(&Symbols)
|
||||
.take(32)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
domain::{handler::BackendHandler, types::UserId},
|
||||
domain::handler::BackendHandler,
|
||||
infra::{
|
||||
access_control::{
|
||||
AccessControlledBackendHandler, AdminBackendHandler, ReadonlyBackendHandler,
|
||||
@@ -11,6 +11,7 @@ use crate::{
|
||||
tcp_server::AppState,
|
||||
},
|
||||
};
|
||||
|
||||
use actix_web::FromRequest;
|
||||
use actix_web::HttpMessage;
|
||||
use actix_web::{error::JsonPayloadError, web, Error, HttpRequest, HttpResponse};
|
||||
@@ -22,6 +23,7 @@ use juniper::{
|
||||
},
|
||||
EmptySubscription, FieldError, RootNode, ScalarValue,
|
||||
};
|
||||
use lldap_domain::types::UserId;
|
||||
use tracing::debug;
|
||||
|
||||
pub struct Context<Handler: BackendHandler> {
|
||||
|
||||
@@ -2,16 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
domain::{
|
||||
deserialize::deserialize_attribute_value,
|
||||
handler::{
|
||||
AttributeList, BackendHandler, CreateAttributeRequest, CreateGroupRequest,
|
||||
CreateUserRequest, UpdateGroupRequest, UpdateUserRequest,
|
||||
},
|
||||
schema::PublicSchema,
|
||||
types::{
|
||||
AttributeName, AttributeType, AttributeValue as DomainAttributeValue, Email, GroupId,
|
||||
JpegPhoto, LdapObjectClass, UserId,
|
||||
},
|
||||
deserialize::deserialize_attribute_value, handler::BackendHandler, schema::PublicSchema,
|
||||
},
|
||||
infra::{
|
||||
access_control::{
|
||||
@@ -24,6 +15,17 @@ use crate::{
|
||||
use anyhow::{anyhow, Context as AnyhowContext};
|
||||
use base64::Engine;
|
||||
use juniper::{graphql_object, FieldError, FieldResult, GraphQLInputObject, GraphQLObject};
|
||||
use lldap_domain::{
|
||||
requests::{
|
||||
CreateAttributeRequest, CreateGroupRequest, CreateUserRequest, UpdateGroupRequest,
|
||||
UpdateUserRequest,
|
||||
},
|
||||
schema::AttributeList,
|
||||
types::{
|
||||
AttributeName, AttributeType, AttributeValue as DomainAttributeValue, Email, GroupId,
|
||||
JpegPhoto, LdapObjectClass, UserId,
|
||||
},
|
||||
};
|
||||
use lldap_validation::attributes::{validate_attribute_name, ALLOWED_CHARACTERS_DESCRIPTION};
|
||||
use tracing::{debug, debug_span, Instrument, Span};
|
||||
|
||||
@@ -731,18 +733,16 @@ fn deserialize_attribute(
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
domain::types::{AttributeName, AttributeType},
|
||||
infra::{
|
||||
access_control::{Permission, ValidationResults},
|
||||
graphql::query::Query,
|
||||
test_utils::MockTestBackendHandler,
|
||||
},
|
||||
use crate::infra::{
|
||||
access_control::{Permission, ValidationResults},
|
||||
graphql::query::Query,
|
||||
test_utils::MockTestBackendHandler,
|
||||
};
|
||||
use juniper::{
|
||||
execute, graphql_value, DefaultScalarValue, EmptySubscription, GraphQLType, InputValue,
|
||||
RootNode, Variables,
|
||||
};
|
||||
use lldap_domain::types::{AttributeName, AttributeType};
|
||||
use mockall::predicate::eq;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
|
||||
@@ -7,9 +7,6 @@ use crate::{
|
||||
ldap::utils::{map_user_field, UserFieldType},
|
||||
model::UserColumn,
|
||||
schema::PublicSchema,
|
||||
types::{
|
||||
AttributeType, GroupDetails, GroupId, JpegPhoto, LdapObjectClass, Serialized, UserId,
|
||||
},
|
||||
},
|
||||
infra::{
|
||||
access_control::{ReadonlyBackendHandler, UserReadableBackendHandler},
|
||||
@@ -19,16 +16,19 @@ use crate::{
|
||||
use anyhow::Context as AnyhowContext;
|
||||
use chrono::{NaiveDateTime, TimeZone};
|
||||
use juniper::{graphql_object, FieldResult, GraphQLInputObject};
|
||||
use lldap_domain::types::{
|
||||
AttributeType, GroupDetails, GroupId, JpegPhoto, LdapObjectClass, Serialized, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::{debug, debug_span, Instrument, Span};
|
||||
|
||||
type DomainRequestFilter = crate::domain::handler::UserRequestFilter;
|
||||
type DomainUser = crate::domain::types::User;
|
||||
type DomainGroup = crate::domain::types::Group;
|
||||
type DomainUserAndGroups = crate::domain::types::UserAndGroups;
|
||||
type DomainAttributeList = crate::domain::handler::AttributeList;
|
||||
type DomainAttributeSchema = crate::domain::handler::AttributeSchema;
|
||||
type DomainAttributeValue = crate::domain::types::AttributeValue;
|
||||
type DomainUser = lldap_domain::types::User;
|
||||
type DomainGroup = lldap_domain::types::Group;
|
||||
type DomainUserAndGroups = lldap_domain::types::UserAndGroups;
|
||||
type DomainAttributeList = lldap_domain::schema::AttributeList;
|
||||
type DomainAttributeSchema = lldap_domain::schema::AttributeSchema;
|
||||
type DomainAttributeValue = lldap_domain::types::AttributeValue;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, GraphQLInputObject)]
|
||||
/// A filter for requests, specifying a boolean expression based on field constraints. Only one of
|
||||
@@ -801,21 +801,19 @@ impl<Handler: BackendHandler> AttributeValue<Handler> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
domain::{
|
||||
handler::AttributeList,
|
||||
types::{AttributeName, AttributeType, LdapObjectClass, Serialized},
|
||||
},
|
||||
infra::{
|
||||
access_control::{Permission, ValidationResults},
|
||||
test_utils::{setup_default_schema, MockTestBackendHandler},
|
||||
},
|
||||
use crate::infra::{
|
||||
access_control::{Permission, ValidationResults},
|
||||
test_utils::{setup_default_schema, MockTestBackendHandler},
|
||||
};
|
||||
use chrono::TimeZone;
|
||||
use juniper::{
|
||||
execute, graphql_value, DefaultScalarValue, EmptyMutation, EmptySubscription, GraphQLType,
|
||||
RootNode, Variables,
|
||||
};
|
||||
use lldap_domain::{
|
||||
schema::{AttributeList, Schema},
|
||||
types::{AttributeName, AttributeType, LdapObjectClass, Serialized},
|
||||
};
|
||||
use mockall::predicate::eq;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashSet;
|
||||
@@ -860,7 +858,7 @@ mod tests {
|
||||
|
||||
let mut mock = MockTestBackendHandler::new();
|
||||
mock.expect_get_schema().returning(|| {
|
||||
Ok(crate::domain::handler::Schema {
|
||||
Ok(Schema {
|
||||
user_attributes: DomainAttributeList {
|
||||
attributes: vec![
|
||||
DomainAttributeSchema {
|
||||
@@ -908,7 +906,7 @@ mod tests {
|
||||
user_id: UserId::new("bob"),
|
||||
email: "bob@bobbers.on".into(),
|
||||
creation_date: chrono::Utc.timestamp_millis_opt(42).unwrap().naive_utc(),
|
||||
uuid: crate::uuid!("b1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"),
|
||||
uuid: lldap_domain::uuid!("b1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"),
|
||||
attributes: vec![
|
||||
DomainAttributeValue {
|
||||
name: "first_name".into(),
|
||||
@@ -927,7 +925,7 @@ mod tests {
|
||||
group_id: GroupId(3),
|
||||
display_name: "Bobbersons".into(),
|
||||
creation_date: chrono::Utc.timestamp_nanos(42).naive_utc(),
|
||||
uuid: crate::uuid!("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"),
|
||||
uuid: lldap_domain::uuid!("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"),
|
||||
attributes: vec![DomainAttributeValue {
|
||||
name: "club_name".into(),
|
||||
value: Serialized::from("Gang of Four"),
|
||||
@@ -937,7 +935,7 @@ mod tests {
|
||||
group_id: GroupId(7),
|
||||
display_name: "Jefferees".into(),
|
||||
creation_date: chrono::Utc.timestamp_nanos(12).naive_utc(),
|
||||
uuid: crate::uuid!("b1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"),
|
||||
uuid: lldap_domain::uuid!("b1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"),
|
||||
attributes: Vec::new(),
|
||||
});
|
||||
mock.expect_get_user_groups()
|
||||
@@ -1299,7 +1297,7 @@ mod tests {
|
||||
let mut mock = MockTestBackendHandler::new();
|
||||
|
||||
mock.expect_get_schema().times(1).return_once(|| {
|
||||
Ok(crate::domain::handler::Schema {
|
||||
Ok(Schema {
|
||||
user_attributes: AttributeList {
|
||||
attributes: vec![DomainAttributeSchema {
|
||||
name: "invisible".into(),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use crate::{
|
||||
domain::{
|
||||
handler::{
|
||||
BackendHandler, BindRequest, CreateUserRequest, LoginHandler, ReadSchemaBackendHandler,
|
||||
},
|
||||
handler::{BackendHandler, BindRequest, LoginHandler, ReadSchemaBackendHandler},
|
||||
ldap::{
|
||||
error::{LdapError, LdapResult},
|
||||
group::{convert_groups_to_ldap_op, get_groups_list},
|
||||
@@ -13,7 +11,6 @@ use crate::{
|
||||
},
|
||||
opaque_handler::OpaqueHandler,
|
||||
schema::PublicSchema,
|
||||
types::{AttributeName, Email, Group, JpegPhoto, UserAndGroups, UserId},
|
||||
},
|
||||
infra::access_control::{
|
||||
AccessControlledBackendHandler, AdminBackendHandler, UserAndGroupListerBackendHandler,
|
||||
@@ -28,6 +25,10 @@ use ldap3_proto::proto::{
|
||||
LdapResult as LdapResultOp, LdapResultCode, LdapSearchRequest, LdapSearchResultEntry,
|
||||
LdapSearchScope,
|
||||
};
|
||||
use lldap_domain::{
|
||||
requests::CreateUserRequest,
|
||||
types::{AttributeName, Email, Group, JpegPhoto, UserAndGroups, UserId},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use tracing::{debug, instrument, warn};
|
||||
|
||||
@@ -879,12 +880,15 @@ impl<Backend: BackendHandler + LoginHandler + OpaqueHandler> LdapHandler<Backend
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
domain::{handler::*, types::*},
|
||||
domain::handler::*,
|
||||
domain::model::UserColumn,
|
||||
infra::test_utils::{setup_default_schema, MockTestBackendHandler},
|
||||
uuid,
|
||||
};
|
||||
use chrono::TimeZone;
|
||||
use ldap3_proto::proto::{LdapDerefAliases, LdapSearchScope, LdapSubstringFilter};
|
||||
use lldap_domain::schema::{AttributeList, AttributeSchema, Schema};
|
||||
use lldap_domain::types::*;
|
||||
use lldap_domain::uuid;
|
||||
use mockall::predicate::eq;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashSet;
|
||||
@@ -1691,7 +1695,7 @@ mod tests {
|
||||
}])
|
||||
});
|
||||
mock.expect_get_schema().returning(|| {
|
||||
Ok(crate::domain::handler::Schema {
|
||||
Ok(Schema {
|
||||
user_attributes: AttributeList {
|
||||
attributes: Vec::new(),
|
||||
},
|
||||
@@ -3020,7 +3024,7 @@ mod tests {
|
||||
}])
|
||||
});
|
||||
mock.expect_get_schema().returning(|| {
|
||||
Ok(crate::domain::handler::Schema {
|
||||
Ok(Schema {
|
||||
user_attributes: AttributeList {
|
||||
attributes: vec![AttributeSchema {
|
||||
name: "nickname".into(),
|
||||
|
||||
@@ -2,7 +2,6 @@ use crate::{
|
||||
domain::{
|
||||
handler::{BackendHandler, LoginHandler},
|
||||
opaque_handler::OpaqueHandler,
|
||||
types::AttributeName,
|
||||
},
|
||||
infra::{
|
||||
access_control::AccessControlledBackendHandler,
|
||||
@@ -15,6 +14,7 @@ use actix_server::ServerBuilder;
|
||||
use actix_service::{fn_service, ServiceFactoryExt};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use ldap3_proto::{control::LdapControl, proto::LdapMsg, proto::LdapOp, LdapCodec};
|
||||
use lldap_domain::types::AttributeName;
|
||||
use rustls::PrivateKey;
|
||||
use tokio_rustls::TlsAcceptor as RustlsTlsAcceptor;
|
||||
use tokio_util::codec::{FramedRead, FramedWrite};
|
||||
|
||||
@@ -3,10 +3,10 @@ use crate::domain::{
|
||||
error::*,
|
||||
model::{self, JwtRefreshStorageColumn, JwtStorageColumn, PasswordResetTokensColumn},
|
||||
sql_backend_handler::SqlBackendHandler,
|
||||
types::UserId,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use chrono::NaiveDateTime;
|
||||
use lldap_domain::types::UserId;
|
||||
use sea_orm::{
|
||||
sea_query::{Cond, Expr},
|
||||
ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter, QuerySelect,
|
||||
|
||||
@@ -2,7 +2,8 @@ use async_trait::async_trait;
|
||||
use chrono::NaiveDateTime;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::domain::{error::Result, types::UserId};
|
||||
use crate::domain::error::Result;
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
#[async_trait]
|
||||
pub trait TcpBackendHandler: Sync {
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
use crate::domain::{error::Result, handler::*, opaque_handler::*, types::*};
|
||||
use crate::domain::{error::Result, handler::*, opaque_handler::*};
|
||||
use lldap_domain::{
|
||||
requests::{
|
||||
CreateAttributeRequest, CreateGroupRequest, CreateUserRequest, UpdateGroupRequest,
|
||||
UpdateUserRequest,
|
||||
},
|
||||
schema::{AttributeList, AttributeSchema, Schema},
|
||||
types::*,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use std::collections::HashSet;
|
||||
|
||||
+4
-2
@@ -8,8 +8,8 @@ use std::time::Duration;
|
||||
use crate::{
|
||||
domain::{
|
||||
handler::{
|
||||
CreateGroupRequest, CreateUserRequest, GroupBackendHandler, GroupListerBackendHandler,
|
||||
GroupRequestFilter, UserBackendHandler, UserListerBackendHandler, UserRequestFilter,
|
||||
GroupBackendHandler, GroupListerBackendHandler, GroupRequestFilter, UserBackendHandler,
|
||||
UserListerBackendHandler, UserRequestFilter,
|
||||
},
|
||||
sql_backend_handler::SqlBackendHandler,
|
||||
sql_opaque_handler::register_password,
|
||||
@@ -30,6 +30,8 @@ use futures_util::TryFutureExt;
|
||||
use sea_orm::{Database, DatabaseConnection};
|
||||
use tracing::{debug, error, info, instrument, span, warn, Instrument, Level};
|
||||
|
||||
use lldap_domain::requests::{CreateGroupRequest, CreateUserRequest};
|
||||
|
||||
mod domain;
|
||||
mod infra;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user