Skip to main content

kanidm_proto/
attribute.rs

1use crate::{constants::*, internal::OperationError};
2use serde::{Deserialize, Serialize};
3use std::{convert::Infallible, fmt, str::FromStr};
4use utoipa::ToSchema;
5
6pub use smartstring::alias::String as AttrString;
7
8#[derive(
9    Serialize, Deserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Default, ToSchema,
10)]
11#[cfg_attr(test, derive(enum_iterator::Sequence))]
12#[serde(rename_all = "lowercase", from = "String", into = "AttrString")]
13pub enum Attribute {
14    Account,
15    AccountExpire,
16    AccountValidFrom,
17    AccountSoftlockExpire,
18    AcpCreateAttr,
19    AcpCreateClass,
20    AcpEnable,
21    AcpModifyClass,
22    AcpModifyPresentClass,
23    AcpModifyRemoveClass,
24    AcpModifyPresentAttr,
25    AcpModifyRemovedAttr,
26    AcpReceiver,
27    AcpReceiverGroup,
28    AcpSearchAttr,
29    AcpTargetScope,
30    ApiTokenSession,
31    ApplicationPassword,
32    ApplicationUrl,
33    AttestedPasskeys,
34    #[default]
35    Attr,
36    AttributeName,
37    AttributeType,
38    AuthSessionExpiry,
39    AuthPasswordMinimumLength,
40    BadlistPassword,
41    Certificate,
42    CascadeDeleted,
43    Claim,
44    Class,
45    ClassName,
46    Cn,
47    CookiePrivateKey,
48    CreatedAtCid,
49    CredentialUpdateIntentToken,
50    CredentialTypeMinimum,
51    DeniedName,
52    DeleteAfter,
53    Description,
54    DirectMemberOf,
55    DisplayName,
56    Dn,
57    Domain,
58    DomainAllowEasterEggs,
59    DomainAllowAccountRecovery,
60    DomainDevelopmentTaint,
61    DomainDisplayName,
62    DomainLdapBasedn,
63    DomainName,
64    DomainSsid,
65    DomainTokenKey,
66    DomainUuid,
67    DynGroup,
68    DynGroupFilter,
69    DynMember,
70    Enabled,
71    Email,
72    EmailAlternative,
73    EmailPrimary,
74    EntryDn,
75    EntryManagedBy,
76    EntryUuid,
77    Es256PrivateKeyDer,
78    Excludes,
79    FernetPrivateKeyStr,
80    Gecos,
81    GidNumber,
82    GrantUiHint,
83    Group,
84    HmacNameHistory,
85    HomeDirectory,
86    IdVerificationEcKey,
87    Image,
88    Index,
89    Indexed,
90    InMemoriam,
91    IpaNtHash,
92    IpaSshPubKey,
93    JwsEs256PrivateKey,
94    KeyActionRotate,
95    KeyActionRevoke,
96    KeyActionImportJwsEs256,
97    KeyActionImportJwsRs256,
98    KeyInternalData,
99    KeyProvider,
100    LastModifiedCid,
101    LdapAllowUnixPwBind,
102    /// An LDAP Compatible emailAddress
103    LdapEmailAddress,
104    /// An LDAP Compatible sshkeys virtual attribute
105    LdapKeys,
106    LdapMaxQueryableAttrs,
107    LegalName,
108    LimitSearchMaxResults,
109    LimitSearchMaxFilterTest,
110    LinkedGroup,
111    LoginShell,
112    Mail,
113    MailDestination,
114    May,
115    Member,
116    MemberCreateOnce,
117    MemberOf,
118    MessageTemplate,
119    MultiValue,
120    Must,
121    Name,
122    NameHistory,
123    NoIndex,
124    NsUniqueId,
125    NsAccountLock,
126    OAuth2AllowInsecureClientDisablePkce,
127    OAuth2AllowLocalhostRedirect,
128    OAuth2AuthorisationEndpoint,
129    OAuth2ClientId,
130    OAuth2ClientSecret,
131    OAuth2ConsentScopeMap,
132    OAuth2DeviceFlowEnable,
133    OAuth2JwtLegacyCryptoEnable,
134    OAuth2PreferShortUsername,
135    OAuth2RefreshTokenExpiry,
136    OAuth2RequestScopes,
137    OAuth2RsBasicSecret,
138    OAuth2RsClaimMap,
139    OAuth2RsImplicitScopes,
140    OAuth2RsName,
141    OAuth2RsOrigin,
142    OAuth2RsOriginLanding,
143    OAuth2RsScopeMap,
144    OAuth2RsSupScopeMap,
145    OAuth2RsTokenKey,
146    OAuth2Session,
147    OAuth2StrictRedirectUri,
148    OAuth2TokenEndpoint,
149    OAuth2TokenIntrospectEndpoint,
150    OAuth2AccountCredentialUuid,
151    OAuth2AccountProvider,
152    OAuth2AccountUniqueUserId,
153    OAuth2AccountUniqueUserSub,
154    OAuth2ConsentPromptEnable,
155    ObjectClass,
156    OtherNoIndex,
157    PassKeys,
158    PasswordImport,
159    PasswordChangedTime,
160    PatchLevel,
161    Phantom,
162    PrimaryCredential,
163    PrivateCookieKey,
164    PrivilegeExpiry,
165    RadiusSecret,
166    RecycledDirectMemberOf,
167    Refers,
168    Replicated,
169    Rs256PrivateKeyDer,
170    S256,
171    /// A set of scim schemas. This is similar to a kanidm class.
172    #[serde(rename = "schemas")]
173    ScimSchemas,
174    Scope,
175    SendAfter,
176    SentAt,
177    SourceUuid,
178    Spn,
179    /// An LDAP-compatible sshpublickey
180    LdapSshPublicKey,
181    /// The Kanidm-local ssh_publickey
182    SshPublicKey,
183    SudoHost,
184    Supplements,
185    SystemSupplements,
186    SyncAllowed,
187    SyncClass,
188    SyncCookie,
189    SyncCredentialPortal,
190    SyncExternalId,
191    SyncParentUuid,
192    SyncTokenSession,
193    SyncYieldAuthority,
194    Syntax,
195    SystemExcludes,
196    SystemMay,
197    SystemMust,
198    Term,
199    TotpImport,
200    Uid,
201    UidNumber,
202    Unique,
203    UnixPassword,
204    UnixPasswordImport,
205    UserAuthTokenSession,
206    UserId,
207    UserPassword,
208    Uuid,
209    Version,
210    WebauthnAttestationCaList,
211    AllowPrimaryCredFallback,
212
213    #[cfg(any(debug_assertions, test, feature = "test"))]
214    NonExist,
215    #[cfg(any(debug_assertions, test, feature = "test"))]
216    TestAttr,
217    #[cfg(test)]
218    TestAttrA,
219    #[cfg(test)]
220    TestAttrB,
221    #[cfg(test)]
222    TestAttrC,
223    #[cfg(test)]
224    TestAttrD,
225    #[cfg(any(debug_assertions, test, feature = "test"))]
226    TestNumber,
227    #[cfg(any(debug_assertions, test, feature = "test"))]
228    Extra,
229    #[cfg(any(debug_assertions, test, feature = "test"))]
230    TestNotAllowed,
231
232    #[cfg(not(test))]
233    #[schema(value_type = String)]
234    Custom(AttrString),
235}
236
237impl AsRef<str> for Attribute {
238    fn as_ref(&self) -> &str {
239        self.as_str()
240    }
241}
242
243impl AsRef<Attribute> for Attribute {
244    fn as_ref(&self) -> &Attribute {
245        self
246    }
247}
248
249impl TryFrom<&AttrString> for Attribute {
250    type Error = OperationError;
251
252    fn try_from(value: &AttrString) -> Result<Self, Self::Error> {
253        Ok(Attribute::inner_from_str(value.as_str()))
254    }
255}
256
257impl From<&str> for Attribute {
258    fn from(value: &str) -> Self {
259        Self::inner_from_str(value)
260    }
261}
262
263impl From<String> for Attribute {
264    fn from(value: String) -> Self {
265        Self::inner_from_str(value.as_str())
266    }
267}
268
269impl<'a> From<&'a Attribute> for &'a str {
270    fn from(val: &'a Attribute) -> Self {
271        val.as_str()
272    }
273}
274
275impl From<Attribute> for AttrString {
276    fn from(val: Attribute) -> Self {
277        AttrString::from(val.as_str())
278    }
279}
280
281impl FromStr for Attribute {
282    type Err = Infallible;
283
284    fn from_str(value: &str) -> Result<Self, Self::Err> {
285        Ok(Self::inner_from_str(value))
286    }
287}
288
289impl Attribute {
290    pub fn as_str(&self) -> &str {
291        match self {
292            Attribute::Account => ATTR_ACCOUNT,
293            Attribute::AccountExpire => ATTR_ACCOUNT_EXPIRE,
294            Attribute::AccountValidFrom => ATTR_ACCOUNT_VALID_FROM,
295            Attribute::AccountSoftlockExpire => ATTR_ACCOUNT_SOFTLOCK_EXPIRE,
296            Attribute::AcpCreateAttr => ATTR_ACP_CREATE_ATTR,
297            Attribute::AcpCreateClass => ATTR_ACP_CREATE_CLASS,
298            Attribute::AcpEnable => ATTR_ACP_ENABLE,
299            Attribute::AcpModifyClass => ATTR_ACP_MODIFY_CLASS,
300            Attribute::AcpModifyPresentClass => ATTR_ACP_MODIFY_PRESENT_CLASS,
301            Attribute::AcpModifyRemoveClass => ATTR_ACP_MODIFY_REMOVE_CLASS,
302            Attribute::AcpModifyPresentAttr => ATTR_ACP_MODIFY_PRESENTATTR,
303            Attribute::AcpModifyRemovedAttr => ATTR_ACP_MODIFY_REMOVEDATTR,
304            Attribute::AcpReceiver => ATTR_ACP_RECEIVER,
305            Attribute::AcpReceiverGroup => ATTR_ACP_RECEIVER_GROUP,
306            Attribute::AcpSearchAttr => ATTR_ACP_SEARCH_ATTR,
307            Attribute::AcpTargetScope => ATTR_ACP_TARGET_SCOPE,
308            Attribute::AllowPrimaryCredFallback => ATTR_ALLOW_PRIMARY_CRED_FALLBACK,
309            Attribute::ApiTokenSession => ATTR_API_TOKEN_SESSION,
310            Attribute::ApplicationPassword => ATTR_APPLICATION_PASSWORD,
311            Attribute::ApplicationUrl => ATTR_APPLICATION_URL,
312            Attribute::AttestedPasskeys => ATTR_ATTESTED_PASSKEYS,
313            Attribute::Attr => ATTR_ATTR,
314            Attribute::AttributeName => ATTR_ATTRIBUTENAME,
315            Attribute::AttributeType => ATTR_ATTRIBUTETYPE,
316            Attribute::AuthSessionExpiry => ATTR_AUTH_SESSION_EXPIRY,
317            Attribute::AuthPasswordMinimumLength => ATTR_AUTH_PASSWORD_MINIMUM_LENGTH,
318            Attribute::BadlistPassword => ATTR_BADLIST_PASSWORD,
319            Attribute::Certificate => ATTR_CERTIFICATE,
320            Attribute::CascadeDeleted => ATTR_CASCADE_DELETED,
321            Attribute::Claim => ATTR_CLAIM,
322            Attribute::Class => ATTR_CLASS,
323            Attribute::ClassName => ATTR_CLASSNAME,
324            Attribute::Cn => ATTR_CN,
325            Attribute::CookiePrivateKey => ATTR_COOKIE_PRIVATE_KEY,
326            Attribute::CreatedAtCid => ATTR_CREATED_AT_CID,
327            Attribute::CredentialUpdateIntentToken => ATTR_CREDENTIAL_UPDATE_INTENT_TOKEN,
328            Attribute::CredentialTypeMinimum => ATTR_CREDENTIAL_TYPE_MINIMUM,
329            Attribute::DeniedName => ATTR_DENIED_NAME,
330            Attribute::DeleteAfter => ATTR_DELETE_AFTER,
331            Attribute::Description => ATTR_DESCRIPTION,
332            Attribute::DirectMemberOf => ATTR_DIRECTMEMBEROF,
333            Attribute::DisplayName => ATTR_DISPLAYNAME,
334            Attribute::Dn => ATTR_DN,
335            Attribute::Domain => ATTR_DOMAIN,
336            Attribute::DomainAllowEasterEggs => ATTR_DOMAIN_ALLOW_EASTER_EGGS,
337            Attribute::DomainAllowAccountRecovery => ATTR_DOMAIN_ALLOW_ACCOUNT_RECOVERY,
338            Attribute::DomainDevelopmentTaint => ATTR_DOMAIN_DEVELOPMENT_TAINT,
339            Attribute::DomainDisplayName => ATTR_DOMAIN_DISPLAY_NAME,
340            Attribute::DomainLdapBasedn => ATTR_DOMAIN_LDAP_BASEDN,
341            Attribute::DomainName => ATTR_DOMAIN_NAME,
342            Attribute::DomainSsid => ATTR_DOMAIN_SSID,
343            Attribute::DomainTokenKey => ATTR_DOMAIN_TOKEN_KEY,
344            Attribute::DomainUuid => ATTR_DOMAIN_UUID,
345            Attribute::DynGroup => ATTR_DYNGROUP,
346            Attribute::DynGroupFilter => ATTR_DYNGROUP_FILTER,
347            Attribute::DynMember => ATTR_DYNMEMBER,
348            Attribute::Enabled => ATTR_ENABLED,
349            Attribute::Email => ATTR_EMAIL,
350            Attribute::EmailAlternative => ATTR_EMAIL_ALTERNATIVE,
351            Attribute::EmailPrimary => ATTR_EMAIL_PRIMARY,
352            Attribute::EntryDn => ATTR_ENTRYDN,
353            Attribute::EntryManagedBy => ATTR_ENTRY_MANAGED_BY,
354            Attribute::EntryUuid => ATTR_ENTRYUUID,
355            Attribute::Es256PrivateKeyDer => ATTR_ES256_PRIVATE_KEY_DER,
356            Attribute::Excludes => ATTR_EXCLUDES,
357            Attribute::FernetPrivateKeyStr => ATTR_FERNET_PRIVATE_KEY_STR,
358            Attribute::Gecos => ATTR_GECOS,
359            Attribute::GidNumber => ATTR_GIDNUMBER,
360            Attribute::GrantUiHint => ATTR_GRANT_UI_HINT,
361            Attribute::Group => ATTR_GROUP,
362            Attribute::HmacNameHistory => ATTR_HMAC_NAME_HISTORY,
363            Attribute::HomeDirectory => ATTR_HOME_DIRECTORY,
364            Attribute::IdVerificationEcKey => ATTR_ID_VERIFICATION_ECKEY,
365            Attribute::Image => ATTR_IMAGE,
366            Attribute::Index => ATTR_INDEX,
367            Attribute::Indexed => ATTR_INDEXED,
368            Attribute::InMemoriam => ATTR_IN_MEMORIAM,
369            Attribute::IpaNtHash => ATTR_IPANTHASH,
370            Attribute::IpaSshPubKey => ATTR_IPASSHPUBKEY,
371            Attribute::JwsEs256PrivateKey => ATTR_JWS_ES256_PRIVATE_KEY,
372            Attribute::KeyActionRotate => ATTR_KEY_ACTION_ROTATE,
373            Attribute::KeyActionRevoke => ATTR_KEY_ACTION_REVOKE,
374            Attribute::KeyActionImportJwsEs256 => ATTR_KEY_ACTION_IMPORT_JWS_ES256,
375            Attribute::KeyActionImportJwsRs256 => ATTR_KEY_ACTION_IMPORT_JWS_RS256,
376            Attribute::KeyInternalData => ATTR_KEY_INTERNAL_DATA,
377            Attribute::KeyProvider => ATTR_KEY_PROVIDER,
378            Attribute::LastModifiedCid => ATTR_LAST_MODIFIED_CID,
379            Attribute::LdapAllowUnixPwBind => ATTR_LDAP_ALLOW_UNIX_PW_BIND,
380            Attribute::LdapEmailAddress => ATTR_LDAP_EMAIL_ADDRESS,
381            Attribute::LdapKeys => ATTR_LDAP_KEYS,
382            Attribute::LdapMaxQueryableAttrs => ATTR_LDAP_MAX_QUERYABLE_ATTRS,
383            Attribute::LdapSshPublicKey => ATTR_LDAP_SSHPUBLICKEY,
384            Attribute::LegalName => ATTR_LEGALNAME,
385            Attribute::LimitSearchMaxResults => ATTR_LIMIT_SEARCH_MAX_RESULTS,
386            Attribute::LimitSearchMaxFilterTest => ATTR_LIMIT_SEARCH_MAX_FILTER_TEST,
387            Attribute::LinkedGroup => ATTR_LINKEDGROUP,
388            Attribute::LoginShell => ATTR_LOGINSHELL,
389            Attribute::Mail => ATTR_MAIL,
390            Attribute::MailDestination => ATTR_MAIL_DESTINATION,
391            Attribute::May => ATTR_MAY,
392            Attribute::Member => ATTR_MEMBER,
393            Attribute::MemberCreateOnce => ATTR_MEMBER_CREATE_ONCE,
394            Attribute::MemberOf => ATTR_MEMBEROF,
395            Attribute::MessageTemplate => ATTR_MESSAGE_TEMPLATE,
396            Attribute::MultiValue => ATTR_MULTIVALUE,
397            Attribute::Must => ATTR_MUST,
398            Attribute::Name => ATTR_NAME,
399            Attribute::NameHistory => ATTR_NAME_HISTORY,
400            Attribute::NoIndex => ATTR_NO_INDEX,
401            Attribute::NsUniqueId => ATTR_NSUNIQUEID,
402            Attribute::NsAccountLock => ATTR_NSACCOUNTLOCK,
403            Attribute::OAuth2AllowInsecureClientDisablePkce => {
404                ATTR_OAUTH2_ALLOW_INSECURE_CLIENT_DISABLE_PKCE
405            }
406            Attribute::OAuth2AllowLocalhostRedirect => ATTR_OAUTH2_ALLOW_LOCALHOST_REDIRECT,
407            Attribute::OAuth2AuthorisationEndpoint => ATTR_OAUTH2_AUTHORISATION_ENDPOINT,
408            Attribute::OAuth2ClientId => ATTR_OAUTH2_CLIENT_ID,
409            Attribute::OAuth2ClientSecret => ATTR_OAUTH2_CLIENT_SECRET,
410            Attribute::OAuth2ConsentScopeMap => ATTR_OAUTH2_CONSENT_SCOPE_MAP,
411            Attribute::OAuth2DeviceFlowEnable => ATTR_OAUTH2_DEVICE_FLOW_ENABLE,
412            Attribute::OAuth2JwtLegacyCryptoEnable => ATTR_OAUTH2_JWT_LEGACY_CRYPTO_ENABLE,
413            Attribute::OAuth2PreferShortUsername => ATTR_OAUTH2_PREFER_SHORT_USERNAME,
414            Attribute::OAuth2RefreshTokenExpiry => ATTR_OAUTH2_REFRESH_TOKEN_EXPIRY,
415            Attribute::OAuth2RequestScopes => ATTR_OAUTH2_REQUEST_SCOPES,
416            Attribute::OAuth2RsBasicSecret => ATTR_OAUTH2_RS_BASIC_SECRET,
417            Attribute::OAuth2RsClaimMap => ATTR_OAUTH2_RS_CLAIM_MAP,
418            Attribute::OAuth2RsImplicitScopes => ATTR_OAUTH2_RS_IMPLICIT_SCOPES,
419            Attribute::OAuth2RsName => ATTR_OAUTH2_RS_NAME,
420            Attribute::OAuth2RsOrigin => ATTR_OAUTH2_RS_ORIGIN,
421            Attribute::OAuth2RsOriginLanding => ATTR_OAUTH2_RS_ORIGIN_LANDING,
422            Attribute::OAuth2RsScopeMap => ATTR_OAUTH2_RS_SCOPE_MAP,
423            Attribute::OAuth2RsSupScopeMap => ATTR_OAUTH2_RS_SUP_SCOPE_MAP,
424            Attribute::OAuth2RsTokenKey => ATTR_OAUTH2_RS_TOKEN_KEY,
425            Attribute::OAuth2Session => ATTR_OAUTH2_SESSION,
426            Attribute::OAuth2StrictRedirectUri => ATTR_OAUTH2_STRICT_REDIRECT_URI,
427            Attribute::OAuth2TokenEndpoint => ATTR_OAUTH2_TOKEN_ENDPOINT,
428            Attribute::OAuth2TokenIntrospectEndpoint => ATTR_OAUTH2_TOKEN_INTROSPECT_ENDPOINT,
429            Attribute::OAuth2AccountCredentialUuid => ATTR_OAUTH2_ACCOUNT_CREDENTIAL_UUID,
430            Attribute::OAuth2AccountProvider => ATTR_OAUTH2_ACCOUNT_PROVIDER,
431            Attribute::OAuth2AccountUniqueUserId => ATTR_OAUTH2_ACCOUNT_UNIQUE_USER_ID,
432            Attribute::OAuth2AccountUniqueUserSub => ATTR_OAUTH2_ACCOUNT_UNIQUE_USER_SUB,
433            Attribute::OAuth2ConsentPromptEnable => ATTR_OAUTH2_CONSENT_PROMPT_ENABLE,
434            Attribute::ObjectClass => ATTR_OBJECTCLASS,
435            Attribute::OtherNoIndex => ATTR_OTHER_NO_INDEX,
436            Attribute::PassKeys => ATTR_PASSKEYS,
437            Attribute::PasswordChangedTime => ATTR_PWD_CHANGED_TIME,
438            Attribute::PasswordImport => ATTR_PASSWORD_IMPORT,
439            Attribute::PatchLevel => ATTR_PATCH_LEVEL,
440            Attribute::Phantom => ATTR_PHANTOM,
441            Attribute::PrimaryCredential => ATTR_PRIMARY_CREDENTIAL,
442            Attribute::PrivateCookieKey => ATTR_PRIVATE_COOKIE_KEY,
443            Attribute::PrivilegeExpiry => ATTR_PRIVILEGE_EXPIRY,
444            Attribute::RadiusSecret => ATTR_RADIUS_SECRET,
445            Attribute::RecycledDirectMemberOf => ATTR_RECYCLEDDIRECTMEMBEROF,
446            Attribute::Refers => ATTR_REFERS,
447            Attribute::Replicated => ATTR_REPLICATED,
448            Attribute::Rs256PrivateKeyDer => ATTR_RS256_PRIVATE_KEY_DER,
449            Attribute::S256 => ATTR_S256,
450            Attribute::Scope => ATTR_SCOPE,
451            Attribute::ScimSchemas => ATTR_SCIM_SCHEMAS,
452            Attribute::SendAfter => ATTR_SEND_AFTER,
453            Attribute::SentAt => ATTR_SENT_AT,
454            Attribute::SourceUuid => ATTR_SOURCE_UUID,
455            Attribute::Spn => ATTR_SPN,
456            Attribute::SshPublicKey => ATTR_SSH_PUBLICKEY,
457            Attribute::SudoHost => ATTR_SUDOHOST,
458            Attribute::Supplements => ATTR_SUPPLEMENTS,
459            Attribute::SyncAllowed => ATTR_SYNC_ALLOWED,
460            Attribute::SyncClass => ATTR_SYNC_CLASS,
461            Attribute::SyncCookie => ATTR_SYNC_COOKIE,
462            Attribute::SyncCredentialPortal => ATTR_SYNC_CREDENTIAL_PORTAL,
463            Attribute::SyncExternalId => ATTR_SYNC_EXTERNAL_ID,
464            Attribute::SyncParentUuid => ATTR_SYNC_PARENT_UUID,
465            Attribute::SyncTokenSession => ATTR_SYNC_TOKEN_SESSION,
466            Attribute::SyncYieldAuthority => ATTR_SYNC_YIELD_AUTHORITY,
467            Attribute::Syntax => ATTR_SYNTAX,
468            Attribute::SystemExcludes => ATTR_SYSTEMEXCLUDES,
469            Attribute::SystemMay => ATTR_SYSTEMMAY,
470            Attribute::SystemMust => ATTR_SYSTEMMUST,
471            Attribute::SystemSupplements => ATTR_SYSTEMSUPPLEMENTS,
472            Attribute::Term => ATTR_TERM,
473            Attribute::TotpImport => ATTR_TOTP_IMPORT,
474            Attribute::Uid => ATTR_UID,
475            Attribute::UidNumber => ATTR_UIDNUMBER,
476            Attribute::Unique => ATTR_UNIQUE,
477            Attribute::UnixPassword => ATTR_UNIX_PASSWORD,
478            Attribute::UnixPasswordImport => ATTR_UNIX_PASSWORD_IMPORT,
479            Attribute::UserAuthTokenSession => ATTR_USER_AUTH_TOKEN_SESSION,
480            Attribute::UserId => ATTR_USERID,
481            Attribute::UserPassword => ATTR_USERPASSWORD,
482            Attribute::Uuid => ATTR_UUID,
483            Attribute::Version => ATTR_VERSION,
484            Attribute::WebauthnAttestationCaList => ATTR_WEBAUTHN_ATTESTATION_CA_LIST,
485
486            #[cfg(any(debug_assertions, test, feature = "test"))]
487            Attribute::NonExist => TEST_ATTR_NON_EXIST,
488            #[cfg(any(debug_assertions, test, feature = "test"))]
489            Attribute::TestAttr => TEST_ATTR_TEST_ATTR,
490
491            #[cfg(test)]
492            Attribute::TestAttrA => TEST_ATTR_TEST_ATTR_A,
493            #[cfg(test)]
494            Attribute::TestAttrB => TEST_ATTR_TEST_ATTR_B,
495            #[cfg(test)]
496            Attribute::TestAttrC => TEST_ATTR_TEST_ATTR_C,
497            #[cfg(test)]
498            Attribute::TestAttrD => TEST_ATTR_TEST_ATTR_D,
499
500            #[cfg(any(debug_assertions, test, feature = "test"))]
501            Attribute::Extra => TEST_ATTR_EXTRA,
502            #[cfg(any(debug_assertions, test, feature = "test"))]
503            Attribute::TestNumber => TEST_ATTR_NUMBER,
504            #[cfg(any(debug_assertions, test, feature = "test"))]
505            Attribute::TestNotAllowed => TEST_ATTR_NOTALLOWED,
506
507            #[cfg(not(test))]
508            Attribute::Custom(value) => value.as_str(),
509        }
510    }
511
512    // We allow this because the standard lib from_str is fallible, and we want an infallible version.
513    #[allow(clippy::should_implement_trait)]
514    fn inner_from_str(value: &str) -> Self {
515        // Could this be something like heapless to save allocations? Also gives a way
516        // to limit length of str?
517        match value.to_lowercase().as_str() {
518            ATTR_ACCOUNT => Attribute::Account,
519            ATTR_ACCOUNT_EXPIRE => Attribute::AccountExpire,
520            ATTR_ACCOUNT_VALID_FROM => Attribute::AccountValidFrom,
521            ATTR_ACCOUNT_SOFTLOCK_EXPIRE => Attribute::AccountSoftlockExpire,
522            ATTR_ACP_CREATE_ATTR => Attribute::AcpCreateAttr,
523            ATTR_ACP_CREATE_CLASS => Attribute::AcpCreateClass,
524            ATTR_ACP_ENABLE => Attribute::AcpEnable,
525            ATTR_ACP_MODIFY_CLASS => Attribute::AcpModifyClass,
526            ATTR_ACP_MODIFY_PRESENT_CLASS => Attribute::AcpModifyPresentClass,
527            ATTR_ACP_MODIFY_REMOVE_CLASS => Attribute::AcpModifyRemoveClass,
528            ATTR_ACP_MODIFY_PRESENTATTR => Attribute::AcpModifyPresentAttr,
529            ATTR_ACP_MODIFY_REMOVEDATTR => Attribute::AcpModifyRemovedAttr,
530            ATTR_ACP_RECEIVER => Attribute::AcpReceiver,
531            ATTR_ACP_RECEIVER_GROUP => Attribute::AcpReceiverGroup,
532            ATTR_ACP_SEARCH_ATTR => Attribute::AcpSearchAttr,
533            ATTR_ACP_TARGET_SCOPE => Attribute::AcpTargetScope,
534            ATTR_ALLOW_PRIMARY_CRED_FALLBACK => Attribute::AllowPrimaryCredFallback,
535            ATTR_API_TOKEN_SESSION => Attribute::ApiTokenSession,
536            ATTR_APPLICATION_PASSWORD => Attribute::ApplicationPassword,
537            ATTR_APPLICATION_URL => Attribute::ApplicationUrl,
538            ATTR_ATTESTED_PASSKEYS => Attribute::AttestedPasskeys,
539            ATTR_ATTR => Attribute::Attr,
540            ATTR_ATTRIBUTENAME => Attribute::AttributeName,
541            ATTR_ATTRIBUTETYPE => Attribute::AttributeType,
542            ATTR_AUTH_SESSION_EXPIRY => Attribute::AuthSessionExpiry,
543            ATTR_AUTH_PASSWORD_MINIMUM_LENGTH => Attribute::AuthPasswordMinimumLength,
544            ATTR_BADLIST_PASSWORD => Attribute::BadlistPassword,
545            ATTR_CERTIFICATE => Attribute::Certificate,
546            ATTR_CASCADE_DELETED => Attribute::CascadeDeleted,
547            ATTR_CLAIM => Attribute::Claim,
548            ATTR_CLASS => Attribute::Class,
549            ATTR_CLASSNAME => Attribute::ClassName,
550            ATTR_CN => Attribute::Cn,
551            ATTR_COOKIE_PRIVATE_KEY => Attribute::CookiePrivateKey,
552            ATTR_CREATED_AT_CID => Attribute::CreatedAtCid,
553            ATTR_CREDENTIAL_UPDATE_INTENT_TOKEN => Attribute::CredentialUpdateIntentToken,
554            ATTR_CREDENTIAL_TYPE_MINIMUM => Attribute::CredentialTypeMinimum,
555            ATTR_DENIED_NAME => Attribute::DeniedName,
556            ATTR_DELETE_AFTER => Attribute::DeleteAfter,
557            ATTR_DESCRIPTION => Attribute::Description,
558            ATTR_DIRECTMEMBEROF => Attribute::DirectMemberOf,
559            ATTR_DISPLAYNAME => Attribute::DisplayName,
560            ATTR_DN => Attribute::Dn,
561            ATTR_DOMAIN => Attribute::Domain,
562            ATTR_DOMAIN_ALLOW_EASTER_EGGS => Attribute::DomainAllowEasterEggs,
563            ATTR_DOMAIN_ALLOW_ACCOUNT_RECOVERY => Attribute::DomainAllowAccountRecovery,
564            ATTR_DOMAIN_DISPLAY_NAME => Attribute::DomainDisplayName,
565            ATTR_DOMAIN_DEVELOPMENT_TAINT => Attribute::DomainDevelopmentTaint,
566            ATTR_DOMAIN_LDAP_BASEDN => Attribute::DomainLdapBasedn,
567            ATTR_DOMAIN_NAME => Attribute::DomainName,
568            ATTR_DOMAIN_SSID => Attribute::DomainSsid,
569            ATTR_DOMAIN_TOKEN_KEY => Attribute::DomainTokenKey,
570            ATTR_DOMAIN_UUID => Attribute::DomainUuid,
571            ATTR_DYNGROUP => Attribute::DynGroup,
572            ATTR_DYNGROUP_FILTER => Attribute::DynGroupFilter,
573            ATTR_DYNMEMBER => Attribute::DynMember,
574            ATTR_ENABLED => Attribute::Enabled,
575            ATTR_EMAIL => Attribute::Email,
576            ATTR_EMAIL_ALTERNATIVE => Attribute::EmailAlternative,
577            ATTR_EMAIL_PRIMARY => Attribute::EmailPrimary,
578            ATTR_ENTRYDN => Attribute::EntryDn,
579            ATTR_ENTRY_MANAGED_BY => Attribute::EntryManagedBy,
580            ATTR_ENTRYUUID => Attribute::EntryUuid,
581            ATTR_ES256_PRIVATE_KEY_DER => Attribute::Es256PrivateKeyDer,
582            ATTR_EXCLUDES => Attribute::Excludes,
583            ATTR_FERNET_PRIVATE_KEY_STR => Attribute::FernetPrivateKeyStr,
584            ATTR_GECOS => Attribute::Gecos,
585            ATTR_GIDNUMBER => Attribute::GidNumber,
586            ATTR_GRANT_UI_HINT => Attribute::GrantUiHint,
587            ATTR_GROUP => Attribute::Group,
588            ATTR_HMAC_NAME_HISTORY => Attribute::HmacNameHistory,
589            ATTR_HOME_DIRECTORY => Attribute::HomeDirectory,
590            ATTR_ID_VERIFICATION_ECKEY => Attribute::IdVerificationEcKey,
591            ATTR_IMAGE => Attribute::Image,
592            ATTR_INDEX => Attribute::Index,
593            ATTR_INDEXED => Attribute::Indexed,
594            ATTR_IN_MEMORIAM => Attribute::InMemoriam,
595            ATTR_IPANTHASH => Attribute::IpaNtHash,
596            ATTR_IPASSHPUBKEY => Attribute::IpaSshPubKey,
597            ATTR_JWS_ES256_PRIVATE_KEY => Attribute::JwsEs256PrivateKey,
598            ATTR_KEY_ACTION_ROTATE => Attribute::KeyActionRotate,
599            ATTR_KEY_ACTION_REVOKE => Attribute::KeyActionRevoke,
600            ATTR_KEY_ACTION_IMPORT_JWS_ES256 => Attribute::KeyActionImportJwsEs256,
601            ATTR_KEY_ACTION_IMPORT_JWS_RS256 => Attribute::KeyActionImportJwsRs256,
602            ATTR_KEY_INTERNAL_DATA => Attribute::KeyInternalData,
603            ATTR_KEY_PROVIDER => Attribute::KeyProvider,
604            ATTR_LAST_MODIFIED_CID => Attribute::LastModifiedCid,
605            ATTR_LDAP_ALLOW_UNIX_PW_BIND => Attribute::LdapAllowUnixPwBind,
606            ATTR_LDAP_EMAIL_ADDRESS => Attribute::LdapEmailAddress,
607            ATTR_LDAP_KEYS => Attribute::LdapKeys,
608            ATTR_LDAP_MAX_QUERYABLE_ATTRS => Attribute::LdapMaxQueryableAttrs,
609            ATTR_SSH_PUBLICKEY => Attribute::SshPublicKey,
610            ATTR_LEGALNAME => Attribute::LegalName,
611            ATTR_LINKEDGROUP => Attribute::LinkedGroup,
612            ATTR_LOGINSHELL => Attribute::LoginShell,
613            ATTR_LIMIT_SEARCH_MAX_RESULTS => Attribute::LimitSearchMaxResults,
614            ATTR_LIMIT_SEARCH_MAX_FILTER_TEST => Attribute::LimitSearchMaxFilterTest,
615            ATTR_MAIL => Attribute::Mail,
616            ATTR_MAIL_DESTINATION => Attribute::MailDestination,
617            ATTR_MAY => Attribute::May,
618            ATTR_MEMBER => Attribute::Member,
619            ATTR_MEMBER_CREATE_ONCE => Attribute::MemberCreateOnce,
620            ATTR_MEMBEROF => Attribute::MemberOf,
621            ATTR_MESSAGE_TEMPLATE => Attribute::MessageTemplate,
622            ATTR_MULTIVALUE => Attribute::MultiValue,
623            ATTR_MUST => Attribute::Must,
624            ATTR_NAME => Attribute::Name,
625            ATTR_NAME_HISTORY => Attribute::NameHistory,
626            ATTR_NO_INDEX => Attribute::NoIndex,
627            ATTR_NSUNIQUEID => Attribute::NsUniqueId,
628            ATTR_NSACCOUNTLOCK => Attribute::NsAccountLock,
629            ATTR_OAUTH2_ALLOW_INSECURE_CLIENT_DISABLE_PKCE => {
630                Attribute::OAuth2AllowInsecureClientDisablePkce
631            }
632            ATTR_OAUTH2_ALLOW_LOCALHOST_REDIRECT => Attribute::OAuth2AllowLocalhostRedirect,
633            ATTR_OAUTH2_AUTHORISATION_ENDPOINT => Attribute::OAuth2AuthorisationEndpoint,
634            ATTR_OAUTH2_CLIENT_ID => Attribute::OAuth2ClientId,
635            ATTR_OAUTH2_CLIENT_SECRET => Attribute::OAuth2ClientSecret,
636            ATTR_OAUTH2_CONSENT_SCOPE_MAP => Attribute::OAuth2ConsentScopeMap,
637            ATTR_OAUTH2_DEVICE_FLOW_ENABLE => Attribute::OAuth2DeviceFlowEnable,
638            ATTR_OAUTH2_JWT_LEGACY_CRYPTO_ENABLE => Attribute::OAuth2JwtLegacyCryptoEnable,
639            ATTR_OAUTH2_PREFER_SHORT_USERNAME => Attribute::OAuth2PreferShortUsername,
640            ATTR_OAUTH2_REFRESH_TOKEN_EXPIRY => Attribute::OAuth2RefreshTokenExpiry,
641            ATTR_OAUTH2_REQUEST_SCOPES => Attribute::OAuth2RequestScopes,
642            ATTR_OAUTH2_RS_BASIC_SECRET => Attribute::OAuth2RsBasicSecret,
643            ATTR_OAUTH2_RS_CLAIM_MAP => Attribute::OAuth2RsClaimMap,
644            ATTR_OAUTH2_RS_IMPLICIT_SCOPES => Attribute::OAuth2RsImplicitScopes,
645            ATTR_OAUTH2_RS_NAME => Attribute::OAuth2RsName,
646            ATTR_OAUTH2_RS_ORIGIN => Attribute::OAuth2RsOrigin,
647            ATTR_OAUTH2_RS_ORIGIN_LANDING => Attribute::OAuth2RsOriginLanding,
648            ATTR_OAUTH2_RS_SCOPE_MAP => Attribute::OAuth2RsScopeMap,
649            ATTR_OAUTH2_RS_SUP_SCOPE_MAP => Attribute::OAuth2RsSupScopeMap,
650            ATTR_OAUTH2_RS_TOKEN_KEY => Attribute::OAuth2RsTokenKey,
651            ATTR_OAUTH2_SESSION => Attribute::OAuth2Session,
652            ATTR_OAUTH2_STRICT_REDIRECT_URI => Attribute::OAuth2StrictRedirectUri,
653            ATTR_OAUTH2_TOKEN_ENDPOINT => Attribute::OAuth2TokenEndpoint,
654            ATTR_OAUTH2_TOKEN_INTROSPECT_ENDPOINT => Attribute::OAuth2TokenIntrospectEndpoint,
655            ATTR_OAUTH2_ACCOUNT_CREDENTIAL_UUID => Attribute::OAuth2AccountCredentialUuid,
656            ATTR_OAUTH2_ACCOUNT_PROVIDER => Attribute::OAuth2AccountProvider,
657            ATTR_OAUTH2_ACCOUNT_UNIQUE_USER_ID => Attribute::OAuth2AccountUniqueUserId,
658            ATTR_OAUTH2_ACCOUNT_UNIQUE_USER_SUB => Attribute::OAuth2AccountUniqueUserSub,
659            ATTR_OAUTH2_CONSENT_PROMPT_ENABLE => Attribute::OAuth2ConsentPromptEnable,
660            ATTR_OBJECTCLASS => Attribute::ObjectClass,
661            ATTR_OTHER_NO_INDEX => Attribute::OtherNoIndex,
662            ATTR_PASSKEYS => Attribute::PassKeys,
663            ATTR_PASSWORD_IMPORT => Attribute::PasswordImport,
664            ATTR_PATCH_LEVEL => Attribute::PatchLevel,
665            ATTR_PHANTOM => Attribute::Phantom,
666            ATTR_PRIMARY_CREDENTIAL => Attribute::PrimaryCredential,
667            ATTR_PRIVATE_COOKIE_KEY => Attribute::PrivateCookieKey,
668            ATTR_PRIVILEGE_EXPIRY => Attribute::PrivilegeExpiry,
669            ATTR_PWD_CHANGED_TIME => Attribute::PasswordChangedTime,
670            ATTR_RADIUS_SECRET => Attribute::RadiusSecret,
671            ATTR_RECYCLEDDIRECTMEMBEROF => Attribute::RecycledDirectMemberOf,
672            ATTR_REFERS => Attribute::Refers,
673            ATTR_REPLICATED => Attribute::Replicated,
674            ATTR_RS256_PRIVATE_KEY_DER => Attribute::Rs256PrivateKeyDer,
675            ATTR_S256 => Attribute::S256,
676            ATTR_SCIM_SCHEMAS => Attribute::ScimSchemas,
677            ATTR_SEND_AFTER => Attribute::SendAfter,
678            ATTR_SENT_AT => Attribute::SentAt,
679            ATTR_SCOPE => Attribute::Scope,
680            ATTR_SOURCE_UUID => Attribute::SourceUuid,
681            ATTR_SPN => Attribute::Spn,
682            ATTR_LDAP_SSHPUBLICKEY => Attribute::LdapSshPublicKey,
683            ATTR_SUDOHOST => Attribute::SudoHost,
684            ATTR_SUPPLEMENTS => Attribute::Supplements,
685            ATTR_SYNC_ALLOWED => Attribute::SyncAllowed,
686            ATTR_SYNC_CLASS => Attribute::SyncClass,
687            ATTR_SYNC_COOKIE => Attribute::SyncCookie,
688            ATTR_SYNC_CREDENTIAL_PORTAL => Attribute::SyncCredentialPortal,
689            ATTR_SYNC_EXTERNAL_ID => Attribute::SyncExternalId,
690            ATTR_SYNC_PARENT_UUID => Attribute::SyncParentUuid,
691            ATTR_SYNC_TOKEN_SESSION => Attribute::SyncTokenSession,
692            ATTR_SYNC_YIELD_AUTHORITY => Attribute::SyncYieldAuthority,
693            ATTR_SYNTAX => Attribute::Syntax,
694            ATTR_SYSTEMEXCLUDES => Attribute::SystemExcludes,
695            ATTR_SYSTEMMAY => Attribute::SystemMay,
696            ATTR_SYSTEMMUST => Attribute::SystemMust,
697            ATTR_SYSTEMSUPPLEMENTS => Attribute::SystemSupplements,
698            ATTR_TERM => Attribute::Term,
699            ATTR_TOTP_IMPORT => Attribute::TotpImport,
700            ATTR_UID => Attribute::Uid,
701            ATTR_UIDNUMBER => Attribute::UidNumber,
702            ATTR_UNIQUE => Attribute::Unique,
703            ATTR_UNIX_PASSWORD => Attribute::UnixPassword,
704            ATTR_UNIX_PASSWORD_IMPORT => Attribute::UnixPasswordImport,
705            ATTR_USER_AUTH_TOKEN_SESSION => Attribute::UserAuthTokenSession,
706            ATTR_USERID => Attribute::UserId,
707            ATTR_USERPASSWORD => Attribute::UserPassword,
708            ATTR_UUID => Attribute::Uuid,
709            ATTR_VERSION => Attribute::Version,
710            ATTR_WEBAUTHN_ATTESTATION_CA_LIST => Attribute::WebauthnAttestationCaList,
711
712            #[cfg(any(debug_assertions, test, feature = "test"))]
713            TEST_ATTR_NON_EXIST => Attribute::NonExist,
714            #[cfg(any(debug_assertions, test, feature = "test"))]
715            TEST_ATTR_TEST_ATTR => Attribute::TestAttr,
716
717            #[cfg(test)]
718            TEST_ATTR_TEST_ATTR_A => Attribute::TestAttrA,
719            #[cfg(test)]
720            TEST_ATTR_TEST_ATTR_B => Attribute::TestAttrB,
721            #[cfg(test)]
722            TEST_ATTR_TEST_ATTR_C => Attribute::TestAttrC,
723            #[cfg(test)]
724            TEST_ATTR_TEST_ATTR_D => Attribute::TestAttrD,
725
726            #[cfg(any(debug_assertions, test, feature = "test"))]
727            TEST_ATTR_EXTRA => Attribute::Extra,
728            #[cfg(any(debug_assertions, test, feature = "test"))]
729            TEST_ATTR_NUMBER => Attribute::TestNumber,
730            #[cfg(any(debug_assertions, test, feature = "test"))]
731            TEST_ATTR_NOTALLOWED => Attribute::TestNotAllowed,
732
733            #[cfg(not(test))]
734            _ => Attribute::Custom(AttrString::from(value)),
735            // Allowed only in tests
736            #[allow(clippy::unreachable)]
737            #[cfg(test)]
738            _ => {
739                unreachable!(
740                    "Check that you've implemented the Attribute conversion for {:?}",
741                    value
742                );
743            }
744        }
745    }
746}
747
748impl fmt::Display for Attribute {
749    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
750        write!(f, "{}", self.as_str())
751    }
752}
753
754impl From<Attribute> for String {
755    fn from(attr: Attribute) -> String {
756        attr.to_string()
757    }
758}
759
760/// Sub attributes are a component of SCIM, allowing tagged sub properties of a complex
761/// attribute to be accessed.
762#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, ToSchema)]
763#[serde(rename_all = "lowercase", try_from = "&str", into = "AttrString")]
764pub enum SubAttribute {
765    /// Denotes a primary value.
766    Primary,
767    /// The type of value
768    Type,
769    /// The data associated to a value
770    Value,
771
772    #[cfg(not(test))]
773    #[schema(value_type = String)]
774    Custom(AttrString),
775}
776
777impl fmt::Display for SubAttribute {
778    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
779        write!(f, "{}", self.as_str())
780    }
781}
782
783impl From<SubAttribute> for AttrString {
784    fn from(val: SubAttribute) -> Self {
785        AttrString::from(val.as_str())
786    }
787}
788
789impl From<&str> for SubAttribute {
790    fn from(value: &str) -> Self {
791        Self::inner_from_str(value)
792    }
793}
794
795impl FromStr for SubAttribute {
796    type Err = Infallible;
797
798    fn from_str(value: &str) -> Result<Self, Self::Err> {
799        Ok(Self::inner_from_str(value))
800    }
801}
802
803impl SubAttribute {
804    pub fn as_str(&self) -> &str {
805        match self {
806            SubAttribute::Primary => SUB_ATTR_PRIMARY,
807            SubAttribute::Type => SUB_ATTR_TYPE,
808            SubAttribute::Value => SUB_ATTR_VALUE,
809            #[cfg(not(test))]
810            SubAttribute::Custom(s) => s,
811        }
812    }
813
814    // We allow this because the standard lib from_str is fallible, and we want an infallible version.
815    #[allow(clippy::should_implement_trait)]
816    fn inner_from_str(value: &str) -> Self {
817        // Could this be something like heapless to save allocations? Also gives a way
818        // to limit length of str?
819        match value.to_lowercase().as_str() {
820            SUB_ATTR_PRIMARY => SubAttribute::Primary,
821            SUB_ATTR_TYPE => SubAttribute::Type,
822            SUB_ATTR_VALUE => SubAttribute::Value,
823
824            #[cfg(not(test))]
825            _ => SubAttribute::Custom(AttrString::from(value)),
826
827            // Allowed only in tests
828            #[allow(clippy::unreachable)]
829            #[cfg(test)]
830            _ => {
831                unreachable!(
832                    "Check that you've implemented the SubAttribute conversion for {:?}",
833                    value
834                );
835            }
836        }
837    }
838}
839
840#[cfg(test)]
841mod test {
842    use super::Attribute;
843
844    #[test]
845    fn test_valueattribute_from_str() {
846        assert_eq!(Attribute::Uuid, Attribute::from("UUID"));
847        assert_eq!(Attribute::Uuid, Attribute::from("UuiD"));
848        assert_eq!(Attribute::Uuid, Attribute::from("uuid"));
849    }
850
851    #[test]
852    fn test_valueattribute_as_str() {
853        assert_eq!(Attribute::Class.as_str(), "class");
854        assert_eq!(Attribute::Class.to_string(), "class".to_string());
855    }
856
857    #[test]
858    // this ensures we cover both ends of the conversion to/from string-types
859    fn test_valueattribute_round_trip() {
860        use enum_iterator::all;
861        let the_list = all::<Attribute>().collect::<Vec<_>>();
862        for attr in the_list {
863            let attr2 = Attribute::from(attr.as_str());
864            assert!(
865                attr == attr2,
866                "Round-trip failed for {attr} <=> {attr2} check you've implemented a from and to string"
867            );
868        }
869    }
870}