1313// SPDX-License-Identifier: Apache-2.0
1414
1515use async_trait:: async_trait;
16+ use chrono:: { DateTime , Utc } ;
1617use std:: collections:: HashSet ;
1718use webauthn_rs:: prelude:: { Passkey , PasskeyAuthentication , PasskeyRegistration } ;
1819
@@ -162,7 +163,15 @@ impl IdentityBackend for SqlBackend {
162163 state : & ServiceState ,
163164 user_id : & ' a str ,
164165 ) -> Result < Vec < Group > , IdentityProviderError > {
165- Ok ( user_group:: list_user_groups ( & state. db , user_id) . await ?)
166+ Ok ( user_group:: list_user_groups (
167+ & state. db ,
168+ user_id,
169+ & self
170+ . config
171+ . federation
172+ . get_expiring_user_group_membership_cutof_datetime ( ) ,
173+ )
174+ . await ?)
166175 }
167176
168177 /// Add the user into the group.
@@ -176,6 +185,21 @@ impl IdentityBackend for SqlBackend {
176185 Ok ( user_group:: add_user_to_group ( & state. db , user_id, group_id) . await ?)
177186 }
178187
188+ /// Add the user to the group with expiration.
189+ #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
190+ async fn add_user_to_group_expiring < ' a > (
191+ & self ,
192+ state : & ServiceState ,
193+ user_id : & ' a str ,
194+ group_id : & ' a str ,
195+ idp_id : & ' a str ,
196+ ) -> Result < ( ) , IdentityProviderError > {
197+ Ok (
198+ user_group:: add_user_to_group_expiring ( & state. db , user_id, group_id, idp_id, None )
199+ . await ?,
200+ )
201+ }
202+
179203 /// Add user group membership relations.
180204 #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
181205 async fn add_users_to_groups < ' a > (
@@ -186,6 +210,17 @@ impl IdentityBackend for SqlBackend {
186210 Ok ( user_group:: add_users_to_groups ( & state. db , memberships) . await ?)
187211 }
188212
213+ /// Add expiring user group membership relations.
214+ #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
215+ async fn add_users_to_groups_expiring < ' a > (
216+ & self ,
217+ state : & ServiceState ,
218+ memberships : Vec < ( & ' a str , & ' a str ) > ,
219+ idp_id : & ' a str ,
220+ ) -> Result < ( ) , IdentityProviderError > {
221+ Ok ( user_group:: add_users_to_groups_expiring ( & state. db , memberships, idp_id, None ) . await ?)
222+ }
223+
189224 /// Remove the user from the group.
190225 #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
191226 async fn remove_user_from_group < ' a > (
@@ -197,6 +232,21 @@ impl IdentityBackend for SqlBackend {
197232 Ok ( user_group:: remove_user_from_group ( & state. db , user_id, group_id) . await ?)
198233 }
199234
235+ /// Remove the user from the group with expiration.
236+ #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
237+ async fn remove_user_from_group_expiring < ' a > (
238+ & self ,
239+ state : & ServiceState ,
240+ user_id : & ' a str ,
241+ group_id : & ' a str ,
242+ idp_id : & ' a str ,
243+ ) -> Result < ( ) , IdentityProviderError > {
244+ Ok (
245+ user_group:: remove_user_from_group_expiring ( & state. db , user_id, group_id, idp_id)
246+ . await ?,
247+ )
248+ }
249+
200250 /// Remove the user from multiple groups.
201251 #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
202252 async fn remove_user_from_groups < ' a > (
@@ -208,6 +258,21 @@ impl IdentityBackend for SqlBackend {
208258 Ok ( user_group:: remove_user_from_groups ( & state. db , user_id, group_ids) . await ?)
209259 }
210260
261+ /// Remove the user from multiple expiring groups.
262+ #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
263+ async fn remove_user_from_groups_expiring < ' a > (
264+ & self ,
265+ state : & ServiceState ,
266+ user_id : & ' a str ,
267+ group_ids : HashSet < & ' a str > ,
268+ idp_id : & ' a str ,
269+ ) -> Result < ( ) , IdentityProviderError > {
270+ Ok (
271+ user_group:: remove_user_from_groups_expiring ( & state. db , user_id, group_ids, idp_id)
272+ . await ?,
273+ )
274+ }
275+
211276 /// Set group memberships of the user.
212277 #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
213278 async fn set_user_groups < ' a > (
@@ -219,6 +284,26 @@ impl IdentityBackend for SqlBackend {
219284 Ok ( user_group:: set_user_groups ( & state. db , user_id, group_ids) . await ?)
220285 }
221286
287+ /// Set expiring group memberships for the user.
288+ #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
289+ async fn set_user_groups_expiring < ' a > (
290+ & self ,
291+ state : & ServiceState ,
292+ user_id : & ' a str ,
293+ group_ids : HashSet < & ' a str > ,
294+ idp_id : & ' a str ,
295+ last_verified : Option < & DateTime < Utc > > ,
296+ ) -> Result < ( ) , IdentityProviderError > {
297+ Ok ( user_group:: set_user_groups_expiring (
298+ & state. db ,
299+ user_id,
300+ group_ids,
301+ idp_id,
302+ last_verified,
303+ )
304+ . await ?)
305+ }
306+
222307 /// Create webauthn credential for the user.
223308 #[ tracing:: instrument( level = "debug" , skip( self , state) ) ]
224309 async fn create_user_webauthn_credential < ' a > (
0 commit comments