Skip to content

Commit 4efd278

Browse files
authored
Fix the owner related features in kafka sql (#5731)
* Fix the owner related features in kafka sql * Fix scope * Fix owner only updates * Make auth tests use keycloak container for better reproducibility * Upgrade keycloak version
1 parent 88dae10 commit 4efd278

File tree

52 files changed

+4304
-692
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4304
-692
lines changed

app/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@
293293
<artifactId>strimzi-test-container</artifactId>
294294
<scope>test</scope>
295295
</dependency>
296+
<dependency>
297+
<groupId>com.github.dasniko</groupId>
298+
<artifactId>testcontainers-keycloak</artifactId>
299+
<scope>test</scope>
300+
</dependency>
296301
<dependency>
297302
<groupId>io.zonky.test</groupId>
298303
<artifactId>embedded-postgres</artifactId>

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/AbstractResource.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.apicurio.registry.types.VersionState;
3333
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
3434
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
35+
import io.quarkus.security.identity.SecurityIdentity;
3536
import jakarta.inject.Inject;
3637
import jakarta.ws.rs.BadRequestException;
3738
import org.apache.avro.AvroTypeException;
@@ -67,6 +68,9 @@ public abstract class AbstractResource {
6768
@Inject
6869
ArtifactTypeUtilProviderFactory factory;
6970

71+
@Inject
72+
SecurityIdentity securityIdentity;
73+
7074
protected String toSubjectWithGroupConcat(String groupId, String artifactId) {
7175
return (groupId == null ? "" : groupId) + cconfig.groupConcatSeparator + artifactId;
7276
}
@@ -107,6 +111,9 @@ protected ArtifactVersionMetaDataDto createOrUpdateArtifact(String artifactId, S
107111
.collect(Collectors.toList());
108112
final Map<String, TypedContent> resolvedReferences = RegistryContentUtils
109113
.recursivelyResolveReferences(parsedReferences, storage::getContentByReference);
114+
115+
String owner = securityIdentity.getPrincipal().getName();
116+
110117
try {
111118
ContentHandle schemaContent;
112119
schemaContent = ContentHandle.create(schema);
@@ -126,16 +133,18 @@ protected ArtifactVersionMetaDataDto createOrUpdateArtifact(String artifactId, S
126133
ContentWrapperDto firstVersionContent = ContentWrapperDto.builder().content(schemaContent)
127134
.contentType(contentType).references(parsedReferences).build();
128135

129-
res = storage.createArtifact(groupId, artifactId, artifactType, artifactMetaData, null,
130-
firstVersionContent, firstVersionMetaData, null, false, false).getValue();
136+
res = storage
137+
.createArtifact(groupId, artifactId, artifactType, artifactMetaData, null,
138+
firstVersionContent, firstVersionMetaData, null, false, false, owner)
139+
.getValue();
131140
} else {
132141
TypedContent typedSchemaContent = TypedContent.create(schemaContent, contentType);
133142
rulesService.applyRules(groupId, artifactId, artifactType, typedSchemaContent,
134143
RuleApplicationType.UPDATE, artifactReferences, resolvedReferences);
135144
ContentWrapperDto versionContent = ContentWrapperDto.builder().content(schemaContent)
136145
.contentType(contentType).references(parsedReferences).build();
137146
res = storage.createArtifactVersion(groupId, artifactId, null, artifactType, versionContent,
138-
EditableVersionMetaDataDto.builder().build(), List.of(), false, false);
147+
EditableVersionMetaDataDto.builder().build(), List.of(), false, false, owner);
139148
}
140149
} catch (RuleViolationException ex) {
141150
if (ex.getRuleType() == RuleType.VALIDITY) {

app/src/main/java/io/apicurio/registry/limits/RegistryStorageLimitsEnforcer.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,26 @@ public int order() {
6060
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
6161
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
6262
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
63-
List<String> versionBranches, boolean versionIsDraft, boolean dryRun)
63+
List<String> versionBranches, boolean versionIsDraft, boolean dryRun, String owner)
6464
throws RegistryStorageException {
6565
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> rval = withLimitsCheck(
6666
() -> limitsService.canCreateArtifact(artifactMetaData, versionContent, versionMetaData))
6767
.execute(() -> super.createArtifact(groupId, artifactId, artifactType, artifactMetaData,
68-
version, versionContent, versionMetaData, versionBranches, versionIsDraft, dryRun));
68+
version, versionContent, versionMetaData, versionBranches, versionIsDraft, dryRun,
69+
owner));
6970
limitsService.artifactCreated();
7071
return rval;
7172
}
7273

7374
@Override
7475
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
7576
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
76-
List<String> branches, boolean isDraft, boolean dryRun) throws RegistryStorageException {
77+
List<String> branches, boolean isDraft, boolean dryRun, String owner)
78+
throws RegistryStorageException {
7779
ArtifactVersionMetaDataDto dto = withLimitsCheck(
7880
() -> limitsService.canCreateArtifactVersion(groupId, artifactId, null, content.getContent()))
7981
.execute(() -> super.createArtifactVersion(groupId, artifactId, version, artifactType,
80-
content, metaData, branches, isDraft, dryRun));
82+
content, metaData, branches, isDraft, dryRun, owner));
8183
limitsService.artifactVersionCreated(groupId, artifactId);
8284
return dto;
8385
}

