Skip to content

Commit 6f6d2cb

Browse files
committed
feat: Add identity.get_user_domain_id method
There are lot of cases where it is necessary to determine the `domain_id` by the `user_id`. Fetching the whole user is relatively expensive due to the multiple table joins while the attribute itself is present already on the main table entry. Implement a method that only returns the `domain_id` attribute by the `user_id`. Since this data can never change (unless somebody mess directly in the database) caching can be implemented to further improve the performance (when `conf.identity.caching` is true).
1 parent e4774ad commit 6f6d2cb

File tree

19 files changed

+672
-387
lines changed

19 files changed

+672
-387
lines changed

src/application_credential/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ mod mock;
139139
pub mod types;
140140

141141
/// Application Credential Provider.
142-
#[derive(Clone)]
143142
pub struct ApplicationCredentialProvider {
144143
backend_driver: Arc<dyn ApplicationCredentialBackend>,
145144
}

src/assignment/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ use crate::resource::ResourceApi;
7373
pub use mock::MockAssignmentProvider;
7474
pub use types::AssignmentApi;
7575

76-
#[derive(Clone)]
7776
pub struct AssignmentProvider {
7877
backend_driver: Arc<dyn AssignmentBackend>,
7978
}

src/catalog/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ pub use types::CatalogApi;
5252

5353
use types::*;
5454

55-
#[derive(Clone)]
5655
pub struct CatalogProvider {
5756
backend_driver: Arc<dyn CatalogBackend>,
5857
}

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ pub struct IdentityProvider {
263263
#[serde(default = "default_sql_driver")]
264264
pub driver: String,
265265

266+
/// Caching.
267+
#[serde(default)]
268+
pub caching: bool,
269+
266270
/// Default password hashing algorithm.
267271
#[serde(default)]
268272
pub password_hashing_algorithm: PasswordHashingAlgo,
@@ -282,6 +286,7 @@ impl Default for IdentityProvider {
282286
fn default() -> Self {
283287
Self {
284288
driver: default_sql_driver(),
289+
caching: false,
285290
password_hashing_algorithm: PasswordHashingAlgo::Bcrypt,
286291
max_password_length: 4096,
287292
password_hash_rounds: None,

src/federation/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use types::*;
3737
pub use mock::MockFederationProvider;
3838
pub use types::FederationApi;
3939

40-
#[derive(Clone)]
4140
pub struct FederationProvider {
4241
backend_driver: Arc<dyn FederationBackend>,
4342
}

src/identity/backend.rs

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,51 @@ pub mod sql;
2727
#[cfg_attr(test, mockall::automock)]
2828
#[async_trait]
2929
pub trait IdentityBackend: Send + Sync {
30-
/// Authenticate a user by a password.
31-
async fn authenticate_by_password(
30+
/// Add the user to the group.
31+
async fn add_user_to_group<'a>(
3232
&self,
3333
state: &ServiceState,
34-
auth: &UserPasswordAuthRequest,
35-
) -> Result<AuthenticatedInfo, IdentityProviderError>;
34+
user_id: &'a str,
35+
group_id: &'a str,
36+
) -> Result<(), IdentityProviderError>;
3637

37-
/// List Users.
38-
async fn list_users(
38+
/// Add the user to the group with expiration.
39+
async fn add_user_to_group_expiring<'a>(
3940
&self,
4041
state: &ServiceState,
41-
params: &UserListParameters,
42-
) -> Result<Vec<UserResponse>, IdentityProviderError>;
42+
user_id: &'a str,
43+
group_id: &'a str,
44+
idp_id: &'a str,
45+
) -> Result<(), IdentityProviderError>;
4346

44-
/// Get single user by ID.
45-
async fn get_user<'a>(
47+
/// Add user group membership relations.
48+
async fn add_users_to_groups<'a>(
4649
&self,
4750
state: &ServiceState,
48-
user_id: &'a str,
49-
) -> Result<Option<UserResponse>, IdentityProviderError>;
51+
memberships: Vec<(&'a str, &'a str)>,
52+
) -> Result<(), IdentityProviderError>;
5053

51-
/// Find federated user by IDP and Unique ID.
52-
async fn find_federated_user<'a>(
54+
/// Add expiring user group membership relations.
55+
async fn add_users_to_groups_expiring<'a>(
5356
&self,
5457
state: &ServiceState,
58+
memberships: Vec<(&'a str, &'a str)>,
5559
idp_id: &'a str,
56-
unique_id: &'a str,
57-
) -> Result<Option<UserResponse>, IdentityProviderError>;
60+
) -> Result<(), IdentityProviderError>;
61+
62+
/// Authenticate a user by a password.
63+
async fn authenticate_by_password(
64+
&self,
65+
state: &ServiceState,
66+
auth: &UserPasswordAuthRequest,
67+
) -> Result<AuthenticatedInfo, IdentityProviderError>;
68+
69+
/// Create group.
70+
async fn create_group(
71+
&self,
72+
state: &ServiceState,
73+
group: GroupCreate,
74+
) -> Result<Group, IdentityProviderError>;
5875

