rust_web_server/authz/
mod.rs1pub(crate) mod config;
27pub(crate) mod identity;
28mod layer;
29pub mod rebac;
30#[cfg(any(feature = "model-sqlite", feature = "model-postgres", feature = "model-mysql"))]
31pub mod sql;
32
33pub use identity::{with_identity, Identity};
34pub use layer::{AuthzLayer, ObjectTemplate};
35#[cfg(any(feature = "model-sqlite", feature = "model-postgres", feature = "model-mysql"))]
36pub use sql::SqlStore;
37pub use rebac::{AuthzError, Authorizer, MemoryStore, ObjectRef, Schema, Subject, Tuple, TupleFilter, TupleStore};
38#[cfg(feature = "http2")]
39pub use identity::scope_identity;
40
41#[cfg(test)]
42pub(crate) mod test_support {
43 use crate::application::Application;
44 use crate::request::Request;
45 use crate::response::{Response, STATUS_CODE_REASON_PHRASE};
46 use crate::server::ConnectionInfo;
47
48 pub(crate) struct WhoAmI;
50
51 impl Application for WhoAmI {
52 fn execute(&self, _request: &Request, _connection: &ConnectionInfo) -> Result<Response, String> {
53 let who = super::Identity::current().map_or("anonymous".to_string(), |i| format!("{} via {}", i.subject(), i.source()));
54 Ok(Response::text(STATUS_CODE_REASON_PHRASE.n200_ok, &who))
55 }
56 }
57
58 pub(crate) fn body(response: &Response) -> String {
59 String::from_utf8_lossy(&response.content_range_list.first().map(|c| c.body.clone()).unwrap_or_default()).to_string()
60 }
61}
62
63#[cfg(test)]
64mod tests;