From 710010e454cc5b193bbe66d900d2ad05b2c869e3 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Wed, 26 Aug 2026 17:20:14 -0700 Subject: [PATCH 01/42] Run Maven tests on every pull request. Give the repo a GitHub Actions workflow so PRs and main are checked automatically, running the server suite when that module is present. --- .github/workflows/ci.yml | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..6c283da79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + server-test: + name: Server tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Check for server module + id: server + run: | + if [ -f server/pom.xml ]; then + echo "present=true" >> "$GITHUB_OUTPUT" + else + echo "present=false" >> "$GITHUB_OUTPUT" + fi + + - uses: actions/setup-java@v4 + if: steps.server.outputs.present == 'true' + with: + distribution: temurin + java-version: "21" + cache: maven + cache-dependency-path: server/pom.xml + + - name: Run tests + if: steps.server.outputs.present == 'true' + working-directory: server + run: mvn -B -ntp verify + + - name: Skip Maven tests + if: steps.server.outputs.present != 'true' + run: echo "No server/pom.xml in this revision; skipping Maven tests." + + - name: Upload test reports + if: failure() + uses: actions/upload-artifact@v4 + with: + name: surefire-reports + path: server/target/surefire-reports/ + if-no-files-found: ignore From 15c596a3a9d7bda38eedc9a926e314694aa8a50b Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Wed, 26 Aug 2026 17:26:21 -0700 Subject: [PATCH 02/42] Add a Maven skeleton so CI can run server tests. Match the reference server's coordinates and Java 21 / Spring Boot 3.5.3 from the draft implementation PR, with a context-load test, so pull-request CI exercises mvn verify instead of skipping. --- server/.gitignore | 5 ++ server/pom.xml | 82 +++++++++++++++++++ .../io/opensharing/OpenSharingServer.java | 12 +++ .../io/opensharing/OpenSharingServerTest.java | 11 +++ 4 files changed, 110 insertions(+) create mode 100644 server/.gitignore create mode 100644 server/pom.xml create mode 100644 server/src/main/java/io/opensharing/OpenSharingServer.java create mode 100644 server/src/test/java/io/opensharing/OpenSharingServerTest.java diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 000000000..79bee1ea3 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,5 @@ +target/ +data/ +*.db +*.mv.db +*.trace.db diff --git a/server/pom.xml b/server/pom.xml new file mode 100644 index 000000000..9b9759f77 --- /dev/null +++ b/server/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + io.opensharing + opensharing-server + 0.1.0-SNAPSHOT + + OpenSharing Reference Server + Reference implementation of the OpenSharing protocol + + + + Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0 + + + + + UTF-8 + 21 + 3.5.3 + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + + -parameters + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + diff --git a/server/src/main/java/io/opensharing/OpenSharingServer.java b/server/src/main/java/io/opensharing/OpenSharingServer.java new file mode 100644 index 000000000..b972ae751 --- /dev/null +++ b/server/src/main/java/io/opensharing/OpenSharingServer.java @@ -0,0 +1,12 @@ +package io.opensharing; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class OpenSharingServer { + + public static void main(String[] args) { + SpringApplication.run(OpenSharingServer.class, args); + } +} diff --git a/server/src/test/java/io/opensharing/OpenSharingServerTest.java b/server/src/test/java/io/opensharing/OpenSharingServerTest.java new file mode 100644 index 000000000..5bbbe147a --- /dev/null +++ b/server/src/test/java/io/opensharing/OpenSharingServerTest.java @@ -0,0 +1,11 @@ +package io.opensharing; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class OpenSharingServerTest { + + @Test + void contextLoads() {} +} From f26b370f378dd3da51a5b3d22d78a66669769749 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Wed, 26 Aug 2026 17:52:58 -0700 Subject: [PATCH 03/42] Always run Maven tests, and pin GitHub Actions to SHAs. Drop the skip path now that server/ is in the tree, pin the runner to ubuntu-24.04, and pin checkout, setup-java, and upload-artifact to the same commit SHAs Delta Sharing uses. --- .github/workflows/ci.yml | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c283da79..01d42e740 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,21 +17,16 @@ permissions: jobs: server-test: name: Server tests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + defaults: + run: + working-directory: server steps: - - uses: actions/checkout@v4 - - - name: Check for server module - id: server - run: | - if [ -f server/pom.xml ]; then - echo "present=true" >> "$GITHUB_OUTPUT" - else - echo "present=false" >> "$GITHUB_OUTPUT" - fi + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-java@v4 - if: steps.server.outputs.present == 'true' + - name: Install Java 21 + uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4.8.0 with: distribution: temurin java-version: "21" @@ -39,17 +34,11 @@ jobs: cache-dependency-path: server/pom.xml - name: Run tests - if: steps.server.outputs.present == 'true' - working-directory: server run: mvn -B -ntp verify - - name: Skip Maven tests - if: steps.server.outputs.present != 'true' - run: echo "No server/pom.xml in this revision; skipping Maven tests." - - name: Upload test reports if: failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: surefire-reports path: server/target/surefire-reports/ From b59cbdaf7f92af862717fe54ffcd5bfff88d171a Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 13:22:59 -0700 Subject: [PATCH 04/42] Add server runtime configuration and metadata-store dependencies. --- server/README.md | 10 ++++ server/pom.xml | 22 ++++++++ server/src/main/resources/application.yml | 66 +++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 server/README.md create mode 100644 server/src/main/resources/application.yml diff --git a/server/README.md b/server/README.md new file mode 100644 index 000000000..537aabee3 --- /dev/null +++ b/server/README.md @@ -0,0 +1,10 @@ +# OpenSharing Reference Server + +Reference implementation of the [OpenSharing](https://github.com/OpenSharing-IO/OpenSharing) protocol. + +## Build + +```bash +cd server +mvn test +``` diff --git a/server/pom.xml b/server/pom.xml index 9b9759f77..72e1d55fa 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -41,6 +41,28 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-configuration-processor + true + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.h2database + h2 + runtime + org.springframework.boot spring-boot-starter-test diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml new file mode 100644 index 000000000..7319c81da --- /dev/null +++ b/server/src/main/resources/application.yml @@ -0,0 +1,66 @@ +# Defaults for a local run. Any key here can be overridden per environment without editing the file: +# pass --the.key.path=value as an argument, or set the upper-case underscored form of the path, such as +# OPENSHARING_ADMIN_BOOTSTRAP_TOKEN for opensharing.admin.bootstrap-token. +spring: + application: + name: opensharing-server + datasource: + # The driver is derived from the URL, so pointing this at Postgres or MySQL is the only change + # needed to move the metadata store there. + url: jdbc:h2:file:./data/opensharing;AUTO_SERVER=TRUE + username: sa + password: "" + jpa: + hibernate: + ddl-auto: update + open-in-view: false + jackson: + default-property-inclusion: non_null + mapper: + accept-case-insensitive-enums: true + serialization: + write-dates-as-timestamps: false + +server: + port: 8080 + error: + whitelabel: + enabled: false + +opensharing: + # Prefix the protocol-serving endpoints are mounted under; this is what goes in a profile file. + protocol-prefix: /open-sharing + admin: + base-path: /api/admin/v1 + # Registers the first principals and is accepted only on /principals. A random one is generated + # and logged at startup when this is blank. + bootstrap-token: "" + activation: + base-path: /activation + ttl: 72h + external-base-url: http://localhost:8080 + recipient-tokens: + default-ttl: 90d + rotation-grace: 24h + asset-credentials: + ttl: 1h + pagination: + default-max-results: 500 + max-max-results: 1000 + delta: + # Reading Delta logs to serve version/metadata/query, and signing per-file urls from the + # credentials the catalog minted. Turning this off leaves dir access mode alone. + url-access-enabled: true + url-ttl: 1h + s3-region: us-east-1 + catalog: + # 'local' reads every asset from a declarative file. It is the only connector this build ships. + type: local + local: + file: classpath:local-catalog.yml + +logging: + level: + io.opensharing: INFO + # Delta Kernel narrates every log segment it loads, which is a line per request. + io.delta: WARN From 585f5623fe82c0914effb38b2d86a4b3b086c3bb Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 13:30:40 -0700 Subject: [PATCH 05/42] Default protocol-prefix to /opensharing. --- server/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 7319c81da..e259be887 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -29,7 +29,7 @@ server: opensharing: # Prefix the protocol-serving endpoints are mounted under; this is what goes in a profile file. - protocol-prefix: /open-sharing + protocol-prefix: /opensharing admin: base-path: /api/admin/v1 # Registers the first principals and is accepted only on /principals. A random one is generated From 447a113cd766e288b5f316f017586ccaacfd4f1c Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 13:35:39 -0700 Subject: [PATCH 06/42] Keep application.yml limited to Spring and server defaults. OpenSharing feature keys arrive in later PRs as each area lands. --- server/src/main/resources/application.yml | 37 +---------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index e259be887..061840e5c 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -1,6 +1,5 @@ # Defaults for a local run. Any key here can be overridden per environment without editing the file: -# pass --the.key.path=value as an argument, or set the upper-case underscored form of the path, such as -# OPENSHARING_ADMIN_BOOTSTRAP_TOKEN for opensharing.admin.bootstrap-token. +# pass --the.key.path=value as an argument, or set the upper-case underscored form of the path. spring: application: name: opensharing-server @@ -27,40 +26,6 @@ server: whitelabel: enabled: false -opensharing: - # Prefix the protocol-serving endpoints are mounted under; this is what goes in a profile file. - protocol-prefix: /opensharing - admin: - base-path: /api/admin/v1 - # Registers the first principals and is accepted only on /principals. A random one is generated - # and logged at startup when this is blank. - bootstrap-token: "" - activation: - base-path: /activation - ttl: 72h - external-base-url: http://localhost:8080 - recipient-tokens: - default-ttl: 90d - rotation-grace: 24h - asset-credentials: - ttl: 1h - pagination: - default-max-results: 500 - max-max-results: 1000 - delta: - # Reading Delta logs to serve version/metadata/query, and signing per-file urls from the - # credentials the catalog minted. Turning this off leaves dir access mode alone. - url-access-enabled: true - url-ttl: 1h - s3-region: us-east-1 - catalog: - # 'local' reads every asset from a declarative file. It is the only connector this build ships. - type: local - local: - file: classpath:local-catalog.yml - logging: level: io.opensharing: INFO - # Delta Kernel narrates every log segment it loads, which is a line per request. - io.delta: WARN From d1b335cd9a2eef686d87065b8ac581f03c211515 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:42 -0700 Subject: [PATCH 07/42] Add Base Entity. --- .../main/java/io/opensharing/BaseEntity.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 server/src/main/java/io/opensharing/BaseEntity.java diff --git a/server/src/main/java/io/opensharing/BaseEntity.java b/server/src/main/java/io/opensharing/BaseEntity.java new file mode 100644 index 000000000..2a0aa417e --- /dev/null +++ b/server/src/main/java/io/opensharing/BaseEntity.java @@ -0,0 +1,55 @@ +package io.opensharing; + +import jakarta.persistence.Column; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import jakarta.persistence.PrePersist; +import jakarta.persistence.PreUpdate; +import java.time.Instant; +import java.util.UUID; + +/** Server-assigned identity and audit columns shared by every stored entity. */ +@MappedSuperclass +public abstract class BaseEntity { + + @Id + @Column(name = "id", length = 36, nullable = false, updatable = false) + private String id = UUID.randomUUID().toString(); + + @Column(name = "created_at", nullable = false, updatable = false) + private Instant createdAt; + + @Column(name = "updated_at", nullable = false) + private Instant updatedAt; + + @PrePersist + void onPersist() { + this.createdAt = Instant.now(); + this.updatedAt = this.createdAt; + } + + @PreUpdate + void onUpdate() { + this.updatedAt = Instant.now(); + } + + public String getId() { + return id; + } + + /** + * Adopts an id chosen elsewhere, for the entities whose identity is not the server's to invent. Only + * meaningful before the row is written: the column is not updatable. + */ + protected void setId(String id) { + this.id = id; + } + + public Instant getCreatedAt() { + return createdAt; + } + + public Instant getUpdatedAt() { + return updatedAt; + } +} From 2bc6fd14f10b69af840ee1711c990b0529569bf8 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:43 -0700 Subject: [PATCH 08/42] Add Object Names. --- .../main/java/io/opensharing/ObjectNames.java | 69 +++++++++++++++++++ .../java/io/opensharing/ObjectNamesTest.java | 44 ++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 server/src/main/java/io/opensharing/ObjectNames.java create mode 100644 server/src/test/java/io/opensharing/ObjectNamesTest.java diff --git a/server/src/main/java/io/opensharing/ObjectNames.java b/server/src/main/java/io/opensharing/ObjectNames.java new file mode 100644 index 000000000..e257dadf5 --- /dev/null +++ b/server/src/main/java/io/opensharing/ObjectNames.java @@ -0,0 +1,69 @@ +package io.opensharing; + +import java.util.Locale; + +/** + * Name rules from {@code spec/protocols/OVERVIEW.md}. Object names are compared case-insensitively, + * so callers persist {@link #normalize(String)} alongside the name as provided. + */ +public final class ObjectNames { + + public static final int MAX_LENGTH = 255; + + private ObjectNames() {} + + /** Validates a share name. */ + public static String validateShareName(String name) { + return validate(name, "share name", false); + } + + /** Validates a schema name, which additionally disallows {@code .}. */ + public static String validateSchemaName(String name) { + return validate(name, "schema name", true); + } + + /** Validates a shared asset name, which additionally disallows {@code .}. */ + public static String validateAssetName(String name) { + return validate(name, "asset name", true); + } + + /** Validates a recipient name using the same rules as a share name. */ + public static String validateRecipientName(String name) { + return validate(name, "recipient name", false); + } + + /** Validates a principal name, which is often an email address and so may contain periods. */ + public static String validatePrincipalName(String name) { + return validate(name, "principal name", false); + } + + /** Lower-cases a name for case-insensitive lookups and uniqueness checks. */ + public static String normalize(String name) { + return name == null ? null : name.toLowerCase(Locale.ROOT); + } + + private static String validate(String name, String what, boolean rejectPeriod) { + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException(what + " must not be empty"); + } + if (name.length() > MAX_LENGTH) { + throw new IllegalArgumentException(what + " must not exceed " + MAX_LENGTH + " characters"); + } + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + if (c == ' ') { + throw new IllegalArgumentException(what + " must not contain a space"); + } + if (c == '/') { + throw new IllegalArgumentException(what + " must not contain a forward slash"); + } + if (c <= 0x1F || c == 0x7F) { + throw new IllegalArgumentException(what + " must not contain control characters"); + } + if (rejectPeriod && c == '.') { + throw new IllegalArgumentException(what + " must not contain a period"); + } + } + return name; + } +} diff --git a/server/src/test/java/io/opensharing/ObjectNamesTest.java b/server/src/test/java/io/opensharing/ObjectNamesTest.java new file mode 100644 index 000000000..4e06b32dc --- /dev/null +++ b/server/src/test/java/io/opensharing/ObjectNamesTest.java @@ -0,0 +1,44 @@ +package io.opensharing; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class ObjectNamesTest { + + @Test + void acceptsOrdinaryNames() { + assertEquals("vaccine_share", ObjectNames.validateShareName("vaccine_share")); + assertEquals("acme-data", ObjectNames.validateSchemaName("acme-data")); + assertEquals("orders", ObjectNames.validateAssetName("orders")); + } + + @Test + void rejectsRestrictedCharacters() { + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateShareName("my share")); + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateShareName("a/b")); + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateShareName("a\u0001b")); + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateShareName("a\u007fb")); + } + + @Test + void rejectsPeriodOnlyForSchemasAndAssets() { + assertEquals("share.with.dots", ObjectNames.validateShareName("share.with.dots")); + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateSchemaName("a.b")); + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateAssetName("a.b")); + } + + @Test + void rejectsEmptyAndOverlongNames() { + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateShareName("")); + assertThrows(IllegalArgumentException.class, () -> ObjectNames.validateShareName(null)); + assertThrows( + IllegalArgumentException.class, () -> ObjectNames.validateShareName("x".repeat(256))); + } + + @Test + void normalizesForCaseInsensitiveComparison() { + assertEquals("vaccine_share", ObjectNames.normalize("Vaccine_Share")); + } +} From 99eceaf76c70b30de9c51bebe45c9cb650d55ac2 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:44 -0700 Subject: [PATCH 09/42] Add Error Codes. --- .../java/io/opensharing/http/ErrorCodes.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/ErrorCodes.java diff --git a/server/src/main/java/io/opensharing/http/ErrorCodes.java b/server/src/main/java/io/opensharing/http/ErrorCodes.java new file mode 100644 index 000000000..09614b1cd --- /dev/null +++ b/server/src/main/java/io/opensharing/http/ErrorCodes.java @@ -0,0 +1,18 @@ +package io.opensharing.http; + +/** Error codes used in {@link ErrorResponse#errorCode()}. */ +public final class ErrorCodes { + + public static final String MALFORMED_REQUEST = "MALFORMED_REQUEST"; + public static final String INVALID_PARAMETER_VALUE = "INVALID_PARAMETER_VALUE"; + public static final String UNAUTHENTICATED = "UNAUTHENTICATED"; + public static final String PERMISSION_DENIED = "PERMISSION_DENIED"; + public static final String RESOURCE_DOES_NOT_EXIST = "RESOURCE_DOES_NOT_EXIST"; + public static final String RESOURCE_ALREADY_EXISTS = "RESOURCE_ALREADY_EXISTS"; + public static final String RESOURCE_CONFLICT = "RESOURCE_CONFLICT"; + public static final String CATALOG_ERROR = "CATALOG_ERROR"; + public static final String NOT_IMPLEMENTED = "NOT_IMPLEMENTED"; + public static final String INTERNAL_ERROR = "INTERNAL_ERROR"; + + private ErrorCodes() {} +} From c9f364ccbbaaab66a9cf864e8b160408428641d6 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:45 -0700 Subject: [PATCH 10/42] Add Error Response. --- server/src/main/java/io/opensharing/http/ErrorResponse.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/ErrorResponse.java diff --git a/server/src/main/java/io/opensharing/http/ErrorResponse.java b/server/src/main/java/io/opensharing/http/ErrorResponse.java new file mode 100644 index 000000000..aea36ae13 --- /dev/null +++ b/server/src/main/java/io/opensharing/http/ErrorResponse.java @@ -0,0 +1,4 @@ +package io.opensharing.http; + +/** Error body returned by every non-2xx protocol response. */ +public record ErrorResponse(String errorCode, String message) {} From be3b7d6fb4dfa87fb946b685c3660651e8a1adb3 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:46 -0700 Subject: [PATCH 11/42] Add Api Exception. --- .../io/opensharing/http/ApiException.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/ApiException.java diff --git a/server/src/main/java/io/opensharing/http/ApiException.java b/server/src/main/java/io/opensharing/http/ApiException.java new file mode 100644 index 000000000..76ad725f6 --- /dev/null +++ b/server/src/main/java/io/opensharing/http/ApiException.java @@ -0,0 +1,54 @@ +package io.opensharing.http; + +import org.springframework.http.HttpStatus; + +/** An error with an explicit protocol error code and HTTP status. */ +public class ApiException extends RuntimeException { + + private final HttpStatus status; + private final String errorCode; + + public ApiException(HttpStatus status, String errorCode, String message) { + super(message); + this.status = status; + this.errorCode = errorCode; + } + + public HttpStatus getStatus() { + return status; + } + + public String getErrorCode() { + return errorCode; + } + + public static ApiException notFound(String message) { + return new ApiException(HttpStatus.NOT_FOUND, ErrorCodes.RESOURCE_DOES_NOT_EXIST, message); + } + + public static ApiException alreadyExists(String message) { + return new ApiException(HttpStatus.CONFLICT, ErrorCodes.RESOURCE_ALREADY_EXISTS, message); + } + + /** The object exists, but its current state does not allow what was asked. */ + public static ApiException conflict(String message) { + return new ApiException(HttpStatus.CONFLICT, ErrorCodes.RESOURCE_CONFLICT, message); + } + + public static ApiException invalidParameter(String message) { + return new ApiException(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, message); + } + + /** The caller is known, but is not allowed to do this. */ + public static ApiException permissionDenied(String message) { + return new ApiException(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, message); + } + + public static ApiException unauthenticated(String message) { + return new ApiException(HttpStatus.UNAUTHORIZED, ErrorCodes.UNAUTHENTICATED, message); + } + + public static ApiException notImplemented(String message) { + return new ApiException(HttpStatus.NOT_IMPLEMENTED, ErrorCodes.NOT_IMPLEMENTED, message); + } +} From 2798753d434cc2fb84b537cd06d56b82441f3912 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:47 -0700 Subject: [PATCH 12/42] Add Admin Json. --- .../java/io/opensharing/http/AdminJson.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/AdminJson.java diff --git a/server/src/main/java/io/opensharing/http/AdminJson.java b/server/src/main/java/io/opensharing/http/AdminJson.java new file mode 100644 index 000000000..1d121f8ae --- /dev/null +++ b/server/src/main/java/io/opensharing/http/AdminJson.java @@ -0,0 +1,19 @@ +package io.opensharing.http; + +import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a provider-admin request or response body. The admin API speaks snake_case, unlike the + * recipient-facing protocol, which is camelCase and must stay that way for Delta Sharing clients. + */ +@JacksonAnnotationsInside +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface AdminJson {} From 8e5eab0b9f7996f8e357af471823e29fc21f11b7 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:47 -0700 Subject: [PATCH 13/42] Add Protocol Media Type. --- .../main/java/io/opensharing/http/ProtocolMediaType.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/ProtocolMediaType.java diff --git a/server/src/main/java/io/opensharing/http/ProtocolMediaType.java b/server/src/main/java/io/opensharing/http/ProtocolMediaType.java new file mode 100644 index 000000000..358f76321 --- /dev/null +++ b/server/src/main/java/io/opensharing/http/ProtocolMediaType.java @@ -0,0 +1,9 @@ +package io.opensharing.http; + +/** Content type the spec requires on successful protocol responses. */ +public final class ProtocolMediaType { + + public static final String JSON_UTF8 = "application/json;charset=utf-8"; + + private ProtocolMediaType() {} +} From 739648179a4881f980986c079a0c038f72fafdf0 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:48 -0700 Subject: [PATCH 14/42] Add List Response. --- .../main/java/io/opensharing/http/ListResponse.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/ListResponse.java diff --git a/server/src/main/java/io/opensharing/http/ListResponse.java b/server/src/main/java/io/opensharing/http/ListResponse.java new file mode 100644 index 000000000..0fdd9cd41 --- /dev/null +++ b/server/src/main/java/io/opensharing/http/ListResponse.java @@ -0,0 +1,13 @@ +package io.opensharing.http; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.List; + +/** Paginated list envelope shared by every {@code list} endpoint. */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record ListResponse(List items, String nextPageToken) { + + public static ListResponse of(List items, String nextPageToken) { + return new ListResponse<>(items, nextPageToken); + } +} From 01d54218a7e84a4da00213ca2ffd4d157d58420c Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:49 -0700 Subject: [PATCH 15/42] Add Offset Pageable. --- .../io/opensharing/http/OffsetPageable.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/OffsetPageable.java diff --git a/server/src/main/java/io/opensharing/http/OffsetPageable.java b/server/src/main/java/io/opensharing/http/OffsetPageable.java new file mode 100644 index 000000000..b92b0f1ca --- /dev/null +++ b/server/src/main/java/io/opensharing/http/OffsetPageable.java @@ -0,0 +1,70 @@ +package io.opensharing.http; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; + +/** + * A {@link Pageable} addressed by absolute offset. Protocol page tokens carry an offset rather than + * a page number, so a client is free to change {@code maxResults} between requests. + */ +public final class OffsetPageable implements Pageable { + + private final int offset; + private final int limit; + + public OffsetPageable(int offset, int limit) { + if (offset < 0) { + throw new IllegalArgumentException("offset must not be negative"); + } + if (limit < 1) { + throw new IllegalArgumentException("limit must be positive"); + } + this.offset = offset; + this.limit = limit; + } + + @Override + public int getPageNumber() { + return offset / limit; + } + + @Override + public int getPageSize() { + return limit; + } + + @Override + public long getOffset() { + return offset; + } + + @Override + public Sort getSort() { + return Sort.unsorted(); + } + + @Override + public Pageable next() { + return new OffsetPageable(offset + limit, limit); + } + + @Override + public Pageable previousOrFirst() { + return hasPrevious() ? new OffsetPageable(Math.max(0, offset - limit), limit) : first(); + } + + @Override + public Pageable first() { + return new OffsetPageable(0, limit); + } + + @Override + public Pageable withPage(int pageNumber) { + return new OffsetPageable(pageNumber * limit, limit); + } + + @Override + public boolean hasPrevious() { + return offset > 0; + } +} From 9ec42835cce8600d1339870268b9903f26f8d54f Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:50 -0700 Subject: [PATCH 16/42] Add Offset Page. --- .../java/io/opensharing/http/OffsetPage.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/OffsetPage.java diff --git a/server/src/main/java/io/opensharing/http/OffsetPage.java b/server/src/main/java/io/opensharing/http/OffsetPage.java new file mode 100644 index 000000000..c616e60c4 --- /dev/null +++ b/server/src/main/java/io/opensharing/http/OffsetPage.java @@ -0,0 +1,37 @@ +package io.opensharing.http; + +import java.util.List; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.PageImpl; + +/** + * A page cut from a list already in memory, addressed by the absolute offset {@link OffsetPageable} + * carries. + * + *

{@link PageImpl} decides whether anything remains by page number, which is only right when every + * offset is a multiple of the page size. A client may change {@code maxResults} between requests, so + * offsets here are arbitrary and the question is answered by counting instead — otherwise a client + * that reduced its page size would be handed a token to a page that does not exist. + */ +public final class OffsetPage extends PageImpl { + + private final long offset; + private final long total; + + public static OffsetPage of(List all, Pageable pageable) { + int from = (int) Math.min(pageable.getOffset(), all.size()); + int to = (int) Math.min((long) from + pageable.getPageSize(), all.size()); + return new OffsetPage<>(all.subList(from, to), pageable, all.size()); + } + + private OffsetPage(List content, Pageable pageable, long total) { + super(content, pageable, total); + this.offset = pageable.getOffset(); + this.total = total; + } + + @Override + public boolean hasNext() { + return offset + getNumberOfElements() < total; + } +} From 02b5c495d24cea2c0a0fb5e99dcd49a0f8d66a03 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:51 -0700 Subject: [PATCH 17/42] Add Page Tokens. --- .../java/io/opensharing/http/PageTokens.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 server/src/main/java/io/opensharing/http/PageTokens.java diff --git a/server/src/main/java/io/opensharing/http/PageTokens.java b/server/src/main/java/io/opensharing/http/PageTokens.java new file mode 100644 index 000000000..226a109aa --- /dev/null +++ b/server/src/main/java/io/opensharing/http/PageTokens.java @@ -0,0 +1,52 @@ +package io.opensharing.http; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import org.springframework.data.domain.Page; + +/** + * Opaque page tokens. The encoding is an implementation detail clients must not depend on, so the + * offset is wrapped in a versioned, base64url-encoded envelope. + */ +public final class PageTokens { + + private static final String PREFIX = "os1:"; + + private PageTokens() {} + + /** Returns the offset a client asked to resume from, or 0 when no token was supplied. */ + public static int offsetOf(String pageToken) { + if (pageToken == null || pageToken.isBlank()) { + return 0; + } + try { + String decoded = + new String( + Base64.getUrlDecoder().decode(pageToken.trim()), StandardCharsets.UTF_8); + if (!decoded.startsWith(PREFIX)) { + throw new IllegalArgumentException("unexpected token envelope"); + } + int offset = Integer.parseInt(decoded.substring(PREFIX.length())); + if (offset < 0) { + throw new IllegalArgumentException("negative offset"); + } + return offset; + } catch (IllegalArgumentException e) { + throw ApiException.invalidParameter("pageToken is not a valid page token"); + } + } + + /** Returns the token for the page after {@code page}, or null when the results are exhausted. */ + public static String nextToken(Page page, int offset) { + if (!page.hasNext()) { + return null; + } + return encode(offset + page.getNumberOfElements()); + } + + public static String encode(int offset) { + return Base64.getUrlEncoder() + .withoutPadding() + .encodeToString((PREFIX + offset).getBytes(StandardCharsets.UTF_8)); + } +} From d8c63f84a0cdd490ef0292e8bdda9807565a174b Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:52 -0700 Subject: [PATCH 18/42] Add Protocol Action. --- .../main/java/io/opensharing/protocol/ProtocolAction.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/ProtocolAction.java diff --git a/server/src/main/java/io/opensharing/protocol/ProtocolAction.java b/server/src/main/java/io/opensharing/protocol/ProtocolAction.java new file mode 100644 index 000000000..507628639 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/ProtocolAction.java @@ -0,0 +1,7 @@ +package io.opensharing.protocol; + +/** + * The reader version a client needs to interpret the response, so a client too old for a table is + * told rather than left to misread it. + */ +public record ProtocolAction(int minReaderVersion) {} From 43a7d17c02466d8515b4f3ae30e87f5e9f38b865 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:53 -0700 Subject: [PATCH 19/42] Add Metadata Action. --- .../opensharing/protocol/MetadataAction.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/MetadataAction.java diff --git a/server/src/main/java/io/opensharing/protocol/MetadataAction.java b/server/src/main/java/io/opensharing/protocol/MetadataAction.java new file mode 100644 index 000000000..fe3408c7e --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/MetadataAction.java @@ -0,0 +1,32 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.List; +import java.util.Map; + +/** + * A table's metadata as a Delta read response reports it. + * + * @param schemaString the schema as a JSON string, which the client deserializes itself + * @param location the table root, which must be present for a table offering {@code dir} access + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record MetadataAction( + String id, + String name, + String description, + String location, + List auxiliaryLocations, + List accessModes, + Format format, + String schemaString, + List partitionColumns, + Map configuration, + Long version, + Long size, + Long numFiles) { + + /** The encoding of the table's data files. */ + @JsonInclude(JsonInclude.Include.NON_NULL) + public record Format(String provider, Map options) {} +} From f33a2afc63f241e049d1b81271f1bd0ac99b3ddd Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:54 -0700 Subject: [PATCH 20/42] Add File Action. --- .../io/opensharing/protocol/FileAction.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/FileAction.java diff --git a/server/src/main/java/io/opensharing/protocol/FileAction.java b/server/src/main/java/io/opensharing/protocol/FileAction.java new file mode 100644 index 000000000..91871d27a --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/FileAction.java @@ -0,0 +1,22 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.Map; + +/** + * One data file, with a url the recipient reads directly. + * + * @param id stable for a given file across responses, so a client can cache the bytes against it + * @param stats the log's statistics JSON, passed through, which a client may use or ignore + * @param expirationTimestamp when the url stops working, in epoch milliseconds + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record FileAction( + String url, + String id, + Map partitionValues, + long size, + String stats, + Long version, + Long timestamp, + Long expirationTimestamp) {} From 83c844b6576d3f6ceaf2ec178cb492091c0d1a89 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:55 -0700 Subject: [PATCH 21/42] Add Change File Action. --- .../protocol/ChangeFileAction.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/ChangeFileAction.java diff --git a/server/src/main/java/io/opensharing/protocol/ChangeFileAction.java b/server/src/main/java/io/opensharing/protocol/ChangeFileAction.java new file mode 100644 index 000000000..995f99e80 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/ChangeFileAction.java @@ -0,0 +1,23 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.Map; + +/** + * One file of a change data feed, sent as an {@code add}, {@code cdf} or {@code remove} line + * depending on what it records. The three shapes are identical but for statistics, which only an + * added file carries. + * + * @param version the table version this change belongs to, which a streaming reader tracks + * @param timestamp the commit's timestamp, in epoch milliseconds + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record ChangeFileAction( + String url, + String id, + Map partitionValues, + long size, + long timestamp, + long version, + String stats, + Long expirationTimestamp) {} From d41b97fd50e52956219869a82ad4f8716a15ee34 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:56 -0700 Subject: [PATCH 22/42] Add End Stream Action. --- .../io/opensharing/protocol/EndStreamAction.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/EndStreamAction.java diff --git a/server/src/main/java/io/opensharing/protocol/EndStreamAction.java b/server/src/main/java/io/opensharing/protocol/EndStreamAction.java new file mode 100644 index 000000000..790051155 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/EndStreamAction.java @@ -0,0 +1,14 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * Closes a Delta read response, so a client can tell a complete stream from a truncated one. Sent + * only when the client asks for it through the {@code delta-sharing-capabilities} header. + * + * @param minUrlExpirationTimestamp the earliest expiry among the urls in this response, which tells + * a client when it must ask again + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record EndStreamAction( + String refreshToken, String nextPageToken, Long minUrlExpirationTimestamp) {} From c229c4d67944dc4a792dec59a6228733b98007fe Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:57 -0700 Subject: [PATCH 23/42] Add Table Action. --- .../io/opensharing/protocol/TableAction.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/TableAction.java diff --git a/server/src/main/java/io/opensharing/protocol/TableAction.java b/server/src/main/java/io/opensharing/protocol/TableAction.java new file mode 100644 index 000000000..62647efbe --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/TableAction.java @@ -0,0 +1,46 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * One line of a Delta read response. The protocol sends newline-delimited JSON where each line is + * this wrapper carrying exactly one action, so the factories are the only way to build one. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record TableAction( + ProtocolAction protocol, + MetadataAction metaData, + FileAction file, + ChangeFileAction add, + ChangeFileAction cdf, + ChangeFileAction remove, + EndStreamAction endStreamAction) { + + public static TableAction of(ProtocolAction protocol) { + return new TableAction(protocol, null, null, null, null, null, null); + } + + public static TableAction of(MetadataAction metadata) { + return new TableAction(null, metadata, null, null, null, null, null); + } + + public static TableAction of(FileAction file) { + return new TableAction(null, null, file, null, null, null, null); + } + + public static TableAction added(ChangeFileAction change) { + return new TableAction(null, null, null, change, null, null, null); + } + + public static TableAction changed(ChangeFileAction change) { + return new TableAction(null, null, null, null, change, null, null); + } + + public static TableAction removed(ChangeFileAction change) { + return new TableAction(null, null, null, null, null, change, null); + } + + public static TableAction of(EndStreamAction endStream) { + return new TableAction(null, null, null, null, null, null, endStream); + } +} From 1cdc09282bac8cceae6927d4172ecf6abdb0998e Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:58 -0700 Subject: [PATCH 24/42] Add Aws Credentials. --- .../src/main/java/io/opensharing/protocol/AwsCredentials.java | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/AwsCredentials.java diff --git a/server/src/main/java/io/opensharing/protocol/AwsCredentials.java b/server/src/main/java/io/opensharing/protocol/AwsCredentials.java new file mode 100644 index 000000000..b3fe84872 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/AwsCredentials.java @@ -0,0 +1,3 @@ +package io.opensharing.protocol; + +public record AwsCredentials(String accessKeyId, String secretAccessKey, String sessionToken) {} From 67ca73fa6ceec6211651ae70cd7c67e8c05512e0 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:01:59 -0700 Subject: [PATCH 25/42] Add Azure User Delegation Sas. --- .../java/io/opensharing/protocol/AzureUserDelegationSas.java | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/AzureUserDelegationSas.java diff --git a/server/src/main/java/io/opensharing/protocol/AzureUserDelegationSas.java b/server/src/main/java/io/opensharing/protocol/AzureUserDelegationSas.java new file mode 100644 index 000000000..b19a7808b --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/AzureUserDelegationSas.java @@ -0,0 +1,3 @@ +package io.opensharing.protocol; + +public record AzureUserDelegationSas(String sasToken) {} From 8c9c63b0009fc3250e21ef08f9c0db41bfd2d0af Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:00 -0700 Subject: [PATCH 26/42] Add Gcp Oauth Token. --- .../src/main/java/io/opensharing/protocol/GcpOauthToken.java | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/GcpOauthToken.java diff --git a/server/src/main/java/io/opensharing/protocol/GcpOauthToken.java b/server/src/main/java/io/opensharing/protocol/GcpOauthToken.java new file mode 100644 index 000000000..12bc7545d --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/GcpOauthToken.java @@ -0,0 +1,3 @@ +package io.opensharing.protocol; + +public record GcpOauthToken(String oauthToken) {} From f9dd60f1f88c56c869f9810fbc466c16bb880300 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:01 -0700 Subject: [PATCH 27/42] Add R2 Credentials. --- .../src/main/java/io/opensharing/protocol/R2Credentials.java | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/R2Credentials.java diff --git a/server/src/main/java/io/opensharing/protocol/R2Credentials.java b/server/src/main/java/io/opensharing/protocol/R2Credentials.java new file mode 100644 index 000000000..b34a4b6a5 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/R2Credentials.java @@ -0,0 +1,3 @@ +package io.opensharing.protocol; + +public record R2Credentials(String accessKeyId, String secretAccessKey, String sessionToken) {} From 5685e8fc3be5445ab7601e4ea6274b349b5f5f1a Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:02 -0700 Subject: [PATCH 28/42] Add Get Share Response. --- .../main/java/io/opensharing/protocol/GetShareResponse.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/GetShareResponse.java diff --git a/server/src/main/java/io/opensharing/protocol/GetShareResponse.java b/server/src/main/java/io/opensharing/protocol/GetShareResponse.java new file mode 100644 index 000000000..c359f38df --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/GetShareResponse.java @@ -0,0 +1,4 @@ +package io.opensharing.protocol; + +/** {@code GET /shares/{share}} wraps the share in a single-field object. */ +public record GetShareResponse(Share share) {} From e4e5d35eaa832ecddd15c7666cf2ce49b3924706 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:02 -0700 Subject: [PATCH 29/42] Add Schema. --- server/src/main/java/io/opensharing/protocol/Schema.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/Schema.java diff --git a/server/src/main/java/io/opensharing/protocol/Schema.java b/server/src/main/java/io/opensharing/protocol/Schema.java new file mode 100644 index 000000000..dc8c5b0f4 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/Schema.java @@ -0,0 +1,4 @@ +package io.opensharing.protocol; + +/** A schema inside a share. Schemas are derived from the assets shared under them. */ +public record Schema(String name, String share) {} From 7e56baeb0054caa7fe15ed485bf00d0a9aba686d Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:03 -0700 Subject: [PATCH 30/42] Add Share. --- server/src/main/java/io/opensharing/protocol/Share.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/Share.java diff --git a/server/src/main/java/io/opensharing/protocol/Share.java b/server/src/main/java/io/opensharing/protocol/Share.java new file mode 100644 index 000000000..ddc9aff37 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/Share.java @@ -0,0 +1,9 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.Map; + +/** A share as returned by {@code GET /shares} and {@code GET /shares/{share}}. */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Share( + String name, String id, String displayName, String comment, Map properties) {} From 774b7c9a6231d71419bcb19d833286a888afe1a8 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:04 -0700 Subject: [PATCH 31/42] Add Table. --- .../java/io/opensharing/protocol/Table.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/Table.java diff --git a/server/src/main/java/io/opensharing/protocol/Table.java b/server/src/main/java/io/opensharing/protocol/Table.java new file mode 100644 index 000000000..db20226be --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/Table.java @@ -0,0 +1,22 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.List; + +/** + * A shared table, as {@code spec/protocols/TABLES.md} and the Delta Sharing protocol define it. + * + *

{@code location} is where the table's log and data live, and must be present whenever + * {@code accessModes} includes {@code dir}, since that is all a directory-access client is given to + * work from. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Table( + String name, + String schema, + String share, + String shareId, + String id, + String location, + List auxiliaryLocations, + List accessModes) {} From 5697917808321b4bbed4015aaf73d52cd4f78d93 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:05 -0700 Subject: [PATCH 32/42] Add Profile File. --- .../io/opensharing/protocol/ProfileFile.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/ProfileFile.java diff --git a/server/src/main/java/io/opensharing/protocol/ProfileFile.java b/server/src/main/java/io/opensharing/protocol/ProfileFile.java new file mode 100644 index 000000000..fc5f33414 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/ProfileFile.java @@ -0,0 +1,19 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * The {@code config.share} profile file a recipient downloads from an activation URL. + * + * @param expirationTime ISO-8601 instant, or null when the token never expires + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record ProfileFile( + int shareCredentialsVersion, + String endpoint, + String icebergEndpoint, + String bearerToken, + String expirationTime) { + + public static final int CURRENT_VERSION = 1; +} From 6490e139700772e1b657ed316f1a239f70fed484 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:06 -0700 Subject: [PATCH 33/42] Add Iceberg Config. --- .../io/opensharing/protocol/IcebergConfig.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/IcebergConfig.java diff --git a/server/src/main/java/io/opensharing/protocol/IcebergConfig.java b/server/src/main/java/io/opensharing/protocol/IcebergConfig.java new file mode 100644 index 000000000..3409bcde6 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/IcebergConfig.java @@ -0,0 +1,14 @@ +package io.opensharing.protocol; + +import java.util.List; +import java.util.Map; + +/** + * Response of the Iceberg REST catalog {@code GET /v1/config} handshake. + * + * @param overrides carries {@code prefix}, the path prefix the client must use for every later call, + * which is how a share is selected + * @param endpoints the catalog operations this server implements + */ +public record IcebergConfig( + Map defaults, Map overrides, List endpoints) {} From be80a4614fba3b906b987aba2b5bf5124f02556f Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:07 -0700 Subject: [PATCH 34/42] Add Query Table Request. --- .../protocol/QueryTableRequest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/QueryTableRequest.java diff --git a/server/src/main/java/io/opensharing/protocol/QueryTableRequest.java b/server/src/main/java/io/opensharing/protocol/QueryTableRequest.java new file mode 100644 index 000000000..9d6b1ccee --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/QueryTableRequest.java @@ -0,0 +1,31 @@ +package io.opensharing.protocol; + +import java.util.List; + +/** + * The body of a table query. Every field is optional, and an empty object asks for the whole latest + * snapshot. + * + *

The hints are what their name says: a server may narrow the files it returns by them, and a + * client must apply its own filter to the response regardless. This server does not narrow, so it + * accepts them and returns every file of the version asked for. + * + * @param version a version to read instead of the latest + * @param timestamp the state at a moment, as an ISO-8601 instant, exclusive with {@code version} + * @param startingVersion asks for data change files since that version rather than a snapshot + */ +public record QueryTableRequest( + List predicateHints, + String jsonPredicateHints, + Integer limitHint, + Long version, + String timestamp, + Long startingVersion, + Long endingVersion, + Boolean includeHistoricalProtocol, + String idempotencyKey) { + + public static QueryTableRequest snapshot() { + return new QueryTableRequest(null, null, null, null, null, null, null, null, null); + } +} From fa95dc1979ab6bea8cdf8d87b4a4ba48a50604c6 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:08 -0700 Subject: [PATCH 35/42] Add Temporary Credentials. --- .../protocol/TemporaryCredentials.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/TemporaryCredentials.java diff --git a/server/src/main/java/io/opensharing/protocol/TemporaryCredentials.java b/server/src/main/java/io/opensharing/protocol/TemporaryCredentials.java new file mode 100644 index 000000000..816352730 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/TemporaryCredentials.java @@ -0,0 +1,32 @@ +package io.opensharing.protocol; + +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * Response of the {@code temporary-table-credentials} endpoint. Exactly one of the cloud-specific + * fields is populated; {@code expirationTime} is epoch milliseconds. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public record TemporaryCredentials( + AwsCredentials awsTempCredentials, + AzureUserDelegationSas azureUserDelegationSas, + GcpOauthToken gcpOauthToken, + R2Credentials r2Credentials, + long expirationTime) { + + public static TemporaryCredentials aws(AwsCredentials credentials, long expirationTime) { + return new TemporaryCredentials(credentials, null, null, null, expirationTime); + } + + public static TemporaryCredentials azure(AzureUserDelegationSas sas, long expirationTime) { + return new TemporaryCredentials(null, sas, null, null, expirationTime); + } + + public static TemporaryCredentials gcp(GcpOauthToken token, long expirationTime) { + return new TemporaryCredentials(null, null, token, null, expirationTime); + } + + public static TemporaryCredentials r2(R2Credentials credentials, long expirationTime) { + return new TemporaryCredentials(null, null, null, credentials, expirationTime); + } +} From 4208709684bf1c69284d8ba5e4ff4b1fa4c09f6a Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 14:02:09 -0700 Subject: [PATCH 36/42] Add Temporary Credentials Request. --- .../protocol/TemporaryCredentialsRequest.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 server/src/main/java/io/opensharing/protocol/TemporaryCredentialsRequest.java diff --git a/server/src/main/java/io/opensharing/protocol/TemporaryCredentialsRequest.java b/server/src/main/java/io/opensharing/protocol/TemporaryCredentialsRequest.java new file mode 100644 index 000000000..d8b6d6188 --- /dev/null +++ b/server/src/main/java/io/opensharing/protocol/TemporaryCredentialsRequest.java @@ -0,0 +1,9 @@ +package io.opensharing.protocol; + +/** + * Optional body of a {@code temporary-table-credentials} request. + * + * @param location for tables with auxiliary locations, which one to scope credentials to; the + * table's root location is used when omitted + */ +public record TemporaryCredentialsRequest(String location) {} From 642209f3b462d05f0bd7f69ebf131d850543da8c Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 13:36:10 -0700 Subject: [PATCH 37/42] Add global error handling for protocol failures. Catalog exception types and GlobalExceptionHandler only; OpenSharing configuration properties arrive with the features that need them. --- .../catalog/AssetAccessDeniedException.java | 18 +++ .../io/opensharing/catalog/AssetLookup.java | 22 ++++ .../catalog/AssetNotFoundException.java | 9 ++ .../io/opensharing/catalog/AssetType.java | 16 +++ .../CatalogAuthenticationException.java | 13 ++ .../io/opensharing/catalog/CatalogCaller.java | 27 ++++ .../opensharing/catalog/CatalogException.java | 13 ++ .../UnsupportedAssetTypeException.java | 9 ++ .../http/GlobalExceptionHandler.java | 117 ++++++++++++++++++ 9 files changed, 244 insertions(+) create mode 100644 server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java create mode 100644 server/src/main/java/io/opensharing/catalog/AssetLookup.java create mode 100644 server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java create mode 100644 server/src/main/java/io/opensharing/catalog/AssetType.java create mode 100644 server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java create mode 100644 server/src/main/java/io/opensharing/catalog/CatalogCaller.java create mode 100644 server/src/main/java/io/opensharing/catalog/CatalogException.java create mode 100644 server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java create mode 100644 server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java diff --git a/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java b/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java new file mode 100644 index 000000000..fdb990c13 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java @@ -0,0 +1,18 @@ +package io.opensharing.catalog; + +/** + * The catalog knows the asset but will not let this caller share it. Distinct from {@link + * CatalogAuthenticationException}, which is the sharing server's own credentials being rejected. + */ +public class AssetAccessDeniedException extends CatalogException { + + public AssetAccessDeniedException(AssetLookup lookup, CatalogCaller caller) { + super( + (caller.isServer() ? "the sharing server" : "'" + caller.name() + "'") + + " may not share " + + lookup.type() + + " '" + + lookup.identifier() + + "'"); + } +} diff --git a/server/src/main/java/io/opensharing/catalog/AssetLookup.java b/server/src/main/java/io/opensharing/catalog/AssetLookup.java new file mode 100644 index 000000000..c9908f0be --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/AssetLookup.java @@ -0,0 +1,22 @@ +package io.opensharing.catalog; + +import java.util.Objects; + +/** + * Identifies an asset in the catalog's own namespace, independent of how it is named in a share. + * + * @param identifier catalog-native identifier, e.g. a three-level {@code main.sales.orders} + */ +public record AssetLookup(AssetType type, String identifier) { + + public AssetLookup { + Objects.requireNonNull(type, "type"); + if (identifier == null || identifier.isBlank()) { + throw new IllegalArgumentException("catalog identifier must not be blank"); + } + } + + public static AssetLookup of(AssetType type, String identifier) { + return new AssetLookup(type, identifier); + } +} diff --git a/server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java b/server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java new file mode 100644 index 000000000..883c7f3f1 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java @@ -0,0 +1,9 @@ +package io.opensharing.catalog; + +/** The catalog has no asset with the requested identifier and type. */ +public class AssetNotFoundException extends CatalogException { + + public AssetNotFoundException(AssetLookup lookup) { + super(lookup.type() + " '" + lookup.identifier() + "' does not exist in the catalog"); + } +} diff --git a/server/src/main/java/io/opensharing/catalog/AssetType.java b/server/src/main/java/io/opensharing/catalog/AssetType.java new file mode 100644 index 000000000..421692ed7 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/AssetType.java @@ -0,0 +1,16 @@ +package io.opensharing.catalog; + +/** + * Asset types a share can hold. {@link #TABLE} and {@link #SCHEMA} are accepted; the rest are here + * because they are part of the model and are rejected explicitly rather than silently absent. + * + *

{@link #SCHEMA} is the odd one, in that sharing it shares nothing directly: it stands for the + * tables the catalog holds in it, which is why it needs a catalog that can be asked what those are. + */ +public enum AssetType { + TABLE, + VOLUME, + MODEL, + SKILL, + SCHEMA +} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java b/server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java new file mode 100644 index 000000000..6c2833bd4 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java @@ -0,0 +1,13 @@ +package io.opensharing.catalog; + +/** The sharing server's own service-principal credentials were rejected by the catalog. */ +public class CatalogAuthenticationException extends CatalogException { + + public CatalogAuthenticationException(String message) { + super(message); + } + + public CatalogAuthenticationException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogCaller.java b/server/src/main/java/io/opensharing/catalog/CatalogCaller.java new file mode 100644 index 000000000..cc591f061 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/CatalogCaller.java @@ -0,0 +1,27 @@ +package io.opensharing.catalog; + +/** + * Who a catalog request is made on behalf of. + * + *

A provider admin adding an object to a share is resolved as themselves, so the catalog decides + * whether that person may share it. Requests with no user behind them — a recipient reading a table + * long after it was shared — use {@link #server()}, because the server keeps only a hash of a + * principal's token and cannot replay it later. + */ +public record CatalogCaller(String name, String bearerToken) { + + private static final CatalogCaller SERVER = new CatalogCaller(null, null); + + public static CatalogCaller of(String name, String bearerToken) { + return new CatalogCaller(name, bearerToken); + } + + /** The sharing server's own catalog identity. */ + public static CatalogCaller server() { + return SERVER; + } + + public boolean isServer() { + return name == null; + } +} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogException.java b/server/src/main/java/io/opensharing/catalog/CatalogException.java new file mode 100644 index 000000000..0cd5d6915 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/CatalogException.java @@ -0,0 +1,13 @@ +package io.opensharing.catalog; + +/** Raised when the catalog cannot satisfy a request. */ +public class CatalogException extends RuntimeException { + + public CatalogException(String message) { + super(message); + } + + public CatalogException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java b/server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java new file mode 100644 index 000000000..fac436a15 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java @@ -0,0 +1,9 @@ +package io.opensharing.catalog; + +/** The connector cannot handle the requested asset type or operation. */ +public class UnsupportedAssetTypeException extends CatalogException { + + public UnsupportedAssetTypeException(String message) { + super(message); + } +} diff --git a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java new file mode 100644 index 000000000..b6920f7c0 --- /dev/null +++ b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java @@ -0,0 +1,117 @@ +package io.opensharing.http; + +import io.opensharing.catalog.AssetAccessDeniedException; +import io.opensharing.catalog.AssetNotFoundException; +import io.opensharing.catalog.CatalogAuthenticationException; +import io.opensharing.catalog.CatalogException; +import io.opensharing.catalog.UnsupportedAssetTypeException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.HandlerMethodValidationException; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; +import org.springframework.web.servlet.resource.NoResourceFoundException; + +/** Renders every failure as the protocol's {@code {errorCode, message}} body. */ +@RestControllerAdvice +public class GlobalExceptionHandler { + + private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); + + @ExceptionHandler(ApiException.class) + public ResponseEntity handleApi(ApiException e) { + return body(e.getStatus(), e.getErrorCode(), e.getMessage()); + } + + @ExceptionHandler(AssetNotFoundException.class) + public ResponseEntity handleAssetNotFound(AssetNotFoundException e) { + return body(HttpStatus.NOT_FOUND, ErrorCodes.RESOURCE_DOES_NOT_EXIST, e.getMessage()); + } + + @ExceptionHandler(AssetAccessDeniedException.class) + public ResponseEntity handleAssetAccessDenied(AssetAccessDeniedException e) { + return body(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, e.getMessage()); + } + + @ExceptionHandler(UnsupportedAssetTypeException.class) + public ResponseEntity handleUnsupportedAsset(UnsupportedAssetTypeException e) { + return body(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, e.getMessage()); + } + + @ExceptionHandler(CatalogAuthenticationException.class) + public ResponseEntity handleCatalogAuth(CatalogAuthenticationException e) { + log.error("The sharing server could not authenticate to the catalog", e); + return body( + HttpStatus.BAD_GATEWAY, + ErrorCodes.CATALOG_ERROR, + "the sharing server could not authenticate to the catalog"); + } + + @ExceptionHandler(CatalogException.class) + public ResponseEntity handleCatalog(CatalogException e) { + log.error("Catalog request failed", e); + return body(HttpStatus.BAD_GATEWAY, ErrorCodes.CATALOG_ERROR, e.getMessage()); + } + + @ExceptionHandler(IllegalArgumentException.class) + public ResponseEntity handleIllegalArgument(IllegalArgumentException e) { + return body(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, e.getMessage()); + } + + @ExceptionHandler({ + MethodArgumentNotValidException.class, + HandlerMethodValidationException.class, + MethodArgumentTypeMismatchException.class + }) + public ResponseEntity handleValidation(Exception e) { + return body(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, describeValidation(e)); + } + + @ExceptionHandler(HttpMessageNotReadableException.class) + public ResponseEntity handleUnreadable(HttpMessageNotReadableException e) { + return body(HttpStatus.BAD_REQUEST, ErrorCodes.MALFORMED_REQUEST, "request body is malformed"); + } + + @ExceptionHandler(DataIntegrityViolationException.class) + public ResponseEntity handleConflict(DataIntegrityViolationException e) { + log.debug("Rejected request that violated a uniqueness constraint", e); + return body( + HttpStatus.CONFLICT, + ErrorCodes.RESOURCE_ALREADY_EXISTS, + "the object already exists or conflicts with an existing object"); + } + + @ExceptionHandler(NoResourceFoundException.class) + public ResponseEntity handleNoResource(NoResourceFoundException e) { + return body( + HttpStatus.NOT_FOUND, ErrorCodes.RESOURCE_DOES_NOT_EXIST, "the endpoint does not exist"); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity handleUnexpected(Exception e) { + log.error("Unhandled server error", e); + return body( + HttpStatus.INTERNAL_SERVER_ERROR, ErrorCodes.INTERNAL_ERROR, "internal server error"); + } + + private static String describeValidation(Exception e) { + if (e instanceof MethodArgumentNotValidException invalid) { + return invalid.getBindingResult().getFieldErrors().stream() + .findFirst() + .map(error -> error.getField() + " " + error.getDefaultMessage()) + .orElse("request validation failed"); + } + return "request validation failed"; + } + + private static ResponseEntity body( + HttpStatus status, String errorCode, String message) { + return ResponseEntity.status(status).body(new ErrorResponse(errorCode, message)); + } +} From 52bcd9a46337904ffc933b0c4e32a6fd667bfae1 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 15:03:23 -0700 Subject: [PATCH 38/42] Require a named principal on every CatalogCaller. Drop the server() sentinel and isServer(); access-denied messages always name the caller. --- .../catalog/AssetAccessDeniedException.java | 5 +++-- .../io/opensharing/catalog/CatalogCaller.java | 15 +-------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java b/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java index fdb990c13..7b5fadb86 100644 --- a/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java +++ b/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java @@ -8,8 +8,9 @@ public class AssetAccessDeniedException extends CatalogException { public AssetAccessDeniedException(AssetLookup lookup, CatalogCaller caller) { super( - (caller.isServer() ? "the sharing server" : "'" + caller.name() + "'") - + " may not share " + "'" + + caller.name() + + "' may not share " + lookup.type() + " '" + lookup.identifier() diff --git a/server/src/main/java/io/opensharing/catalog/CatalogCaller.java b/server/src/main/java/io/opensharing/catalog/CatalogCaller.java index cc591f061..7f1bae75a 100644 --- a/server/src/main/java/io/opensharing/catalog/CatalogCaller.java +++ b/server/src/main/java/io/opensharing/catalog/CatalogCaller.java @@ -4,24 +4,11 @@ * Who a catalog request is made on behalf of. * *

A provider admin adding an object to a share is resolved as themselves, so the catalog decides - * whether that person may share it. Requests with no user behind them — a recipient reading a table - * long after it was shared — use {@link #server()}, because the server keeps only a hash of a - * principal's token and cannot replay it later. + * whether that person may share it. */ public record CatalogCaller(String name, String bearerToken) { - private static final CatalogCaller SERVER = new CatalogCaller(null, null); - public static CatalogCaller of(String name, String bearerToken) { return new CatalogCaller(name, bearerToken); } - - /** The sharing server's own catalog identity. */ - public static CatalogCaller server() { - return SERVER; - } - - public boolean isServer() { - return name == null; - } } From 62003ab974a8231492c57f420e3c8a3313b493ee Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 15:05:30 -0700 Subject: [PATCH 39/42] Fold access-denied and auth failures into CatalogException. Replace the two thin subclasses with CatalogException.Kind and static factories; GlobalExceptionHandler maps each kind to the same responses as before. --- .../catalog/AssetAccessDeniedException.java | 19 ---------- .../CatalogAuthenticationException.java | 13 ------- .../opensharing/catalog/CatalogException.java | 35 ++++++++++++++++++- .../http/GlobalExceptionHandler.java | 26 ++++++-------- 4 files changed, 44 insertions(+), 49 deletions(-) delete mode 100644 server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java delete mode 100644 server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java diff --git a/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java b/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java deleted file mode 100644 index 7b5fadb86..000000000 --- a/server/src/main/java/io/opensharing/catalog/AssetAccessDeniedException.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.opensharing.catalog; - -/** - * The catalog knows the asset but will not let this caller share it. Distinct from {@link - * CatalogAuthenticationException}, which is the sharing server's own credentials being rejected. - */ -public class AssetAccessDeniedException extends CatalogException { - - public AssetAccessDeniedException(AssetLookup lookup, CatalogCaller caller) { - super( - "'" - + caller.name() - + "' may not share " - + lookup.type() - + " '" - + lookup.identifier() - + "'"); - } -} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java b/server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java deleted file mode 100644 index 6c2833bd4..000000000 --- a/server/src/main/java/io/opensharing/catalog/CatalogAuthenticationException.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.opensharing.catalog; - -/** The sharing server's own service-principal credentials were rejected by the catalog. */ -public class CatalogAuthenticationException extends CatalogException { - - public CatalogAuthenticationException(String message) { - super(message); - } - - public CatalogAuthenticationException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogException.java b/server/src/main/java/io/opensharing/catalog/CatalogException.java index 0cd5d6915..1b5d68453 100644 --- a/server/src/main/java/io/opensharing/catalog/CatalogException.java +++ b/server/src/main/java/io/opensharing/catalog/CatalogException.java @@ -3,11 +3,44 @@ /** Raised when the catalog cannot satisfy a request. */ public class CatalogException extends RuntimeException { + public enum Kind { + ACCESS_DENIED, + AUTHENTICATION_FAILED + } + + private final Kind kind; + public CatalogException(String message) { - super(message); + this(message, null, null); } public CatalogException(String message, Throwable cause) { + this(message, cause, null); + } + + private CatalogException(String message, Throwable cause, Kind kind) { super(message, cause); + this.kind = kind; + } + + public Kind kind() { + return kind; + } + + public static CatalogException accessDenied(AssetLookup lookup, CatalogCaller caller) { + return new CatalogException( + "'" + + caller.name() + + "' may not share " + + lookup.type() + + " '" + + lookup.identifier() + + "'", + null, + Kind.ACCESS_DENIED); + } + + public static CatalogException authenticationFailed(String message, Throwable cause) { + return new CatalogException(message, cause, Kind.AUTHENTICATION_FAILED); } } diff --git a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java index b6920f7c0..2ba9a4896 100644 --- a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java +++ b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java @@ -1,8 +1,6 @@ package io.opensharing.http; -import io.opensharing.catalog.AssetAccessDeniedException; import io.opensharing.catalog.AssetNotFoundException; -import io.opensharing.catalog.CatalogAuthenticationException; import io.opensharing.catalog.CatalogException; import io.opensharing.catalog.UnsupportedAssetTypeException; import org.slf4j.Logger; @@ -34,27 +32,23 @@ public ResponseEntity handleAssetNotFound(AssetNotFoundException return body(HttpStatus.NOT_FOUND, ErrorCodes.RESOURCE_DOES_NOT_EXIST, e.getMessage()); } - @ExceptionHandler(AssetAccessDeniedException.class) - public ResponseEntity handleAssetAccessDenied(AssetAccessDeniedException e) { - return body(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, e.getMessage()); - } - @ExceptionHandler(UnsupportedAssetTypeException.class) public ResponseEntity handleUnsupportedAsset(UnsupportedAssetTypeException e) { return body(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, e.getMessage()); } - @ExceptionHandler(CatalogAuthenticationException.class) - public ResponseEntity handleCatalogAuth(CatalogAuthenticationException e) { - log.error("The sharing server could not authenticate to the catalog", e); - return body( - HttpStatus.BAD_GATEWAY, - ErrorCodes.CATALOG_ERROR, - "the sharing server could not authenticate to the catalog"); - } - @ExceptionHandler(CatalogException.class) public ResponseEntity handleCatalog(CatalogException e) { + if (e.kind() == CatalogException.Kind.ACCESS_DENIED) { + return body(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, e.getMessage()); + } + if (e.kind() == CatalogException.Kind.AUTHENTICATION_FAILED) { + log.error("The sharing server could not authenticate to the catalog", e); + return body( + HttpStatus.BAD_GATEWAY, + ErrorCodes.CATALOG_ERROR, + "the sharing server could not authenticate to the catalog"); + } log.error("Catalog request failed", e); return body(HttpStatus.BAD_GATEWAY, ErrorCodes.CATALOG_ERROR, e.getMessage()); } From 340b5bff5770bb4889728adf5460fcbe0aa616c4 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 15:08:05 -0700 Subject: [PATCH 40/42] Use one authorization subclass with a Reason enum. Keep CatalogException subclasses for each failure shape, but fold access denied and catalog authentication into CatalogAuthorizationException instead of two parallel types. --- .../CatalogAuthorizationException.java | 43 +++++++++++++++++++ .../opensharing/catalog/CatalogException.java | 35 +-------------- .../http/GlobalExceptionHandler.java | 24 ++++++----- 3 files changed, 58 insertions(+), 44 deletions(-) create mode 100644 server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java diff --git a/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java b/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java new file mode 100644 index 000000000..c183f28e7 --- /dev/null +++ b/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java @@ -0,0 +1,43 @@ +package io.opensharing.catalog; + +/** + * The catalog rejected a request on authorization grounds: either the caller may not use the asset, + * or the credential presented to the catalog was not accepted. + */ +public class CatalogAuthorizationException extends CatalogException { + + public enum Reason { + ACCESS_DENIED, + AUTHENTICATION_FAILED + } + + private final Reason reason; + + private CatalogAuthorizationException(Reason reason, String message, Throwable cause) { + super(message, cause); + this.reason = reason; + } + + public Reason reason() { + return reason; + } + + public static CatalogAuthorizationException accessDenied( + AssetLookup lookup, CatalogCaller caller) { + return new CatalogAuthorizationException( + Reason.ACCESS_DENIED, + "'" + + caller.name() + + "' may not share " + + lookup.type() + + " '" + + lookup.identifier() + + "'", + null); + } + + public static CatalogAuthorizationException authenticationFailed( + String message, Throwable cause) { + return new CatalogAuthorizationException(Reason.AUTHENTICATION_FAILED, message, cause); + } +} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogException.java b/server/src/main/java/io/opensharing/catalog/CatalogException.java index 1b5d68453..0cd5d6915 100644 --- a/server/src/main/java/io/opensharing/catalog/CatalogException.java +++ b/server/src/main/java/io/opensharing/catalog/CatalogException.java @@ -3,44 +3,11 @@ /** Raised when the catalog cannot satisfy a request. */ public class CatalogException extends RuntimeException { - public enum Kind { - ACCESS_DENIED, - AUTHENTICATION_FAILED - } - - private final Kind kind; - public CatalogException(String message) { - this(message, null, null); + super(message); } public CatalogException(String message, Throwable cause) { - this(message, cause, null); - } - - private CatalogException(String message, Throwable cause, Kind kind) { super(message, cause); - this.kind = kind; - } - - public Kind kind() { - return kind; - } - - public static CatalogException accessDenied(AssetLookup lookup, CatalogCaller caller) { - return new CatalogException( - "'" - + caller.name() - + "' may not share " - + lookup.type() - + " '" - + lookup.identifier() - + "'", - null, - Kind.ACCESS_DENIED); - } - - public static CatalogException authenticationFailed(String message, Throwable cause) { - return new CatalogException(message, cause, Kind.AUTHENTICATION_FAILED); } } diff --git a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java index 2ba9a4896..6dd9e4acf 100644 --- a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java +++ b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java @@ -1,6 +1,7 @@ package io.opensharing.http; import io.opensharing.catalog.AssetNotFoundException; +import io.opensharing.catalog.CatalogAuthorizationException; import io.opensharing.catalog.CatalogException; import io.opensharing.catalog.UnsupportedAssetTypeException; import org.slf4j.Logger; @@ -37,18 +38,21 @@ public ResponseEntity handleUnsupportedAsset(UnsupportedAssetType return body(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, e.getMessage()); } - @ExceptionHandler(CatalogException.class) - public ResponseEntity handleCatalog(CatalogException e) { - if (e.kind() == CatalogException.Kind.ACCESS_DENIED) { + @ExceptionHandler(CatalogAuthorizationException.class) + public ResponseEntity handleCatalogAuthorization( + CatalogAuthorizationException e) { + if (e.reason() == CatalogAuthorizationException.Reason.ACCESS_DENIED) { return body(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, e.getMessage()); } - if (e.kind() == CatalogException.Kind.AUTHENTICATION_FAILED) { - log.error("The sharing server could not authenticate to the catalog", e); - return body( - HttpStatus.BAD_GATEWAY, - ErrorCodes.CATALOG_ERROR, - "the sharing server could not authenticate to the catalog"); - } + log.error("The sharing server could not authenticate to the catalog", e); + return body( + HttpStatus.BAD_GATEWAY, + ErrorCodes.CATALOG_ERROR, + "the sharing server could not authenticate to the catalog"); + } + + @ExceptionHandler(CatalogException.class) + public ResponseEntity handleCatalog(CatalogException e) { log.error("Catalog request failed", e); return body(HttpStatus.BAD_GATEWAY, ErrorCodes.CATALOG_ERROR, e.getMessage()); } From be9a66c5306caaccc3a4c18d80dc9b4c101f62f3 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 15:10:19 -0700 Subject: [PATCH 41/42] Treat catalog access denied and auth failure as one case. CatalogAuthorizationException no longer distinguishes reason; both map to 403 PERMISSION_DENIED with the exception message. --- .../CatalogAuthorizationException.java | 28 ++++--------------- .../http/GlobalExceptionHandler.java | 10 ++----- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java b/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java index c183f28e7..1f077cae3 100644 --- a/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java +++ b/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java @@ -1,43 +1,25 @@ package io.opensharing.catalog; -/** - * The catalog rejected a request on authorization grounds: either the caller may not use the asset, - * or the credential presented to the catalog was not accepted. - */ +/** The catalog rejected the caller's credential or refused access to the asset. */ public class CatalogAuthorizationException extends CatalogException { - public enum Reason { - ACCESS_DENIED, - AUTHENTICATION_FAILED + public CatalogAuthorizationException(String message) { + super(message); } - private final Reason reason; - - private CatalogAuthorizationException(Reason reason, String message, Throwable cause) { + public CatalogAuthorizationException(String message, Throwable cause) { super(message, cause); - this.reason = reason; - } - - public Reason reason() { - return reason; } public static CatalogAuthorizationException accessDenied( AssetLookup lookup, CatalogCaller caller) { return new CatalogAuthorizationException( - Reason.ACCESS_DENIED, "'" + caller.name() + "' may not share " + lookup.type() + " '" + lookup.identifier() - + "'", - null); - } - - public static CatalogAuthorizationException authenticationFailed( - String message, Throwable cause) { - return new CatalogAuthorizationException(Reason.AUTHENTICATION_FAILED, message, cause); + + "'"); } } diff --git a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java index 6dd9e4acf..adf69a6d1 100644 --- a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java +++ b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java @@ -41,14 +41,10 @@ public ResponseEntity handleUnsupportedAsset(UnsupportedAssetType @ExceptionHandler(CatalogAuthorizationException.class) public ResponseEntity handleCatalogAuthorization( CatalogAuthorizationException e) { - if (e.reason() == CatalogAuthorizationException.Reason.ACCESS_DENIED) { - return body(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, e.getMessage()); + if (e.getCause() != null) { + log.error("Catalog authorization failed", e); } - log.error("The sharing server could not authenticate to the catalog", e); - return body( - HttpStatus.BAD_GATEWAY, - ErrorCodes.CATALOG_ERROR, - "the sharing server could not authenticate to the catalog"); + return body(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, e.getMessage()); } @ExceptionHandler(CatalogException.class) From 82a7b6742f224104a0b63f00e1586d7521679d39 Mon Sep 17 00:00:00 2001 From: Sun Cao Date: Tue, 1 Sep 2026 15:11:24 -0700 Subject: [PATCH 42/42] Keep PR 3 to generic HTTP error handling only. Catalog-specific exception types and their HTTP mapping belong with the catalog connector PR, where connector code translates native catalog failures into sharing-server exceptions. --- .../io/opensharing/catalog/AssetLookup.java | 22 -------------- .../catalog/AssetNotFoundException.java | 9 ------ .../io/opensharing/catalog/AssetType.java | 16 ---------- .../CatalogAuthorizationException.java | 25 ---------------- .../io/opensharing/catalog/CatalogCaller.java | 14 --------- .../opensharing/catalog/CatalogException.java | 13 --------- .../UnsupportedAssetTypeException.java | 9 ------ .../http/GlobalExceptionHandler.java | 29 ------------------- 8 files changed, 137 deletions(-) delete mode 100644 server/src/main/java/io/opensharing/catalog/AssetLookup.java delete mode 100644 server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java delete mode 100644 server/src/main/java/io/opensharing/catalog/AssetType.java delete mode 100644 server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java delete mode 100644 server/src/main/java/io/opensharing/catalog/CatalogCaller.java delete mode 100644 server/src/main/java/io/opensharing/catalog/CatalogException.java delete mode 100644 server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java diff --git a/server/src/main/java/io/opensharing/catalog/AssetLookup.java b/server/src/main/java/io/opensharing/catalog/AssetLookup.java deleted file mode 100644 index c9908f0be..000000000 --- a/server/src/main/java/io/opensharing/catalog/AssetLookup.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.opensharing.catalog; - -import java.util.Objects; - -/** - * Identifies an asset in the catalog's own namespace, independent of how it is named in a share. - * - * @param identifier catalog-native identifier, e.g. a three-level {@code main.sales.orders} - */ -public record AssetLookup(AssetType type, String identifier) { - - public AssetLookup { - Objects.requireNonNull(type, "type"); - if (identifier == null || identifier.isBlank()) { - throw new IllegalArgumentException("catalog identifier must not be blank"); - } - } - - public static AssetLookup of(AssetType type, String identifier) { - return new AssetLookup(type, identifier); - } -} diff --git a/server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java b/server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java deleted file mode 100644 index 883c7f3f1..000000000 --- a/server/src/main/java/io/opensharing/catalog/AssetNotFoundException.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.opensharing.catalog; - -/** The catalog has no asset with the requested identifier and type. */ -public class AssetNotFoundException extends CatalogException { - - public AssetNotFoundException(AssetLookup lookup) { - super(lookup.type() + " '" + lookup.identifier() + "' does not exist in the catalog"); - } -} diff --git a/server/src/main/java/io/opensharing/catalog/AssetType.java b/server/src/main/java/io/opensharing/catalog/AssetType.java deleted file mode 100644 index 421692ed7..000000000 --- a/server/src/main/java/io/opensharing/catalog/AssetType.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.opensharing.catalog; - -/** - * Asset types a share can hold. {@link #TABLE} and {@link #SCHEMA} are accepted; the rest are here - * because they are part of the model and are rejected explicitly rather than silently absent. - * - *

{@link #SCHEMA} is the odd one, in that sharing it shares nothing directly: it stands for the - * tables the catalog holds in it, which is why it needs a catalog that can be asked what those are. - */ -public enum AssetType { - TABLE, - VOLUME, - MODEL, - SKILL, - SCHEMA -} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java b/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java deleted file mode 100644 index 1f077cae3..000000000 --- a/server/src/main/java/io/opensharing/catalog/CatalogAuthorizationException.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.opensharing.catalog; - -/** The catalog rejected the caller's credential or refused access to the asset. */ -public class CatalogAuthorizationException extends CatalogException { - - public CatalogAuthorizationException(String message) { - super(message); - } - - public CatalogAuthorizationException(String message, Throwable cause) { - super(message, cause); - } - - public static CatalogAuthorizationException accessDenied( - AssetLookup lookup, CatalogCaller caller) { - return new CatalogAuthorizationException( - "'" - + caller.name() - + "' may not share " - + lookup.type() - + " '" - + lookup.identifier() - + "'"); - } -} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogCaller.java b/server/src/main/java/io/opensharing/catalog/CatalogCaller.java deleted file mode 100644 index 7f1bae75a..000000000 --- a/server/src/main/java/io/opensharing/catalog/CatalogCaller.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.opensharing.catalog; - -/** - * Who a catalog request is made on behalf of. - * - *

A provider admin adding an object to a share is resolved as themselves, so the catalog decides - * whether that person may share it. - */ -public record CatalogCaller(String name, String bearerToken) { - - public static CatalogCaller of(String name, String bearerToken) { - return new CatalogCaller(name, bearerToken); - } -} diff --git a/server/src/main/java/io/opensharing/catalog/CatalogException.java b/server/src/main/java/io/opensharing/catalog/CatalogException.java deleted file mode 100644 index 0cd5d6915..000000000 --- a/server/src/main/java/io/opensharing/catalog/CatalogException.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.opensharing.catalog; - -/** Raised when the catalog cannot satisfy a request. */ -public class CatalogException extends RuntimeException { - - public CatalogException(String message) { - super(message); - } - - public CatalogException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java b/server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java deleted file mode 100644 index fac436a15..000000000 --- a/server/src/main/java/io/opensharing/catalog/UnsupportedAssetTypeException.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.opensharing.catalog; - -/** The connector cannot handle the requested asset type or operation. */ -public class UnsupportedAssetTypeException extends CatalogException { - - public UnsupportedAssetTypeException(String message) { - super(message); - } -} diff --git a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java index adf69a6d1..84b75d355 100644 --- a/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java +++ b/server/src/main/java/io/opensharing/http/GlobalExceptionHandler.java @@ -1,9 +1,5 @@ package io.opensharing.http; -import io.opensharing.catalog.AssetNotFoundException; -import io.opensharing.catalog.CatalogAuthorizationException; -import io.opensharing.catalog.CatalogException; -import io.opensharing.catalog.UnsupportedAssetTypeException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.DataIntegrityViolationException; @@ -28,31 +24,6 @@ public ResponseEntity handleApi(ApiException e) { return body(e.getStatus(), e.getErrorCode(), e.getMessage()); } - @ExceptionHandler(AssetNotFoundException.class) - public ResponseEntity handleAssetNotFound(AssetNotFoundException e) { - return body(HttpStatus.NOT_FOUND, ErrorCodes.RESOURCE_DOES_NOT_EXIST, e.getMessage()); - } - - @ExceptionHandler(UnsupportedAssetTypeException.class) - public ResponseEntity handleUnsupportedAsset(UnsupportedAssetTypeException e) { - return body(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, e.getMessage()); - } - - @ExceptionHandler(CatalogAuthorizationException.class) - public ResponseEntity handleCatalogAuthorization( - CatalogAuthorizationException e) { - if (e.getCause() != null) { - log.error("Catalog authorization failed", e); - } - return body(HttpStatus.FORBIDDEN, ErrorCodes.PERMISSION_DENIED, e.getMessage()); - } - - @ExceptionHandler(CatalogException.class) - public ResponseEntity handleCatalog(CatalogException e) { - log.error("Catalog request failed", e); - return body(HttpStatus.BAD_GATEWAY, ErrorCodes.CATALOG_ERROR, e.getMessage()); - } - @ExceptionHandler(IllegalArgumentException.class) public ResponseEntity handleIllegalArgument(IllegalArgumentException e) { return body(HttpStatus.BAD_REQUEST, ErrorCodes.INVALID_PARAMETER_VALUE, e.getMessage());