Skip to content

Commit eff9f90

Browse files
authored
feat: Start implementing IdMapping provider (#486)
1 parent 28b7c45 commit eff9f90

File tree

23 files changed

+969
-273
lines changed

23 files changed

+969
-273
lines changed

src/assignment/backend/sql/assignment/list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ pub async fn list_for_multiple_actors_and_targets(
198198

199199
/// Select regular assignments.
200200
///
201-
/// Return Vec<Assignment> for the regular role assignments or `None` when no corresponding targets
202-
/// were given in the query parameters.
201+
/// Return Vec<Assignment> for the regular role assignments or `None` when no
202+
/// corresponding targets were given in the query parameters.
203203
async fn list_for_multiple_actors_and_targets_regular(
204204
db: &DatabaseConnection,
205205
params: &RoleAssignmentListForMultipleActorTargetParameters,
@@ -255,8 +255,8 @@ async fn list_for_multiple_actors_and_targets_regular(
255255

256256
/// Select system assignments.
257257
///
258-
/// Return Vec<Assignment> for the regular role assignments or `None` when no corresponding targets
259-
/// were given in the query parameters.
258+
/// Return Vec<Assignment> for the regular role assignments or `None` when no
259+
/// corresponding targets were given in the query parameters.
260260
async fn list_for_multiple_actors_and_targets_system(
261261
db: &DatabaseConnection,
262262
params: &RoleAssignmentListForMultipleActorTargetParameters,

src/config.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ pub struct Config {
5858
//#[serde(default)]
5959
pub database: DatabaseSection,
6060

61-
/// Identity provider configuration configuration.
61+
/// Identity provider configuration.
6262
#[serde(default)]
6363
pub identity: IdentityProvider,
6464

65+
/// Identity mapping provider configuration.
66+
#[serde(default)]
67+
pub identity_mapping: IdentityMappingProvider,
68+
6569
/// API policy enforcement.
6670
#[serde(default)]
6771
pub api_policy: PolicyProvider,
@@ -251,6 +255,7 @@ impl FederationProvider {
251255
.unwrap_or(Utc::now())
252256
}
253257
}
258+
254259
/// Identity provider.
255260
#[derive(Debug, Deserialize, Clone)]
256261
pub struct IdentityProvider {
@@ -285,6 +290,22 @@ impl Default for IdentityProvider {
285290
}
286291
}
287292

293+
/// Identity mapping provider.
294+
#[derive(Debug, Deserialize, Clone)]
295+
pub struct IdentityMappingProvider {
296+
/// Identity provider driver.
297+
#[serde(default = "default_sql_driver")]
298+
pub driver: String,
299+
}
300+
301+
impl Default for IdentityMappingProvider {
302+
fn default() -> Self {
303+
Self {
304+
driver: default_sql_driver(),
305+
}
306+
}
307+
}
308+
288309
/// Resource provider (domain, project).
289310
#[derive(Debug, Deserialize, Clone)]
290311
pub struct ResourceProvider {

src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::assignment::error::*;
2121
use crate::catalog::error::*;
2222
use crate::federation::error::*;
2323
use crate::identity::error::*;
24+
use crate::identity_mapping::error::*;
2425
use crate::policy::*;
2526
use crate::resource::error::*;
2627
use crate::revoke::error::*;
@@ -70,6 +71,14 @@ pub enum KeystoneError {
7071
source: IdentityProviderError,
7172
},
7273

74+
/// Identity mapping provider.
75+
#[error(transparent)]
76+
IdentityMappingError {
77+
/// The source of the error.
78+
#[from]
79+
source: IdentityMappingError,
80+
},
81+
7382
/// IO error.
7483
#[error(transparent)]
7584
IO {

src/identity/backends/fake.rs

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/identity/backends/sql/user/list.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ use crate::identity::types::*;
3030

3131
/// List users.
3232
///
33-
/// List users in the database. Fetch matching `user` table entries first. Afterwards fetch in
34-
/// parallel `local_user`, `nonlocal_user`, `federated_user`, `user_option` entries merging results
35-
/// to the proper entry. For the local users additionally passwords are being retrieved to identify
33+
/// List users in the database. Fetch matching `user` table entries first.
34+
/// Afterwards fetch in parallel `local_user`, `nonlocal_user`,
35+
/// `federated_user`, `user_option` entries merging results to the proper entry.
36+
/// For the local users additionally passwords are being retrieved to identify
3637
/// the password expiration date.
3738
pub async fn list(
3839
conf: &Config,
@@ -101,8 +102,8 @@ pub async fn list(
101102
)
102103
.await?;
103104

104-
// Determine the date for which users with the last activity earlier than are determined as
105-
// inactive.
105+
// Determine the date for which users with the last activity earlier than are
106+
// determined as inactive.
106107
let last_activity_cutof_date = conf.get_user_last_activity_cutof_date();
107108

108109
let mut results: Vec<UserResponse> = Vec::new();

src/identity/types.rs

Lines changed: 4 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -12,171 +12,10 @@
1212
//
1313
// SPDX-License-Identifier: Apache-2.0
1414

15-
use chrono::{DateTime, Utc};
16-
use std::collections::HashSet;
17-
1815
pub mod group;
16+
pub mod provider_api;
1917
pub mod user;
2018

21-
use async_trait::async_trait;
22-
23-
use crate::auth::AuthenticatedInfo;
24-
use crate::identity::IdentityProviderError;
25-
pub use crate::identity::types::group::{Group, GroupCreate, GroupListParameters};
26-
pub use crate::identity::types::user::*;
27-
use crate::keystone::ServiceState;
28-
29-
#[async_trait]
30-
pub trait IdentityApi: Send + Sync + Clone {
31-
async fn authenticate_by_password(
32-
&self,
33-
state: &ServiceState,
34-
auth: &UserPasswordAuthRequest,
35-
) -> Result<AuthenticatedInfo, IdentityProviderError>;
36-
37-
async fn list_users(
38-
&self,
39-
state: &ServiceState,
40-
params: &UserListParameters,
41-
) -> Result<impl IntoIterator<Item = UserResponse>, IdentityProviderError>;
42-
43-
async fn get_user<'a>(
44-
&self,
45-
state: &ServiceState,
46-
user_id: &'a str,
47-
) -> Result<Option<UserResponse>, IdentityProviderError>;
48-
49-
async fn find_federated_user<'a>(
50-
&self,
51-
state: &ServiceState,
52-
idp_id: &'a str,
53-
unique_id: &'a str,
54-
) -> Result<Option<UserResponse>, IdentityProviderError>;
55-
56-
async fn create_user(
57-
&self,
58-
state: &ServiceState,
59-
user: UserCreate,
60-
) -> Result<UserResponse, IdentityProviderError>;
61-
62-
async fn delete_user<'a>(
63-
&self,
64-
state: &ServiceState,
65-
user_id: &'a str,
66-
) -> Result<(), IdentityProviderError>;
67-
68-
async fn list_groups(
69-
&self,
70-
state: &ServiceState,
71-
params: &GroupListParameters,
72-
) -> Result<impl IntoIterator<Item = Group>, IdentityProviderError>;
73-
74-
async fn get_group<'a>(
75-
&self,
76-
state: &ServiceState,
77-
group_id: &'a str,
78-
) -> Result<Option<Group>, IdentityProviderError>;
79-
80-
async fn create_group(
81-
&self,
82-
state: &ServiceState,
83-
group: GroupCreate,
84-
) -> Result<Group, IdentityProviderError>;
85-
86-
async fn delete_group<'a>(
87-
&self,
88-
state: &ServiceState,
89-
group_id: &'a str,
90-
) -> Result<(), IdentityProviderError>;
91-
92-
/// List groups the user is a member of.
93-
async fn list_groups_of_user<'a>(
94-
&self,
95-
state: &ServiceState,
96-
user_id: &'a str,
97-
) -> Result<impl IntoIterator<Item = Group>, IdentityProviderError>;
98-
99-
/// Add the user to the single group.
100-
async fn add_user_to_group<'a>(
101-
&self,
102-
state: &ServiceState,
103-
user_id: &'a str,
104-
group_id: &'a str,
105-
) -> Result<(), IdentityProviderError>;
106-
107-
/// Add the user to the single group with expiration.
108-
async fn add_user_to_group_expiring<'a>(
109-
&self,
110-
state: &ServiceState,
111-
user_id: &'a str,
112-
group_id: &'a str,
113-
idp_id: &'a str,
114-
) -> Result<(), IdentityProviderError>;
115-
116-
/// Add user group memberships as specified by (uid, gid) tuples.
117-
async fn add_users_to_groups<'a>(
118-
&self,
119-
state: &ServiceState,
120-
memberships: Vec<(&'a str, &'a str)>,
121-
) -> Result<(), IdentityProviderError>;
122-
123-
/// Add expiring user group memberships as specified by (uid, gid) tuples.
124-
async fn add_users_to_groups_expiring<'a>(
125-
&self,
126-
state: &ServiceState,
127-
memberships: Vec<(&'a str, &'a str)>,
128-
idp_id: &'a str,
129-
) -> Result<(), IdentityProviderError>;
130-
131-
/// Remove the user from the single group.
132-
async fn remove_user_from_group<'a>(
133-
&self,
134-
state: &ServiceState,
135-
user_id: &'a str,
136-
group_id: &'a str,
137-
) -> Result<(), IdentityProviderError>;
138-
139-
/// Remove the user from the single group with expiration.
140-
async fn remove_user_from_group_expiring<'a>(
141-
&self,
142-
state: &ServiceState,
143-
user_id: &'a str,
144-
group_id: &'a str,
145-
idp_id: &'a str,
146-
) -> Result<(), IdentityProviderError>;
147-
148-
/// Remove the user from specified groups.
149-
async fn remove_user_from_groups<'a>(
150-
&self,
151-
state: &ServiceState,
152-
user_id: &'a str,
153-
group_ids: HashSet<&'a str>,
154-
) -> Result<(), IdentityProviderError>;
155-
156-
/// Remove the user from specified groups with expiration.
157-
async fn remove_user_from_groups_expiring<'a>(
158-
&self,
159-
state: &ServiceState,
160-
user_id: &'a str,
161-
group_ids: HashSet<&'a str>,
162-
idp_id: &'a str,
163-
) -> Result<(), IdentityProviderError>;
164-
165-
/// Set group memberships of the user.
166-
async fn set_user_groups<'a>(
167-
&self,
168-
state: &ServiceState,
169-
user_id: &'a str,
170-
group_ids: HashSet<&'a str>,
171-
) -> Result<(), IdentityProviderError>;
172-
173-
/// Set expiring group memberships of the user.
174-
async fn set_user_groups_expiring<'a>(
175-
&self,
176-
state: &ServiceState,
177-
user_id: &'a str,
178-
group_ids: HashSet<&'a str>,
179-
idp_id: &'a str,
180-
last_verified: Option<&'a DateTime<Utc>>,
181-
) -> Result<(), IdentityProviderError>;
182-
}
19+
pub use group::*;
20+
pub use provider_api::IdentityApi;
21+
pub use user::*;

0 commit comments

Comments
 (0)