Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit eb21a84

Browse files
committed
basic authorization based on the request principal
1 parent 8c9cc35 commit eb21a84

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

server/app/src/main/java/io/whitefox/api/deltasharing/server/DeltaSharesApiImpl.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ public Response getShare(String share) {
5050
return wrapExceptions(
5151
() ->
5252
optionalToNotFound(shareService.getShare(share),
53-
s -> {
53+
foundShare ->
54+
shareToForbidden(foundShare, s -> {
5455
var resultShare = new Share().name(s.name()).id(s.id());
5556
return Response.ok(resultShare).build();
56-
}),
57+
})),
5758
exceptionToResponse);
5859
}
5960

@@ -107,28 +108,31 @@ public Response getTableVersion(
107108
String share, String schema, String table, String startingTimestampStr) {
108109

109110
return wrapExceptions(
110-
() -> {
111+
() ->
112+
optionalToNotFound(shareService.getShare(share), foundShare -> shareToForbidden(foundShare, s -> {
111113
var startingTimestamp = parseTimestamp(startingTimestampStr);
112114
return optionalToNotFound(
113115
deltaSharesService.getTableVersion(share, schema, table, startingTimestamp),
114116
t -> Response.ok().header(DELTA_TABLE_VERSION_HEADER, t).build());
115-
},
117+
})),
116118
exceptionToResponse);
117119
}
118120

119121
@Override
120122
public Response listALLTables(String share, Integer maxResults, String pageToken) {
121123
return wrapExceptions(
122-
() -> optionalToNotFound(
123-
deltaSharesService.listTablesOfShare(
124-
share, parseToken(pageToken), Optional.ofNullable(maxResults)),
125-
c -> Response.ok(c.getToken()
126-
.map(t -> new ListTablesResponse()
127-
.items(mapList(c.getContent(), DeltaMappers::table2api))
128-
.nextPageToken(tokenEncoder.encodePageToken(t)))
129-
.orElse(new ListTablesResponse()
130-
.items(mapList(c.getContent(), DeltaMappers::table2api))))
131-
.build()),
124+
() ->
125+
optionalToNotFound(shareService.getShare(share), foundShare -> shareToForbidden(foundShare, s ->
126+
optionalToNotFound(
127+
deltaSharesService.listTablesOfShare(
128+
share, parseToken(pageToken), Optional.ofNullable(maxResults)),
129+
c -> Response.ok(c.getToken()
130+
.map(t -> new ListTablesResponse()
131+
.items(mapList(c.getContent(), DeltaMappers::table2api))
132+
.nextPageToken(tokenEncoder.encodePageToken(t)))
133+
.orElse(new ListTablesResponse()
134+
.items(mapList(c.getContent(), DeltaMappers::table2api))))
135+
.build()))),
132136
exceptionToResponse);
133137
}
134138

server/app/src/main/java/io/whitefox/api/server/ApiUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.quarkus.runtime.util.ExceptionUtil;
44
import io.whitefox.api.deltasharing.model.v1.generated.CommonErrorResponse;
55
import io.whitefox.core.Principal;
6+
import io.whitefox.core.Share;
7+
import io.whitefox.core.services.DeltaSharedTable;
68
import io.whitefox.core.services.exceptions.AlreadyExists;
79
import io.whitefox.core.services.exceptions.NotFound;
810
import jakarta.ws.rs.core.Response;
@@ -68,6 +70,25 @@ default <T> Response optionalToNotFound(Optional<T> opt, Function<T, Response> f
6870
return opt.map(fn).orElse(notFoundResponse());
6971
}
7072

73+
default Response shareToForbidden(Share value, Function<Share, Response> fn) {
74+
if (value.recipients().contains(getRequestPrincipal()))
75+
return fn.apply(value);
76+
else
77+
return Response.status(Response.Status.FORBIDDEN).build();
78+
}
79+
80+
default String getResponseFormatHeader(Map<String, String> deltaSharingCapabilities) {
81+
return String.format(
82+
"%s=%s",
83+
DeltaHeaders.DELTA_SHARING_RESPONSE_FORMAT, getResponseFormat(deltaSharingCapabilities));
84+
}
85+
86+
default String getResponseFormat(Map<String, String> deltaSharingCapabilities) {
87+
return deltaSharingCapabilities.getOrDefault(
88+
DeltaHeaders.DELTA_SHARING_RESPONSE_FORMAT,
89+
DeltaSharedTable.DeltaShareTableFormat.RESPONSE_FORMAT_PARQUET);
90+
}
91+
7192
default Principal getRequestPrincipal() {
7293
return new Principal("Mr. Fox");
7394
}

0 commit comments

Comments
 (0)