MCPcopy Index your code
hub / github.com/cedar-policy/cedar-java / json_stateful_is_authorized

Function json_stateful_is_authorized

CedarJavaFFI/src/interface.rs:372–479  ·  view source on GitHub ↗
(input: &str)

Source from the content-addressed store, hash-verified

370}
371
372fn json_stateful_is_authorized(input: &str) -> serde_json::Result<String> {
373 let call: StatefulAuthCall = serde_json::from_str(input)?;
374
375 // Look up cached policy set
376 let policies = CACHED_POLICY_SETS
377 .get(&call.preparsed_policy_set_id)
378 .map(|r| r.clone());
379 let policies = match policies {
380 Some(p) => p,
381 None => {
382 return serde_json::to_string(&make_auth_failure(format!(
383 "preparsed policy set '{}' not found",
384 call.preparsed_policy_set_id
385 )));
386 }
387 };
388
389 // Look up cached schema (optional)
390 let schema = if let Some(ref schema_name) = call.preparsed_schema_name {
391 let s = CACHED_SCHEMAS.get(schema_name).map(|r| r.clone());
392 match s {
393 Some(schema) => Some(schema),
394 None => {
395 return serde_json::to_string(&make_auth_failure(format!(
396 "preparsed schema '{}' not found",
397 schema_name
398 )));
399 }
400 }
401 } else {
402 None
403 };
404
405 // Parse principal, action, resource via FFI EntityUid type
406 let principal: FfiEntityUid = match serde_json::from_value(call.principal) {
407 Ok(p) => p,
408 Err(e) => {
409 return serde_json::to_string(&make_auth_failure(format!(
410 "failed to parse principal: {e}"
411 )));
412 }
413 };
414 let action: FfiEntityUid = match serde_json::from_value(call.action) {
415 Ok(a) => a,
416 Err(e) => {
417 return serde_json::to_string(&make_auth_failure(format!(
418 "failed to parse action: {e}"
419 )));
420 }
421 };
422 let resource: FfiEntityUid = match serde_json::from_value(call.resource) {
423 Ok(r) => r,
424 Err(e) => {
425 return serde_json::to_string(&make_auth_failure(format!(
426 "failed to parse resource: {e}"
427 )));
428 }
429 };

Callers 1

call_cedarFunction · 0.85

Calls 4

make_auth_failureFunction · 0.85
getMethod · 0.45
parseMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected