Skip to content

Commit

Permalink
fix: populate Authorizer.world with facts and rules from snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
divarvel committed Dec 6, 2024
1 parent 096c335 commit e50cddc
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions biscuit-auth/src/token/authorizer/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,46 @@ impl super::Authorizer {
authorizer.blocks = Some(blocks);
}

let mut authorizer_origin = Origin::default();
authorizer_origin.insert(usize::MAX);

let authorizer_scopes: Vec<crate::token::Scope> = authorizer
.authorizer_block_builder
.scopes
.clone()
.iter()
.map(|s| s.convert(&mut authorizer.symbols))
.collect();

let authorizer_trusted_origins = TrustedOrigins::from_scopes(
&authorizer_scopes,
&TrustedOrigins::default(),
usize::MAX,
&authorizer.public_key_to_block_id,
);
for fact in &authorizer.authorizer_block_builder.facts {
authorizer
.world
.facts
.insert(&authorizer_origin, fact.convert(&mut authorizer.symbols));
}

for rule in &authorizer.authorizer_block_builder.rules {
let rule = rule.convert(&mut authorizer.symbols);

let rule_trusted_origins = TrustedOrigins::from_scopes(
&rule.scopes,
&authorizer_trusted_origins,
usize::MAX,
&authorizer.public_key_to_block_id,
);

authorizer
.world
.rules
.insert(usize::MAX, &rule_trusted_origins, rule);
}

for GeneratedFacts { origins, facts } in world.generated_facts {
let origin = proto_origin_to_authorizer_origin(&origins)?;

Expand Down

0 comments on commit e50cddc

Please sign in to comment.