Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CedarJava/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Changelog

## Unreleased
### Added
* Added Zig version validation for publishing artifacts [#306](https://github.com/cedar-policy/cedar-java/pull/306)

## 4.3.0
### Added
* Introduced new model classes for improved type safety and functionality:
* `com.cedarpolicy.model.Context` - Policy context representation (will replace `Map<String,Value>`) [#286](https://github.com/cedar-policy/cedar-java/pull/286)
* `com.cedarpolicy.model.entity.Entities` - Entity collection management (will replace `Set<Entity>`) [#293](https://github.com/cedar-policy/cedar-java/pull/293)
* Enhanced `AuthorizationError` with public getters and `.toString()` method [#294](https://github.com/cedar-policy/cedar-java/pull/294)
* Added JSON parsing support for `Entity` [#292](https://github.com/cedar-policy/cedar-java/pull/292)
* Implemented additional constructors to improve instantiation options for `Entity` [#288](https://github.com/cedar-policy/cedar-java/pull/288)
* Added support for policy annotations [#296](https://github.com/cedar-policy/cedar-java/pull/296)

### Planned Improvements
* The following authorization parameters will be updated in a future release:
* `Map<String,Value>` for context will be replaced by `com.cedarpolicy.model.Context`
* `Set<Entity>` for entities will be replaced by `com.cedarpolicy.model.entity.Entities`

## 3.0

* Reworked interface of `com.cedarpolicy.value.EntityUID` to support namespaces
* Modified `com.cedarpolicy.model.AuthorizationRequest` to use `com.cedarpolicy.value.EntityUID` instead of Strings
Expand Down
22 changes: 22 additions & 0 deletions CedarJava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dependencies {
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.8.6'
testImplementation 'net.jqwik:jqwik:1.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.4'
testImplementation 'org.skyscreamer:jsonassert:2.0-rc1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.4'
}

Expand Down Expand Up @@ -123,6 +124,26 @@ tasks.register('installCargoZigbuild', Exec) {
commandLine 'cargo', '+' + RustVersion, 'install', 'cargo-zigbuild@0.19.7'
}

def ZigVersion = '0.11'
tasks.register('validateZigVersion') {
group = 'Build'
description = 'Validates that the correct zig version is installed'

doLast {
def output = new ByteArrayOutputStream()
exec {
commandLine 'zig', 'version'
standardOutput = output
}
def version = output.toString().trim()
println "Detected Zig version: ${version}"
if (!version.startsWith(ZigVersion)) {
throw new GradleException("Zig version must be ${ZigVersion} but found: ${version}")
}
println "Zig version validation successful"
}
}

tasks.register('compileFFI') {
dependsOn('installCargoZigbuild')
group 'Build'
Expand Down Expand Up @@ -251,6 +272,7 @@ java {
/*
Configures Maven publishing
*/
publish.dependsOn('validateZigVersion')
publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
Binary file modified CedarJava/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions CedarJava/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 13 additions & 9 deletions CedarJava/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions CedarJava/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 44 additions & 4 deletions CedarJava/src/main/java/com/cedarpolicy/AuthorizationEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@

package com.cedarpolicy;

import com.cedarpolicy.model.*;
import java.util.Set;

import com.cedarpolicy.model.AuthorizationRequest;
import com.cedarpolicy.model.AuthorizationResponse;
import com.cedarpolicy.model.EntityValidationRequest;
import com.cedarpolicy.model.PartialAuthorizationRequest;
import com.cedarpolicy.model.PartialAuthorizationResponse;
import com.cedarpolicy.model.ValidationRequest;
import com.cedarpolicy.model.ValidationResponse;
import com.cedarpolicy.model.entity.Entities;
import com.cedarpolicy.model.entity.Entity;
import com.cedarpolicy.model.exception.AuthException;
import com.cedarpolicy.model.exception.BadRequestException;
import com.cedarpolicy.model.entity.Entity;
import com.cedarpolicy.model.policy.PolicySet;

import java.util.Set;

/**
* Implementations of the AuthorizationEngine interface invoke Cedar to respond to an authorization
* or validation request. For authorization, the input includes the relevant policies and entities for
Expand Down Expand Up @@ -51,6 +58,21 @@ public interface AuthorizationEngine {
*/
AuthorizationResponse isAuthorized(AuthorizationRequest request, PolicySet policySet, Set<Entity> entities) throws AuthException;

/**
* Asks whether the given AuthorizationRequest <code>q</code> is approved by the <code>policySet</code> and
* <code>entities</code> hierarchy given. Overloaded method to accept Entities object.
*
* @param request The request to evaluate
* @param policySet The policy set to evaluate against
* @param entities The entities to evaluate against
* @return The result of the request evaluation
* @throws BadRequestException if any errors were found in the syntax of the policies.
* @throws AuthException On failure to make the authorization request. Note that errors inside the
* authorization engine are included in the <code>errors</code> field on the
* AuthorizationResponse.
*/
AuthorizationResponse isAuthorized(AuthorizationRequest request, PolicySet policySet, Entities entities) throws AuthException;

/**
* Asks whether the given AuthorizationRequest <code>q</code> is approved by the <code>policySet</code> and
* <code>entities</code> given. If information required to answer is missing, residual policies are returned.
Expand All @@ -68,6 +90,24 @@ public interface AuthorizationEngine {
PartialAuthorizationResponse isAuthorizedPartial(PartialAuthorizationRequest request,
PolicySet policySet, Set<Entity> entities) throws AuthException;

/**
* Asks whether the given AuthorizationRequest <code>q</code> is approved by the <code>policySet</code> and
* <code>entities</code> given. If information required to answer is missing, residual policies are returned.
* Overloaded method to accept Entities object.
*
* @param request The request to evaluate
* @param policySet The policy set to evaluate against
* @param entities The entities to evaluate against
* @return The result of the request evaluation
* @throws BadRequestException if any errors were found in the syntax of the policies.
* @throws AuthException On failure to make the authorization request. Note that errors inside the
* authorization engine are included in the <code>errors</code> field on the
* AuthorizationResponse.
*/
@Experimental(ExperimentalFeature.PARTIAL_EVALUATION)
PartialAuthorizationResponse isAuthorizedPartial(PartialAuthorizationRequest request,
PolicySet policySet, Entities entities) throws AuthException;

/**
* Asks whether the policies in the given {@link ValidationRequest} <code>q</code> are correct
* when validated against the schema it describes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,30 @@
import static com.cedarpolicy.CedarJson.objectWriter;

import java.io.IOException;
import java.util.List;
import java.util.Set;

import com.cedarpolicy.loader.LibraryLoader;
import com.cedarpolicy.model.*;
import com.cedarpolicy.model.AuthorizationResponse;
import com.cedarpolicy.model.EntityValidationRequest;
import com.cedarpolicy.model.PartialAuthorizationResponse;
import com.cedarpolicy.model.ValidationRequest;
import com.cedarpolicy.model.ValidationResponse;
import com.cedarpolicy.model.entity.Entities;
import com.cedarpolicy.model.entity.Entity;
import com.cedarpolicy.model.exception.AuthException;
import com.cedarpolicy.model.exception.BadRequestException;
import com.cedarpolicy.model.exception.InternalException;
import com.cedarpolicy.model.exception.MissingExperimentalFeatureException;
import com.cedarpolicy.model.entity.Entity;
import com.cedarpolicy.model.policy.PolicySet;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.List;
import java.util.Set;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/** An authorization engine that is compiled in process. Communicated with via JNI. */
public final class BasicAuthorizationEngine implements AuthorizationEngine {
Expand All @@ -57,6 +62,15 @@ public AuthorizationResponse isAuthorized(com.cedarpolicy.model.AuthorizationReq
return call("AuthorizationOperation", AuthorizationResponse.class, request);
}

/**
* Overloaded method to accept Entities object
*/
@Override
public AuthorizationResponse isAuthorized(com.cedarpolicy.model.AuthorizationRequest q,
PolicySet policySet, Entities entities) throws AuthException {
return isAuthorized(q, policySet, entities.getEntities());
}

@Experimental(ExperimentalFeature.PARTIAL_EVALUATION)
@Override
public PartialAuthorizationResponse isAuthorizedPartial(com.cedarpolicy.model.PartialAuthorizationRequest q,
Expand All @@ -73,6 +87,16 @@ public PartialAuthorizationResponse isAuthorizedPartial(com.cedarpolicy.model.Pa
}
}

/**
* Overloaded method to accept Entities object
*/
@Experimental(ExperimentalFeature.PARTIAL_EVALUATION)
@Override
public PartialAuthorizationResponse isAuthorizedPartial(com.cedarpolicy.model.PartialAuthorizationRequest q,
PolicySet policySet, Entities entities) throws AuthException {
return isAuthorizedPartial(q, policySet, entities.getEntities());
}

@Override
public ValidationResponse validate(ValidationRequest q) throws AuthException {
return call("ValidateOperation", ValidationResponse.class, q);
Expand Down
Loading
Loading