soaprs_auth/
authentication.rs1use soaprs_core::{BoxFuture, SoapResult};
4
5use crate::AuthorizationName;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct Authentication<P> {
10 strategy: AuthorizationName,
11 principal: P,
12}
13
14impl<P> Authentication<P> {
15 pub fn new(strategy: impl Into<String>, principal: P) -> SoapResult<Self> {
17 Ok(Self {
18 strategy: AuthorizationName::new(strategy)?,
19 principal,
20 })
21 }
22
23 pub const fn strategy(&self) -> &AuthorizationName {
25 &self.strategy
26 }
27
28 pub const fn principal(&self) -> &P {
30 &self.principal
31 }
32
33 pub fn into_principal(self) -> P {
35 self.principal
36 }
37}
38
39pub trait Authenticator<C, P>: Send + Sync
41where
42 C: Send,
43 P: Send,
44{
45 fn authenticate(&self, credential: C) -> BoxFuture<'_, SoapResult<Authentication<P>>>;
47}