use crate::{AclSource, AuthorizationRequest, AuthorizationResult, Authorizer};
#[derive(Debug, Default)]
pub struct AllowAllAuthorizer;
impl Authorizer for AllowAllAuthorizer {
fn authorize(
&self,
_source: &dyn AclSource,
_req: &AuthorizationRequest<'_>,
) -> AuthorizationResult {
AuthorizationResult::Allow
}
}
#[cfg(test)]
mod tests {
use super::*;
use assert2::assert;
use crabka_metadata::{AclOperation, MetadataImage, ResourceType};
use crabka_security::{AuthMethod, Principal};
use std::net::SocketAddr;
use uuid::Uuid;
#[test]
fn allow_all_returns_allow_for_any_request() {
let img = MetadataImage::new(Uuid::nil());
let p = Principal {
name: "alice".into(),
auth_method: AuthMethod::SaslPlain,
groups: vec![],
};
let host: SocketAddr = "1.2.3.4:9092".parse().unwrap();
let req = AuthorizationRequest {
principal: &p,
host: &host,
resource_type: ResourceType::Topic,
resource_name: "anything",
operation: AclOperation::Write,
};
assert!(AllowAllAuthorizer.authorize(&img, &req) == AuthorizationResult::Allow);
}
}