generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 30
adds validateWithLevel API for CedarJava #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
muditchaudhary
merged 6 commits into
cedar-policy:main
from
muditchaudhary:4.4_release/features/validate_with_level
Aug 1, 2025
+747
−26
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d753389
adds validate_with_level FFI helper methods
muditchaudhary 71f31de
adds validate with level operation to interface
muditchaudhary f47ba08
adds validateWithLevel API
muditchaudhary 5538492
adds validateWithLevel tests
muditchaudhary 2ca8306
fixes nits
muditchaudhary 0aac094
fixes nits
muditchaudhary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
CedarJava/src/main/java/com/cedarpolicy/model/LevelValidationRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Copyright Cedar Contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.cedarpolicy.model; | ||
|
|
||
| import com.cedarpolicy.model.schema.Schema; | ||
| import com.cedarpolicy.model.policy.PolicySet; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** Information passed to Cedar for level validation. */ | ||
| public final class LevelValidationRequest { | ||
| private final Schema schema; | ||
| private final PolicySet policies; | ||
| private final long maxDerefLevel; // Must be non-negative (>=0) | ||
|
|
||
| /** | ||
| * Construct a validation request. | ||
| * | ||
| * @param schema Schema for the request | ||
| * @param policies Map of Policy ID to policy | ||
| * @param maxDerefLevel Maximum level of dereferencing allowed for validation. Must be non-negative (>=0) | ||
| */ | ||
| @SuppressFBWarnings | ||
| public LevelValidationRequest(Schema schema, PolicySet policies, long maxDerefLevel) { | ||
| if (schema == null) { | ||
| throw new NullPointerException("schema"); | ||
| } | ||
|
|
||
| if (policies == null) { | ||
| throw new NullPointerException("policies"); | ||
| } | ||
|
|
||
| if (maxDerefLevel < 0) { | ||
| throw new IllegalArgumentException("maxDerefLevel must be non-negative"); | ||
| } | ||
|
|
||
| this.schema = schema; | ||
| this.policies = policies; | ||
| this.maxDerefLevel = maxDerefLevel; | ||
| } | ||
|
|
||
| /** | ||
| * Get the schema. | ||
| * | ||
| * @return The schema. | ||
| */ | ||
| public Schema getSchema() { | ||
| return this.schema; | ||
| } | ||
|
|
||
| /** | ||
| * Get the policy set. | ||
| * | ||
| * @return A `PolicySet` object | ||
| */ | ||
| @JsonProperty("policies") | ||
| public PolicySet getPolicySet() { | ||
| return this.policies; | ||
| } | ||
|
|
||
| /** | ||
| * Get the maximum deref level. | ||
| * | ||
| * @return The maximum deref level value for validation | ||
| */ | ||
| public long getMaxDerefLevel() { | ||
| return this.maxDerefLevel; | ||
| } | ||
|
|
||
| /** Test equality. */ | ||
| @Override | ||
| public boolean equals(final Object o) { | ||
| if (!(o instanceof LevelValidationRequest)) { | ||
| return false; | ||
| } | ||
|
|
||
| final LevelValidationRequest other = (LevelValidationRequest) o; | ||
| return schema.equals(other.schema) && policies.equals(other.policies) && maxDerefLevel == other.maxDerefLevel; | ||
| } | ||
|
|
||
| /** Hash. */ | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(schema, policies, maxDerefLevel); | ||
| } | ||
|
|
||
| /** Get readable string representation. */ | ||
| public String toString() { | ||
| return "ValidationRequest(schema=" + schema + ", policies=" + policies + ", maxDerefLevel=" + maxDerefLevel | ||
| + ")"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit as an aside: Looks like this is how we do it in most places, but here it looks like we print it differently.
I wonder what our appetite for using something like Lombok to improve boilerplate like this and getters/setters is: https://projectlombok.org/features/NonNull
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there is some inconsistency in the message. I followed the message that we use in
ValidationRequestconstructor.Maybe we can do a Lombok "campaign" to avoid inconsistency across CedarJava before the release.