use std::sync::Arc;
use super::{
aad_authentication_settings::AadAuthenticationSettings,
acl_authentication_settings::AclAuthenticationSettings,
authentication_settings::{AuthSetup, IAuthenticationSettings},
};
use crate::{
acl::{AccessControlList, AclError},
auth::{GarnetAclWithAadAuthenticator, IGarnetAuthenticator},
};
pub struct AclAuthenticationAadSettings {
pub base: AclAuthenticationSettings,
aad_authentication_settings: AadAuthenticationSettings,
}
impl AclAuthenticationAadSettings {
pub fn new(
acl_configuration_file: Option<String>,
default_password: String,
aad_authentication_settings: AadAuthenticationSettings,
) -> Self {
Self {
base: AclAuthenticationSettings::new(acl_configuration_file, default_password),
aad_authentication_settings,
}
}
fn create_authenticator_internal(
&self,
acl: &Arc<AccessControlList>,
) -> Result<Box<dyn IGarnetAuthenticator>, AclError> {
let aad = self
.aad_authentication_settings
.create_authenticator(&AuthSetup {
acl: Some(Arc::clone(acl)),
})?;
Ok(Box::new(GarnetAclWithAadAuthenticator::new(
Arc::clone(acl),
aad,
)))
}
}
impl IAuthenticationSettings for AclAuthenticationAadSettings {
fn create_authenticator(
&self,
setup: &AuthSetup,
) -> Result<Box<dyn IGarnetAuthenticator>, AclError> {
let acl = setup.acl.clone().ok_or_else(|| {
AclError::Acl("ACL authentication settings require a loaded AccessControlList".into())
})?;
self.create_authenticator_internal(&acl)
}
}