use crate::error::GarrisonResult;
use async_trait::async_trait;
use super::DeviceBindingPolicy;
pub(super) async fn check_is_new_device(
session: &crate::session::GarrisonSession,
login_id: &str,
device_id: &str,
) -> GarrisonResult<bool> {
if device_id.is_empty() {
tracing::warn!(
login_id,
"check_is_new_device: empty device_id treated as known device (device binding check skipped; reject empty device upstream for fail-closed)"
);
return Ok(false);
}
let tokens = session.get_tokens_by_login_id(login_id);
if tokens.is_empty() {
return Ok(true);
}
for token in &tokens {
if let Some(ts) = session.get_token_session(token).await? {
if ts.device.as_deref() == Some(device_id) {
return Ok(false);
}
}
}
Ok(true)
}
#[derive(Debug, Default)]
pub struct Disabled;
#[async_trait]
impl DeviceBindingPolicy for Disabled {
async fn is_new_device(&self, _login_id: &str, _device_id: &str) -> GarrisonResult<bool> {
Ok(false)
}
async fn require_secondary_auth(
&self,
_login_id: &str,
_device_id: &str,
) -> GarrisonResult<bool> {
Ok(false)
}
}