5976
/// Create user.
6077
async fn create_user(
@@ -63,19 +80,19 @@ pub trait IdentityBackend: Send + Sync {
6380
user: UserCreate,
6481
) -> Result<UserResponse, IdentityProviderError>;
6582

66-
/// Delete user.
67-
async fn delete_user<'a>(
83+
/// Delete group by ID.
84+
async fn delete_group<'a>(
6885
&self,
6986
state: &ServiceState,
70-
user_id: &'a str,
87+
group_id: &'a str,
7188
) -> Result<(), IdentityProviderError>;
7289

73-
/// List groups.
74-
async fn list_groups(
90+
/// Delete user.
91+
async fn delete_user<'a>(
7592
&self,
7693
state: &ServiceState,
77-
params: &GroupListParameters,
78-
) -> Result<Vec<Group>, IdentityProviderError>;
94+
user_id: &'a str,
95+
) -> Result<(), IdentityProviderError>;
7996

8097
/// Get single group by ID.
8198
async fn get_group<'a>(
@@ -84,58 +101,48 @@ pub trait IdentityBackend: Send + Sync {
84101
group_id: &'a str,
85102
) -> Result<Option<Group>, IdentityProviderError>;
86103

87-
/// Create group.
88-
async fn create_group(
89-
&self,
90-
state: &ServiceState,
91-
group: GroupCreate,
92-
) -> Result<Group, IdentityProviderError>;
93-
94-
/// Delete group by ID.
95-
async fn delete_group<'a>(
104+
/// Get single user by ID.
105+
async fn get_user<'a>(
96106
&self,
97107
state: &ServiceState,
98-
group_id: &'a str,
99-
) -> Result<(), IdentityProviderError>;
108+
user_id: &'a str,
109+
) -> Result<Option<UserResponse>, IdentityProviderError>;
100110

101-
/// List groups a user is member of.
102-
async fn list_groups_of_user<'a>(
111+
/// Get single user by ID.
112+
async fn get_user_domain_id<'a>(
103113
&self,
104114
state: &ServiceState,
105115
user_id: &'a str,
106-
) -> Result<Vec<Group>, IdentityProviderError>;
116+
) -> Result<Option<String>, IdentityProviderError>;
107117

108-
/// Add the user to the group.
109-
async fn add_user_to_group<'a>(
118+
/// Find federated user by IDP and Unique ID.
119+
async fn find_federated_user<'a>(
110120
&self,
111121
state: &ServiceState,
112-
user_id: &'a str,
113-
group_id: &'a str,
114-
) -> Result<(), IdentityProviderError>;
122+
idp_id: &'a str,
123+
unique_id: &'a str,
124+
) -> Result<Option<UserResponse>, IdentityProviderError>;
115125

116-
/// Add the user to the group with expiration.
117-
async fn add_user_to_group_expiring<'a>(
126+
/// List groups.
127+
async fn list_groups(
118128
&self,
119129
state: &ServiceState,
120-
user_id: &'a str,
121-
group_id: &'a str,
122-
idp_id: &'a str,
123-
) -> Result<(), IdentityProviderError>;
130+
params: &GroupListParameters,
131+
) -> Result<Vec<Group>, IdentityProviderError>;
124132

125-
/// Add user group membership relations.
126-
async fn add_users_to_groups<'a>(
133+
/// List Users.
134+
async fn list_users(
127135
&self,
128136
state: &ServiceState,
129-
memberships: Vec<(&'a str, &'a str)>,
130-
) -> Result<(), IdentityProviderError>;
137+
params: &UserListParameters,
138+
) -> Result<Vec<UserResponse>, IdentityProviderError>;
131139

132-
/// Add expiring user group membership relations.
133-
async fn add_users_to_groups_expiring<'a>(
140+
/// List groups a user is member of.
141+
async fn list_groups_of_user<'a>(
134142
&self,
135143
state: &ServiceState,
136-
memberships: Vec<(&'a str, &'a str)>,
137-
idp_id: &'a str,
138-
) -> Result<(), IdentityProviderError>;
144+
user_id: &'a str,
145+
) -> Result<Vec<Group>, IdentityProviderError>;
139146

140147
/// Remove the user from the group.
141148
async fn remove_user_from_group<'a>(

0 commit comments

Comments
 (0)