use std::sync::Arc;
use async_trait::async_trait;
use crate::error::SaTokenResult;
use crate::repository::GrantRepo;
use crate::stp_interface::StpInterface;
pub struct StorageStpInterface {
grant_repo: Arc<GrantRepo>,
}
impl std::fmt::Debug for StorageStpInterface {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("StorageStpInterface").finish()
}
}
impl StorageStpInterface {
pub fn new(grant_repo: Arc<GrantRepo>) -> Self {
Self { grant_repo }
}
pub fn grant_repo(&self) -> &Arc<GrantRepo> {
&self.grant_repo
}
}
#[async_trait]
impl StpInterface for StorageStpInterface {
async fn get_permission_list(
&self,
login_id: &str,
login_type: &str,
) -> SaTokenResult<Vec<String>> {
self.grant_repo.get_permissions(login_type, login_id).await
}
async fn get_role_list(&self, login_id: &str, login_type: &str) -> SaTokenResult<Vec<String>> {
self.grant_repo.get_roles(login_type, login_id).await
}
fn is_writable(&self) -> bool {
true
}
}