app/src/main/java/io/apicurio/registry/rest/v2/GroupsResourceImpl.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,8 @@ private ArtifactMetaData createArtifactWithRefs(String groupId, String xRegistry
10981098

10991099
String ct = getContentType();
11001100
try {
1101+
1102+
String owner = securityIdentity.getPrincipal().getName();
11011103
String artifactId = xRegistryArtifactId;
11021104

11031105
if (artifactId == null || artifactId.trim().isEmpty()) {
@@ -1140,7 +1142,7 @@ private ArtifactMetaData createArtifactWithRefs(String groupId, String xRegistry
11401142

11411143
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createResult = storage.createArtifact(
11421144
defaultGroupIdToNull(groupId), artifactId, artifactType, metaData, xRegistryVersion,
1143-
contentDto, versionMetaData, List.of(), false, false);
1145+
contentDto, versionMetaData, List.of(), false, false, owner);
11441146

11451147
return V2ApiUtil.dtoToMetaData(groupId, artifactId, artifactType, createResult.getRight());
11461148
} catch (ArtifactAlreadyExistsException ex) {
@@ -1258,6 +1260,8 @@ private VersionMetaData createArtifactVersionWithRefs(String groupId, String art
12581260
final Map<String, TypedContent> resolvedReferences = RegistryContentUtils
12591261
.recursivelyResolveReferences(referencesAsDtos, storage::getContentByReference);
12601262

1263+
final String owner = securityIdentity.getPrincipal().getName();
1264+
12611265
String artifactType = lookupArtifactType(groupId, artifactId);
12621266
TypedContent typedContent = TypedContent.create(content, ct);
12631267
rulesService.applyRules(defaultGroupIdToNull(groupId), artifactId, artifactType, typedContent,
@@ -1266,7 +1270,8 @@ private VersionMetaData createArtifactVersionWithRefs(String groupId, String art
12661270
ContentWrapperDto contentDto = ContentWrapperDto.builder().content(content).contentType(ct)
12671271
.references(referencesAsDtos).build();
12681272
ArtifactVersionMetaDataDto vmdDto = storage.createArtifactVersion(defaultGroupIdToNull(groupId),
1269-
artifactId, xRegistryVersion, artifactType, contentDto, metaData, List.of(), false, false);
1273+
artifactId, xRegistryVersion, artifactType, contentDto, metaData, List.of(), false, false,
1274+
owner);
12701275
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId, artifactType,
12711276
vmdDto);
12721277
}
@@ -1366,7 +1371,8 @@ private ArtifactMetaData handleIfExistsReturnOrUpdate(String groupId, String art
13661371
content, contentType, references);
13671372
}
13681373

1369-
private ArtifactMetaData updateArtifactInternal(String groupId, String artifactId, String version,
1374+
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
1375+
protected ArtifactMetaData updateArtifactInternal(String groupId, String artifactId, String version,
13701376
String name, String description, ContentHandle content, String contentType,
13711377
List<ArtifactReference> references) {
13721378

@@ -1396,13 +1402,16 @@ private ArtifactMetaData updateArtifactInternal(String groupId, String artifactI
13961402
if (description != null && description.trim().isEmpty()) {
13971403
artifactMD.setDescription(description);
13981404
}
1405+
1406+
final String owner = securityIdentity.getPrincipal().getName();
1407+
13991408
EditableVersionMetaDataDto metaData = EditableVersionMetaDataDto.builder().name(artifactMD.getName())
14001409
.description(artifactMD.getDescription()).labels(artifactMD.getLabels()).build();
14011410

14021411
ContentWrapperDto contentDto = ContentWrapperDto.builder().content(content).contentType(contentType)
14031412
.references(referencesAsDtos).build();
14041413
ArtifactVersionMetaDataDto dto = storage.createArtifactVersion(defaultGroupIdToNull(groupId),
1405-
artifactId, version, artifactType, contentDto, metaData, List.of(), false, false);
1414+
artifactId, version, artifactType, contentDto, metaData, List.of(), false, false, owner);
14061415

14071416
// Note: if the version was created, we need to update the artifact metadata as well, because
14081417
// those are the semantics of the v2 API. :(

app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,8 @@ public CreateArtifactResponse createArtifact(String groupId, IfArtifactExists if
913913
String artifactType = ArtifactTypeUtil.determineArtifactType(typedContent, data.getArtifactType(),
914914
factory);
915915

916+
final String owner = securityIdentity.getPrincipal().getName();
917+
916918
// Create the artifact (with optional first version)
917919
EditableArtifactMetaDataDto artifactMetaData = EditableArtifactMetaDataDto.builder()
918920
.description(data.getDescription()).name(data.getName()).labels(data.getLabels()).build();
@@ -951,7 +953,7 @@ public CreateArtifactResponse createArtifact(String groupId, IfArtifactExists if
951953
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> storageResult = storage.createArtifact(
952954
new GroupId(groupId).getRawGroupIdWithNull(), artifactId, artifactType, artifactMetaData,
953955
firstVersion, firstVersionContent, firstVersionMetaData, firstVersionBranches,
954-
firstVersionIsDraft, dryRun != null && dryRun);
956+
firstVersionIsDraft, dryRun != null && dryRun, owner);
955957

956958
// Now return both the artifact metadata and (if available) the version metadata
957959
CreateArtifactResponse rval = CreateArtifactResponse.builder()
@@ -1035,14 +1037,17 @@ public VersionMetaData createArtifactVersion(String groupId, String artifactId,
10351037
typedContent, RuleApplicationType.UPDATE, data.getContent().getReferences(),
10361038
resolvedReferences);
10371039
}
1040+
1041+
final String owner = securityIdentity.getPrincipal().getName();
1042+
10381043
EditableVersionMetaDataDto metaDataDto = EditableVersionMetaDataDto.builder()
10391044
.description(data.getDescription()).name(data.getName()).labels(data.getLabels()).build();
10401045
ContentWrapperDto contentDto = ContentWrapperDto.builder().contentType(ct).content(content)
10411046
.references(referencesAsDtos).build();
10421047

10431048
ArtifactVersionMetaDataDto vmd = storage.createArtifactVersion(
10441049
new GroupId(groupId).getRawGroupIdWithNull(), artifactId, data.getVersion(), artifactType,
1045-
contentDto, metaDataDto, data.getBranches(), isDraft, dryRun != null && dryRun);
1050+
contentDto, metaDataDto, data.getBranches(), isDraft, dryRun != null && dryRun, owner);
10461051

10471052
return V3ApiUtil.dtoToVersionMetaData(vmd);
10481053
}
@@ -1275,7 +1280,8 @@ private CreateArtifactResponse handleIfExistsReturnOrUpdate(String groupId, Stri
12751280
return updateArtifactInternal(groupId, artifactId, theVersion);
12761281
}
12771282

1278-
private CreateArtifactResponse updateArtifactInternal(String groupId, String artifactId,
1283+
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
1284+
protected CreateArtifactResponse updateArtifactInternal(String groupId, String artifactId,
12791285
CreateVersion theVersion) {
12801286
String version = theVersion.getVersion();
12811287
String name = theVersion.getName();
@@ -1289,6 +1295,8 @@ private CreateArtifactResponse updateArtifactInternal(String groupId, String art
12891295

12901296
String artifactType = lookupArtifactType(groupId, artifactId);
12911297

1298+
final String owner = securityIdentity.getPrincipal().getName();
1299+
12921300
// Transform the given references into dtos and set the contentId, this will also detect if any of the
12931301
// passed references does not exist.
12941302
final List<ArtifactReferenceDto> referencesAsDtos = toReferenceDtos(references);
@@ -1307,7 +1315,7 @@ private CreateArtifactResponse updateArtifactInternal(String groupId, String art
13071315
ContentWrapperDto contentDto = ContentWrapperDto.builder().contentType(contentType).content(content)
13081316
.references(referencesAsDtos).build();
13091317
ArtifactVersionMetaDataDto vmdDto = storage.createArtifactVersion(groupId, artifactId, version,
1310-
artifactType, contentDto, metaData, branches, isDraftVersion, false);
1318+
artifactType, contentDto, metaData, branches, isDraftVersion, false, owner);
13111319
VersionMetaData vmd = V3ApiUtil.dtoToVersionMetaData(vmdDto);
13121320

13131321
// Need to also return the artifact metadata

app/src/main/java/io/apicurio/registry/storage/RegistryStorage.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public interface RegistryStorage extends DynamicConfigStorage {
112112
Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId, String artifactId,
113113
String artifactType, EditableArtifactMetaDataDto artifactMetaData, String version,
114114
ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
115-
List<String> versionBranches, boolean versionIsDraft, boolean dryRun)
115+
List<String> versionBranches, boolean versionIsDraft, boolean dryRun, String owner)
116116
throws ArtifactAlreadyExistsException, RegistryStorageException;
117117

118118
/**
@@ -190,7 +190,7 @@ ContentWrapperDto getContentByHash(String contentHash)
190190
*/
191191
ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
192192
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
193-
List<String> branches, boolean isDraft, boolean dryRun)
193+
List<String> branches, boolean isDraft, boolean dryRun, String owner)
194194
throws ArtifactNotFoundException, VersionAlreadyExistsException, RegistryStorageException;
195195

196196
/**

app/src/main/java/io/apicurio/registry/storage/decorator/ReadOnlyRegistryStorageDecorator.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ public boolean isReadOnly() {
7676
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
7777
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
7878
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
79-
List<String> versionBranches, boolean isVersionDraft, boolean dryRun)
79+
List<String> versionBranches, boolean isVersionDraft, boolean dryRun, String owner)
8080
throws RegistryStorageException {
8181
checkReadOnly();
8282
return delegate.createArtifact(groupId, artifactId, artifactType, artifactMetaData, version,
83-
versionContent, versionMetaData, versionBranches, isVersionDraft, dryRun);
83+
versionContent, versionMetaData, versionBranches, isVersionDraft, dryRun, owner);
8484
}
8585

8686
@Override
@@ -99,10 +99,11 @@ public void deleteArtifacts(String groupId) throws RegistryStorageException {
9999
@Override
100100
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
101101
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
102-
List<String> branches, boolean isDraft, boolean dryRun) throws RegistryStorageException {
102+
List<String> branches, boolean isDraft, boolean dryRun, String owner)
103+
throws RegistryStorageException {
103104
checkReadOnly();
104105
return delegate.createArtifactVersion(groupId, artifactId, version, artifactType, content, metaData,
105-
branches, isDraft, dryRun);
106+
branches, isDraft, dryRun, owner);
106107
}
107108

108109
@Override

app/src/main/java/io/apicurio/registry/storage/decorator/RegistryStorageDecoratorBase.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ protected RegistryStorageDecoratorBase() {
4242
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
4343
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
4444
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
45-
List<String> versionBranches, boolean versionIsDraft, boolean dryRun)
45+
List<String> versionBranches, boolean versionIsDraft, boolean dryRun, String owner)
4646
throws RegistryStorageException {
4747
return delegate.createArtifact(groupId, artifactId, artifactType, artifactMetaData, version,
48-
versionContent, versionMetaData, versionBranches, versionIsDraft, dryRun);
48+
versionContent, versionMetaData, versionBranches, versionIsDraft, dryRun, owner);
4949
}
5050

5151
@Override
@@ -62,9 +62,10 @@ public void deleteArtifacts(String groupId) throws RegistryStorageException {
6262
@Override
6363
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
6464
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
65-
List<String> branches, boolean isDraft, boolean dryRun) throws RegistryStorageException {
65+
List<String> branches, boolean isDraft, boolean dryRun, String owner)
66+
throws RegistryStorageException {
6667
return delegate.createArtifactVersion(groupId, artifactId, version, artifactType, content, metaData,
67-
branches, isDraft, dryRun);
68+
branches, isDraft, dryRun, owner);
6869
}
6970

7071
@Override

app/src/main/java/io/apicurio/registry/storage/impl/gitops/AbstractReadOnlyRegistryStorage.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public boolean isReadOnly() {
5252
public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(String groupId,
5353
String artifactId, String artifactType, EditableArtifactMetaDataDto artifactMetaData,
5454
String version, ContentWrapperDto versionContent, EditableVersionMetaDataDto versionMetaData,
55-
List<String> versionBranches, boolean versionIsDraft, boolean dryRun)
55+
List<String> versionBranches, boolean versionIsDraft, boolean dryRun, String owner)
5656
throws RegistryStorageException {
5757
readOnlyViolation();
5858
return null;
@@ -61,7 +61,8 @@ public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(Stri
6161
@Override
6262
public ArtifactVersionMetaDataDto createArtifactVersion(String groupId, String artifactId, String version,
6363
String artifactType, ContentWrapperDto content, EditableVersionMetaDataDto metaData,
64-
List<String> branches, boolean isDraft, boolean dryRun) throws RegistryStorageException {
64+
List<String> branches, boolean isDraft, boolean dryRun, String owner)
65+
throws RegistryStorageException {
6566
readOnlyViolation();
6667
return null;
6768
}

0 commit comments

Comments
 (0)