Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
55 lines
1.9 KiB
Rust
55 lines
1.9 KiB
Rust
/*
|
|
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
|
*/
|
|
|
|
use crate::{Account, Credentials, Directory, Recipient, backend::oidc::OidcDiscovery};
|
|
use registry::schema::enums::DirectoryType;
|
|
use trc::AddContext;
|
|
|
|
impl Directory {
|
|
pub async fn authenticate(&self, credentials: &Credentials) -> trc::Result<Account> {
|
|
match &self {
|
|
Directory::Ldap(store) => store.authenticate(credentials).await,
|
|
Directory::Sql(store) => store.authenticate(credentials).await,
|
|
Directory::OpenId(store) => store.authenticate(credentials).await,
|
|
Directory::Unavailable(directory) => Err(directory.error()),
|
|
}
|
|
.caused_by(trc::location!())
|
|
}
|
|
|
|
pub async fn recipient(&self, address: &str) -> trc::Result<Recipient> {
|
|
match &self {
|
|
Directory::Ldap(store) => store.recipient(address).await,
|
|
Directory::Sql(store) => store.recipient(address).await,
|
|
Directory::OpenId(_) => Ok(Recipient::Invalid), // OIDC directories do not support recipient lookups
|
|
Directory::Unavailable(directory) => Err(directory.error()),
|
|
}
|
|
.caused_by(trc::location!())
|
|
}
|
|
|
|
pub fn has_bearer_token_support(&self) -> bool {
|
|
match &self {
|
|
Directory::OpenId(_) => true,
|
|
Directory::Unavailable(directory) => directory.directory_type() == DirectoryType::Oidc,
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
pub fn can_lookup_recipients(&self) -> bool {
|
|
match &self {
|
|
Directory::OpenId(_) => false,
|
|
Directory::Unavailable(directory) => directory.directory_type() != DirectoryType::Oidc,
|
|
_ => true,
|
|
}
|
|
}
|
|
|
|
pub fn oidc_discovery_document(&self) -> Option<&OidcDiscovery> {
|
|
match &self {
|
|
Directory::OpenId(directory) => Some(&directory.discovery),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|