1
1
package io .apicurio .registry .rest .v3 ;
2
2
3
- import io .apicurio .common .apps .config .*;
3
+ import static io .apicurio .common .apps .logging .audit .AuditingConstants .KEY_FOR_BROWSER ;
4
+ import static io .apicurio .common .apps .logging .audit .AuditingConstants .KEY_NAME ;
5
+ import static io .apicurio .common .apps .logging .audit .AuditingConstants .KEY_PRINCIPAL_ID ;
6
+ import static io .apicurio .common .apps .logging .audit .AuditingConstants .KEY_ROLE_MAPPING ;
7
+ import static io .apicurio .common .apps .logging .audit .AuditingConstants .KEY_RULE ;
8
+ import static io .apicurio .common .apps .logging .audit .AuditingConstants .KEY_RULE_TYPE ;
9
+ import static io .apicurio .common .apps .logging .audit .AuditingConstants .KEY_UPDATE_ROLE ;
10
+ import static io .apicurio .registry .util .DtoUtil .appAuthPropertyToRegistry ;
11
+ import static io .apicurio .registry .util .DtoUtil .registryAuthPropertyToApp ;
12
+
13
+ import java .io .IOException ;
14
+ import java .io .InputStream ;
15
+ import java .math .BigInteger ;
16
+ import java .nio .charset .StandardCharsets ;
17
+ import java .util .HashMap ;
18
+ import java .util .List ;
19
+ import java .util .Map ;
20
+ import java .util .function .Supplier ;
21
+ import java .util .stream .Collectors ;
22
+ import java .util .stream .Stream ;
23
+ import java .util .zip .ZipInputStream ;
24
+
25
+ import org .eclipse .microprofile .config .Config ;
26
+ import org .eclipse .microprofile .config .inject .ConfigProperty ;
27
+ import org .slf4j .Logger ;
28
+
29
+ import io .apicurio .common .apps .config .Dynamic ;
30
+ import io .apicurio .common .apps .config .DynamicConfigPropertyDef ;
31
+ import io .apicurio .common .apps .config .DynamicConfigPropertyDto ;
32
+ import io .apicurio .common .apps .config .DynamicConfigPropertyIndex ;
33
+ import io .apicurio .common .apps .config .Info ;
4
34
import io .apicurio .common .apps .logging .Logged ;
5
35
import io .apicurio .common .apps .logging .audit .Audited ;
6
36
import io .apicurio .registry .auth .Authorized ;
10
40
import io .apicurio .registry .metrics .health .liveness .ResponseErrorLivenessCheck ;
11
41
import io .apicurio .registry .metrics .health .readiness .ResponseTimeoutReadinessCheck ;
12
42
import io .apicurio .registry .rest .MissingRequiredParameterException ;
13
- import io .apicurio .registry .rest .v3 .beans .*;
43
+ import io .apicurio .registry .rest .v3 .beans .ArtifactTypeInfo ;
44
+ import io .apicurio .registry .rest .v3 .beans .ConfigurationProperty ;
45
+ import io .apicurio .registry .rest .v3 .beans .DownloadRef ;
46
+ import io .apicurio .registry .rest .v3 .beans .RoleMapping ;
47
+ import io .apicurio .registry .rest .v3 .beans .RoleMappingSearchResults ;
48
+ import io .apicurio .registry .rest .v3 .beans .Rule ;
49
+ import io .apicurio .registry .rest .v3 .beans .UpdateConfigurationProperty ;
50
+ import io .apicurio .registry .rest .v3 .beans .UpdateRole ;
14
51
import io .apicurio .registry .rest .v3 .shared .DataExporter ;
15
52
import io .apicurio .registry .rules .DefaultRuleDeletionException ;
16
53
import io .apicurio .registry .rules .RulesProperties ;
17
54
import io .apicurio .registry .storage .RegistryStorage ;
18
55
import io .apicurio .registry .storage .dto .DownloadContextDto ;
19
56
import io .apicurio .registry .storage .dto .DownloadContextType ;
20
57
import io .apicurio .registry .storage .dto .RoleMappingDto ;
58
+ import io .apicurio .registry .storage .dto .RoleMappingSearchResultsDto ;
21
59
import io .apicurio .registry .storage .dto .RuleConfigurationDto ;
22
60
import io .apicurio .registry .storage .error .ConfigPropertyNotFoundException ;
23
61
import io .apicurio .registry .storage .error .InvalidPropertyValueException ;
24
62
import io .apicurio .registry .storage .error .RuleNotFoundException ;
25
63
import io .apicurio .registry .storage .impexp .EntityInputStream ;
26
64
import io .apicurio .registry .types .Current ;
27
- import io .apicurio .registry .types .RoleType ;
28
65
import io .apicurio .registry .types .RuleType ;
29
66
import io .apicurio .registry .types .provider .ArtifactTypeUtilProviderFactory ;
30
67
import io .apicurio .registry .utils .impexp .Entity ;
36
73
import jakarta .ws .rs .core .Context ;
37
74
import jakarta .ws .rs .core .MediaType ;
38
75
import jakarta .ws .rs .core .Response ;
39
- import org .eclipse .microprofile .config .Config ;
40
- import org .eclipse .microprofile .config .inject .ConfigProperty ;
41
- import org .slf4j .Logger ;
42
-
43
- import java .io .IOException ;
44
- import java .io .InputStream ;
45
- import java .nio .charset .StandardCharsets ;
46
- import java .util .HashMap ;
47
- import java .util .List ;
48
- import java .util .Map ;
49
- import java .util .function .Supplier ;
50
- import java .util .stream .Collectors ;
51
- import java .util .stream .Stream ;
52
- import java .util .zip .ZipInputStream ;
53
-
54
- import static io .apicurio .common .apps .logging .audit .AuditingConstants .*;
55
- import static io .apicurio .registry .util .DtoUtil .appAuthPropertyToRegistry ;
56
- import static io .apicurio .registry .util .DtoUtil .registryAuthPropertyToApp ;
57
76
58
77
@ ApplicationScoped
59
78
@ Interceptors ({ResponseErrorLivenessCheck .class , ResponseTimeoutReadinessCheck .class })
@@ -287,16 +306,21 @@ public void createRoleMapping(RoleMapping data) {
287
306
}
288
307
289
308
/**
290
- * @see io.apicurio.registry.rest.v3.AdminResource#listRoleMappings()
309
+ * @see io.apicurio.registry.rest.v3.AdminResource#listRoleMappings(java.math.BigInteger, java.math.BigInteger )
291
310
*/
292
311
@ Override
293
312
@ Authorized (style =AuthorizedStyle .None , level =AuthorizedLevel .Admin )
294
313
@ RoleBasedAccessApiOperation
295
- public List <RoleMapping > listRoleMappings () {
296
- List <RoleMappingDto > mappings = storage .getRoleMappings ();
297
- return mappings .stream ().map (dto -> {
298
- return dtoToRoleMapping (dto );
299
- }).collect (Collectors .toList ());
314
+ public RoleMappingSearchResults listRoleMappings (BigInteger limit , BigInteger offset ) {
315
+ if (offset == null ) {
316
+ offset = BigInteger .valueOf (0 );
317
+ }
318
+ if (limit == null ) {
319
+ limit = BigInteger .valueOf (20 );
320
+ }
321
+
322
+ RoleMappingSearchResultsDto dto = storage .searchRoleMappings (offset .intValue (), limit .intValue ());
323
+ return V3ApiUtil .dtoToRoleMappingSearchResults (dto );
300
324
}
301
325
302
326
/**
@@ -307,7 +331,7 @@ public List<RoleMapping> listRoleMappings() {
307
331
@ RoleBasedAccessApiOperation
308
332
public RoleMapping getRoleMapping (String principalId ) {
309
333
RoleMappingDto dto = storage .getRoleMapping (principalId );
310
- return dtoToRoleMapping (dto );
334
+ return V3ApiUtil . dtoToRoleMapping (dto );
311
335
}
312
336
313
337
/**
@@ -352,7 +376,7 @@ public List<ConfigurationProperty> listConfigProperties() {
352
376
// on whether the value is actually configured and stored in the DB or not).
353
377
return dynamicPropertyIndex .getAcceptedPropertyNames ().stream ()
354
378
.sorted ((pname1 , pname2 ) -> pname1 .compareTo (pname2 ))
355
- .map (pname -> propsI .containsKey (pname ) ? dtoToConfigurationProperty (dynamicPropertyIndex .getProperty (pname ), propsI .get (pname )) : defToConfigurationProperty (dynamicPropertyIndex .getProperty (pname )))
379
+ .map (pname -> propsI .containsKey (pname ) ? V3ApiUtil . dtoToConfigurationProperty (dynamicPropertyIndex .getProperty (pname ), propsI .get (pname )) : defToConfigurationProperty (dynamicPropertyIndex .getProperty (pname )))
356
380
.collect (Collectors .toList ());
357
381
}
358
382
@@ -369,7 +393,7 @@ public ConfigurationProperty getConfigProperty(String propertyName) {
369
393
if (dto == null ) {
370
394
return defToConfigurationProperty (def );
371
395
} else {
372
- return dtoToConfigurationProperty (def , dto );
396
+ return V3ApiUtil . dtoToConfigurationProperty (def , dto );
373
397
}
374
398
}
375
399
@@ -401,14 +425,6 @@ public void resetConfigProperty(String propertyName) {
401
425
storage .deleteConfigProperty (propertyName );
402
426
}
403
427
404
- private static RoleMapping dtoToRoleMapping (RoleMappingDto dto ) {
405
- RoleMapping mapping = new RoleMapping ();
406
- mapping .setPrincipalId (dto .getPrincipalId ());
407
- mapping .setRole (RoleType .valueOf (dto .getRole ()));
408
- mapping .setPrincipalName (dto .getPrincipalName ());
409
- return mapping ;
410
- }
411
-
412
428
413
429
private static boolean isNullOrTrue (Boolean value ) {
414
430
return value == null || value ;
@@ -418,16 +434,6 @@ private String createDownloadHref(String downloadId) {
418
434
return "/apis/registry/v3/downloads/" + downloadId ;
419
435
}
420
436
421
- private static ConfigurationProperty dtoToConfigurationProperty (DynamicConfigPropertyDef def , DynamicConfigPropertyDto dto ) {
422
- ConfigurationProperty rval = new ConfigurationProperty ();
423
- rval .setName (def .getName ());
424
- rval .setValue (dto .getValue ());
425
- rval .setType (def .getType ().getName ());
426
- rval .setLabel (def .getLabel ());
427
- rval .setDescription (def .getDescription ());
428
- return rval ;
429
- }
430
-
431
437
private ConfigurationProperty defToConfigurationProperty (DynamicConfigPropertyDef def ) {
432
438
String propertyValue = config .getOptionalValue (def .getName (), String .class ).orElse (def .getDefaultValue ());
433
439
0 commit comments