Function check_authorization

Source
pub fn check_authorization(
    expression: &str,
    tokens: &[String],
) -> Result<bool, ParserError>
Expand description

Checks if the given set of access tokens authorizes access to the resource which protection is described by the given expression.

Arguments:

  • expression - The expression to parse and evaluate.
  • tokens - The set of access tokens to check.

Returns:

  • Ok(true) if the expression is valid and the tokens are authorized.
  • Ok(false) if the expression is valid and the tokens are not authorized.
  • Err(ParserError) if the expression is invalid.

§Examples

use accumulo_access::check_authorization;

   let expression = "label1|label5";
   let tokens = &Vec::from([
     String::from("label1"),
     String::from("label5"),
     String::from("label 🕺"),
   ]);

   let result = match check_authorization(expression, tokens) {
    Ok(result) => {
        assert_eq!(result, true);
    }
    Err(_) => panic!("Unexpected error"),
   };