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

Commit 7d31e41

Browse files
committed
basic authorization based on the request principal
1 parent fa230d3 commit 7d31e41

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

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

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ public Response getShare(String share) {
4545
return wrapExceptions(
4646
() ->
4747
optionalToNotFound(shareService.getShare(share),
48-
s -> {
48+
foundShare ->
49+
shareToForbidden(foundShare, s -> {
4950
var resultShare = new Share().name(s.name()).id(s.id());
5051
return Response.ok(resultShare).build();
51-
}),
52+
})),
5253
exceptionToResponse);
5354
}
5455

@@ -73,24 +74,25 @@ public Response getTableMetadata(
7374
String startingTimestampStr,
7475
String deltaSharingCapabilities) {
7576
return wrapExceptions(
76-
() -> {
77-
var startingTimestamp = parseTimestamp(startingTimestampStr);
78-
return optionalToNotFound(
79-
deltaSharesService.getTableMetadata(share, schema, table, startingTimestamp),
80-
m -> optionalToNotFound(
81-
deltaSharesService.getTableVersion(share, schema, table, startingTimestamp),
82-
v -> Response.ok(
83-
tableResponseSerializer.serialize(
84-
DeltaMappers.toTableResponseMetadata(m)),
85-
ndjsonMediaType)
86-
.status(Response.Status.OK.getStatusCode())
87-
.header(DELTA_TABLE_VERSION_HEADER, String.valueOf(v))
88-
.header(
89-
DELTA_SHARE_CAPABILITIES_HEADER,
90-
getResponseFormatHeader(
91-
DeltaMappers.toHeaderCapabilitiesMap(deltaSharingCapabilities)))
92-
.build()));
93-
},
77+
() ->
78+
optionalToNotFound(shareService.getShare(share), foundShare -> shareToForbidden(foundShare, s -> {
79+
var startingTimestamp = parseTimestamp(startingTimestampStr);
80+
return optionalToNotFound(
81+
deltaSharesService.getTableMetadata(share, schema, table, startingTimestamp),
82+
m -> optionalToNotFound(
83+
deltaSharesService.getTableVersion(share, schema, table, startingTimestamp),
84+
v -> Response.ok(
85+
tableResponseSerializer.serialize(
86+
DeltaMappers.toTableResponseMetadata(m)),
87+
ndjsonMediaType)
88+
.status(Response.Status.OK.getStatusCode())
89+
.header(DELTA_TABLE_VERSION_HEADER, String.valueOf(v))
90+
.header(
91+
DELTA_SHARE_CAPABILITIES_HEADER,
92+
getResponseFormatHeader(
93+
DeltaMappers.toHeaderCapabilitiesMap(deltaSharingCapabilities)))
94+
.build()));
95+
})),
9496
exceptionToResponse);
9597
}
9698

@@ -99,28 +101,31 @@ public Response getTableVersion(
99101
String share, String schema, String table, String startingTimestampStr) {
100102

101103
return wrapExceptions(
102-
() -> {
104+
() ->
105+
optionalToNotFound(shareService.getShare(share), foundShare -> shareToForbidden(foundShare, s -> {
103106
var startingTimestamp = parseTimestamp(startingTimestampStr);
104107
return optionalToNotFound(
105108
deltaSharesService.getTableVersion(share, schema, table, startingTimestamp),
106109
t -> Response.ok().header(DELTA_TABLE_VERSION_HEADER, t).build());
107-
},
110+
})),
108111
exceptionToResponse);
109112
}
110113

111114
@Override
112115
public Response listALLTables(String share, Integer maxResults, String pageToken) {
113116
return wrapExceptions(
114-
() -> optionalToNotFound(
115-
deltaSharesService.listTablesOfShare(
116-
share, parseToken(pageToken), Optional.ofNullable(maxResults)),
117-
c -> Response.ok(c.getToken()
118-
.map(t -> new ListTablesResponse()
119-
.items(mapList(c.getContent(), DeltaMappers::table2api))
120-
.nextPageToken(tokenEncoder.encodePageToken(t)))
121-
.orElse(new ListTablesResponse()
122-
.items(mapList(c.getContent(), DeltaMappers::table2api))))
123-
.build()),
117+
() ->
118+
optionalToNotFound(shareService.getShare(share), foundShare -> shareToForbidden(foundShare, s ->
119+
optionalToNotFound(
120+
deltaSharesService.listTablesOfShare(
121+
share, parseToken(pageToken), Optional.ofNullable(maxResults)),
122+
c -> Response.ok(c.getToken()
123+
.map(t -> new ListTablesResponse()
124+
.items(mapList(c.getContent(), DeltaMappers::table2api))
125+
.nextPageToken(tokenEncoder.encodePageToken(t)))
126+
.orElse(new ListTablesResponse()
127+
.items(mapList(c.getContent(), DeltaMappers::table2api))))
128+
.build()))),
124129
exceptionToResponse);
125130
}
126131

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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;
67
import io.whitefox.core.services.DeltaSharedTable;
78
import io.whitefox.core.services.exceptions.AlreadyExists;
89
import io.whitefox.core.services.exceptions.NotFound;
@@ -70,6 +71,13 @@ default <T> Response optionalToNotFound(Optional<T> opt, Function<T, Response> f
7071
return opt.map(fn).orElse(notFoundResponse());
7172
}
7273

74+
default Response shareToForbidden(Share value, Function<Share, Response> fn) {
75+
if (value.recipients().contains(getRequestPrincipal()))
76+
return fn.apply(value);
77+
else
78+
return Response.status(Response.Status.FORBIDDEN).build();
79+
}
80+
7381
default String getResponseFormatHeader(Map<String, String> deltaSharingCapabilities) {
7482
return String.format(
7583
"%s=%s",

0 commit comments

Comments
 (0)