use rocketmq_security_api::PeerInfo;
use rocketmq_security_api::Principal;
use rocketmq_security_api::SecurityBootstrapProfile;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum EmbeddedCaller {
BrokerProxy,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum RequestOrigin {
Network {
peer: PeerInfo,
},
Embedded {
caller: EmbeddedCaller,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum AuthenticationState {
#[allow(
private_interfaces,
reason = "the private proof prevents untrusted construction while patterns can inspect the principal"
)]
Authenticated(Principal, AuthenticationProof),
Anonymous,
SecurityDisabled,
}
impl AuthenticationState {
pub(crate) fn from_network_principal(principal: Option<Principal>, profile: SecurityBootstrapProfile) -> Self {
match (principal, profile) {
(Some(principal), _) => Self::Authenticated(principal, AuthenticationProof),
(None, SecurityBootstrapProfile::DevelopmentInsecureLoopback) => Self::SecurityDisabled,
(None, SecurityBootstrapProfile::SecureEnforced) => Self::Anonymous,
}
}
pub(crate) fn authenticated(principal: Principal) -> Self {
Self::Authenticated(principal, AuthenticationProof)
}
#[must_use]
pub const fn principal(&self) -> Option<&Principal> {
match self {
Self::Authenticated(principal, ..) => Some(principal),
Self::Anonymous | Self::SecurityDisabled => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct AuthenticationProof;