pub enum AuthorizationExpression {
ConjunctionOf(Vec<AuthorizationExpression>),
DisjunctionOf(Vec<AuthorizationExpression>),
AccessToken(String),
Nil,
}Variants§
ConjunctionOf(Vec<AuthorizationExpression>)
A conjunction of multiple access tokens or scopes.
DisjunctionOf(Vec<AuthorizationExpression>)
A disjunction of multiple access tokens or scopes.
AccessToken(String)
An access token.
Nil
A nil expression (empty string).
Implementations§
Source§impl AuthorizationExpression
impl AuthorizationExpression
Sourcepub fn from_json(json: &Value) -> Result<Self, String>
pub fn from_json(json: &Value) -> Result<Self, String>
Create a new AuthorizationExpression from a JSON value.
§Arguments
json - The JSON value to parse.
§Returns
A new AuthorizationExpression instance.
§Example
use accumulo_access::AuthorizationExpression;
let json = serde_json::json!({
"and": [
"A",
{
"or": [
"B",
"C"
]
}
]
});
let expr = AuthorizationExpression::from_json(&json).unwrap();Sourcepub fn evaluate(&self, authorizations: &HashSet<String>) -> bool
pub fn evaluate(&self, authorizations: &HashSet<String>) -> bool
Evaluate the expression with the given set of authorizations.
Returns true if the authorizations are valid, false otherwise.
§Arguments
authorizations - The set of authorizations to check.
§Example
use std::collections::HashSet;
use accumulo_access::AuthorizationExpression;
let expr = AuthorizationExpression::ConjunctionOf(vec![
AuthorizationExpression::AccessToken("A".to_string()),
AuthorizationExpression::DisjunctionOf(vec![
AuthorizationExpression::AccessToken("B".to_string()),
AuthorizationExpression::AccessToken("C".to_string()),
]),
]);
let authorizations = HashSet::from([
"A".to_string(),
"B".to_string(),
]);
assert_eq!(expr.evaluate(&authorizations), true);Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Create a JSON representation of the expression tree.
§Returns
A JSON value representing the expression tree.
§Example
use accumulo_access::AuthorizationExpression;
let expr = AuthorizationExpression::ConjunctionOf(vec![
AuthorizationExpression::AccessToken("A".to_string()),
AuthorizationExpression::AccessToken("B".to_string()),
]);
let json = expr.to_json();
assert_eq!(json, serde_json::json!({"and": ["A", "B"]}));Sourcepub fn to_json_str(&self) -> String
pub fn to_json_str(&self) -> String
Create a JSON string representation of the expression tree.
§Returns
A JSON string representing the expression tree.
§Example
use accumulo_access::AuthorizationExpression;
let expr = AuthorizationExpression::ConjunctionOf(vec![
AuthorizationExpression::AccessToken("A".to_string()),
AuthorizationExpression::AccessToken("B".to_string()),
]);
let json_str = expr.to_json_str();
assert_eq!(json_str, "{\"and\":[\"A\",\"B\"]}");Sourcepub fn to_expression_str(&self) -> String
pub fn to_expression_str(&self) -> String
Create a string representation of the expression tree.
§Returns
A string representing the expression tree.
§Example
use accumulo_access::AuthorizationExpression;
let expr1 = AuthorizationExpression::ConjunctionOf(vec![
AuthorizationExpression::AccessToken("A".to_string()),
AuthorizationExpression::AccessToken("B".to_string()),
]);
let expr_str = expr1.to_expression_str();
assert_eq!(expr_str, "A&B"); ///
let expr2 = AuthorizationExpression::DisjunctionOf(vec![
AuthorizationExpression::AccessToken("A".to_string()),
AuthorizationExpression::AccessToken("B".to_string()),
]);
let expr_str = expr2.to_expression_str();
assert_eq!(expr_str, "A|B");Sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
Normalize the expression tree by sorting and deduplicating the nodes.
§Example
use accumulo_access::AuthorizationExpression;
let mut expr = AuthorizationExpression::ConjunctionOf(vec![
AuthorizationExpression::AccessToken("B".to_string()),
AuthorizationExpression::AccessToken("A".to_string()),
AuthorizationExpression::AccessToken("B".to_string()),
AuthorizationExpression::DisjunctionOf(vec![
AuthorizationExpression::AccessToken("C".to_string()),
AuthorizationExpression::AccessToken("D".to_string()),
AuthorizationExpression::AccessToken("D".to_string())]
)]);
expr.normalize();
let expected = AuthorizationExpression::ConjunctionOf(vec![
AuthorizationExpression::AccessToken("A".to_string()),
AuthorizationExpression::AccessToken("B".to_string()),
AuthorizationExpression::DisjunctionOf(vec![
AuthorizationExpression::AccessToken("C".to_string()),
AuthorizationExpression::AccessToken("D".to_string())]
)]);
assert_eq!(expr, expected);Trait Implementations§
Source§impl Clone for AuthorizationExpression
impl Clone for AuthorizationExpression
Source§fn clone(&self) -> AuthorizationExpression
fn clone(&self) -> AuthorizationExpression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more