pub struct CachingInternalAuthenticator<A> { /* private fields */ }Expand description
Wraps an InternalAuthenticator with a short-lived cache of both
successful and rejected validations.
Construct it around the concrete validator and hand the wrapper to the
transport layer as the InternalAuthenticator:
use std::time::Duration;
use toolkit_security::{CachingInternalAuthenticator, InternalAuthNError, PlatformIdentity};
struct AlwaysOk;
impl toolkit_security::InternalAuthenticator for AlwaysOk {
async fn authenticate(&self, token: &str) -> Result<PlatformIdentity, InternalAuthNError> {
Ok(PlatformIdentity::Shared { name: token.to_owned() })
}
}
let cached = CachingInternalAuthenticator::new(AlwaysOk, Duration::from_secs(30))?;Implementations§
Source§impl<A> CachingInternalAuthenticator<A>
impl<A> CachingInternalAuthenticator<A>
Sourcepub fn new(inner: A, ttl: Duration) -> Result<Self, InvalidCacheTtl>
pub fn new(inner: A, ttl: Duration) -> Result<Self, InvalidCacheTtl>
Wrap inner, caching successful validations for up to ttl (clamped
to the credential’s own expiry when it is a JWT) and rejections for a
short fixed window.
§Errors
Returns InvalidCacheTtl if ttl is zero or exceeds
MAX_TOKEN_REVIEW_CACHE_TTL.
Sourcepub fn with_default_ttl(inner: A) -> Self
pub fn with_default_ttl(inner: A) -> Self
Wrap inner with the DEFAULT_TOKEN_REVIEW_CACHE_TTL.
Sourcepub fn with_authentication_timeout(self, timeout: Duration) -> Self
pub fn with_authentication_timeout(self, timeout: Duration) -> Self
Override the deadline applied to the whole authenticate call
(including the per-token lock wait), replacing
DEFAULT_AUTHENTICATION_TIMEOUT.
Trait Implementations§
Source§impl<A> Debug for CachingInternalAuthenticator<A>
impl<A> Debug for CachingInternalAuthenticator<A>
Source§impl<A: InternalAuthenticator> InternalAuthenticator for CachingInternalAuthenticator<A>
impl<A: InternalAuthenticator> InternalAuthenticator for CachingInternalAuthenticator<A>
Source§async fn authenticate(
&self,
token: &str,
) -> Result<PlatformIdentity, InternalAuthNError>
async fn authenticate( &self, token: &str, ) -> Result<PlatformIdentity, InternalAuthNError>
Authenticate the raw
X-ToolKit-Internal-Token value and resolve the
caller’s PlatformIdentity. Read moreAuto Trait Implementations§
impl<A> !Freeze for CachingInternalAuthenticator<A>
impl<A> !RefUnwindSafe for CachingInternalAuthenticator<A>
impl<A> !UnwindSafe for CachingInternalAuthenticator<A>
impl<A> Send for CachingInternalAuthenticator<A>where
A: Send,
impl<A> Sync for CachingInternalAuthenticator<A>where
A: Sync,
impl<A> Unpin for CachingInternalAuthenticator<A>where
A: Unpin,
impl<A> UnsafeUnpin for CachingInternalAuthenticator<A>where
A: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more