MCPcopy Create free account
hub / github.com/cedar-policy/cedar-java / preparsePolicySetJni

Function preparsePolicySetJni

CedarJavaFFI/src/interface.rs:131–193  ·  view source on GitHub ↗
(
    mut env: JNIEnv<'_>,
    _class: JClass<'_>,
    j_id: JString<'_>,
    j_policies_json: JString<'_>,
)

Source from the content-addressed store, hash-verified

129/// Direct JNI entry point to pre-parse and cache a policy set.
130#[jni_fn("com.cedarpolicy.model.policy.PolicySet")]
131pub fn preparsePolicySetJni(
132 mut env: JNIEnv<'_>,
133 _class: JClass<'_>,
134 j_id: JString<'_>,
135 j_policies_json: JString<'_>,
136) {
137 let id: String = match env.get_string(&j_id) {
138 Ok(s) => s.into(),
139 Err(e) => {
140 let _ = env.throw_new(
141 "com/cedarpolicy/model/exception/InternalException",
142 format!("Failed to read policy set cache ID: {e}"),
143 );
144 return;
145 }
146 };
147 let policies_json: String = match env.get_string(&j_policies_json) {
148 Ok(s) => s.into(),
149 Err(e) => {
150 let _ = env.throw_new(
151 "com/cedarpolicy/model/exception/InternalException",
152 format!("Failed to read policy set JSON: {e}"),
153 );
154 return;
155 }
156 };
157 let policy_set_ffi: PolicySetFFI = match serde_json::from_str(&policies_json) {
158 Ok(ps) => ps,
159 Err(e) => {
160 let _ = env.throw_new(
161 "com/cedarpolicy/model/exception/InternalException",
162 format!("Failed to parse policy set JSON: {e}"),
163 );
164 return;
165 }
166 };
167 match policy_set_ffi.parse() {
168 Ok(parsed) => {
169 if is_cache_full(
170 &CACHED_POLICY_SETS,
171 MAX_CACHED_POLICY_SETS.load(Ordering::Relaxed),
172 ) {
173 let _ = env.throw_new(
174 "com/cedarpolicy/model/exception/InternalException",
175 "Policy set cache is full; increase cedar.cache.maxPolicySets or clear unused entries",
176 );
177 return;
178 }
179 CACHED_POLICY_SETS.insert(id, parsed);
180 }
181 Err(errors) => {
182 let msg = errors
183 .into_iter()
184 .map(|e| e.to_string())
185 .collect::<Vec<_>>()
186 .join("; ");
187 let _ = env.throw_new(
188 "com/cedarpolicy/model/exception/InternalException",

Callers

nothing calls this directly

Calls 2

is_cache_fullFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected