pub struct Authorizer { /* private fields */ }
Expand description
used to check authorization policies on a token
can be created from AuthorizerBuilder::build, AuthorizerBuilder::build_unauthenticated or Biscuit::authorizer
Implementations§
Source§impl Authorizer
impl Authorizer
pub fn from_snapshot(input: AuthorizerSnapshot) -> Result<Self, Token>
pub fn from_raw_snapshot(input: &[u8]) -> Result<Self, Token>
pub fn from_base64_snapshot(input: &str) -> Result<Self, Token>
pub fn snapshot(&self) -> Result<AuthorizerSnapshot, Format>
pub fn to_raw_snapshot(&self) -> Result<Vec<u8>, Format>
pub fn to_base64_snapshot(&self) -> Result<String, Format>
Source§impl Authorizer
impl Authorizer
pub fn run(&mut self) -> Result<Duration, Token>
Sourcepub fn from(data: &[u8]) -> Result<Self, Token>
pub fn from(data: &[u8]) -> Result<Self, Token>
creates an Authorizer
from a serialized crate::format::schema::AuthorizerPolicies
Sourcepub fn save(&self) -> Result<AuthorizerPolicies, Token>
pub fn save(&self) -> Result<AuthorizerPolicies, Token>
serializes a authorizer’s content
you can use this to save a set of policies and load them quickly before verification. This will not store data obtained or generated from a token.
Sourcepub fn limits(&self) -> &AuthorizerLimits
pub fn limits(&self) -> &AuthorizerLimits
Returns the runtime limits of the authorizer
Those limits cover all the executions under the authorize
, query
and query_all
methods
Sourcepub fn external_funcs(&self) -> &HashMap<String, ExternFunc>
pub fn external_funcs(&self) -> &HashMap<String, ExternFunc>
Returns the currently registered external functions
Sourcepub fn query<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>(
&mut self,
rule: R,
) -> Result<Vec<T>, Token>
pub fn query<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>( &mut self, rule: R, ) -> Result<Vec<T>, Token>
run a query over the authorizer’s Datalog engine to gather data
let keypair = KeyPair::new();
let biscuit = Biscuit::builder()
.fact("user(\"John Doe\", 42)")
.expect("parse error")
.build(&keypair)
.unwrap();
let mut authorizer = biscuit.authorizer().unwrap();
let res: Vec<(String, i64)> = authorizer.query("data($name, $id) <- user($name, $id)").unwrap();
Sourcepub fn query_exactly_one<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>(
&mut self,
rule: R,
) -> Result<T, Token>
pub fn query_exactly_one<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>( &mut self, rule: R, ) -> Result<T, Token>
Run a query over the authorizer’s Datalog engine to gather data. If there is more than one result, this function will throw an error.
let keypair = KeyPair::new();
let builder = Biscuit::builder().fact("user(\"John Doe\", 42)").unwrap();
let biscuit = builder.build(&keypair).unwrap();
let mut authorizer = biscuit.authorizer().unwrap();
let res: (String, i64) = authorizer.query_exactly_one("data($name, $id) <- user($name, $id)").unwrap();
assert_eq!(res.0, "John Doe");
assert_eq!(res.1, 42);
Sourcepub fn query_with_limits<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>(
&mut self,
rule: R,
limits: AuthorizerLimits,
) -> Result<Vec<T>, Token>
pub fn query_with_limits<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>( &mut self, rule: R, limits: AuthorizerLimits, ) -> Result<Vec<T>, Token>
run a query over the authorizer’s Datalog engine to gather data
this only sees facts from the authorizer and the authority block
this method overrides the authorizer’s runtime limits, just for this calls
Sourcepub fn query_all<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>(
&mut self,
rule: R,
) -> Result<Vec<T>, Token>
pub fn query_all<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>( &mut self, rule: R, ) -> Result<Vec<T>, Token>
run a query over the authorizer’s Datalog engine to gather data
this has access to the facts generated when evaluating all the blocks
let keypair = KeyPair::new();
let biscuit = Biscuit::builder()
.fact("user(\"John Doe\", 42)")
.expect("parse error")
.build(&keypair)
.unwrap();
let mut authorizer = biscuit.authorizer().unwrap();
let res: Vec<(String, i64)> = authorizer.query_all("data($name, $id) <- user($name, $id)").unwrap();
Sourcepub fn query_all_with_limits<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>(
&mut self,
rule: R,
limits: AuthorizerLimits,
) -> Result<Vec<T>, Token>
pub fn query_all_with_limits<R: TryInto<Rule>, T: TryFrom<Fact, Error = E>, E: Into<Token>>( &mut self, rule: R, limits: AuthorizerLimits, ) -> Result<Vec<T>, Token>
run a query over the authorizer’s Datalog engine to gather data
this has access to the facts generated when evaluating all the blocks
this method overrides the authorizer’s runtime limits, just for this calls
Sourcepub fn execution_time(&self) -> Option<Duration>
pub fn execution_time(&self) -> Option<Duration>
returns the elapsed execution time
Sourcepub fn iterations(&self) -> u64
pub fn iterations(&self) -> u64
returns the number of fact generation iterations
Sourcepub fn fact_count(&self) -> usize
pub fn fact_count(&self) -> usize
returns the number of facts
verifies the checks and policies
on error, this can return a list of all the failed checks or deny policy on success, it returns the index of the policy that matched
verifies the checks and policies
on error, this can return a list of all the failed checks or deny policy
this method overrides the authorizer’s runtime limits, just for this calls
Sourcepub fn print_world(&self) -> String
pub fn print_world(&self) -> String
prints the content of the authorizer
Sourcepub fn dump(&self) -> (Vec<Fact>, Vec<Rule>, Vec<Check>, Vec<Policy>)
pub fn dump(&self) -> (Vec<Fact>, Vec<Rule>, Vec<Check>, Vec<Policy>)
returns all of the data loaded in the authorizer
pub fn dump_code(&self) -> String
Trait Implementations§
Source§impl Clone for Authorizer
impl Clone for Authorizer
Source§fn clone(&self) -> Authorizer
fn clone(&self) -> Authorizer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more