@@ -1102,18 +1102,9 @@ Collection<Object> createComponents(
11021102 operatorPrivilegesService .set (OperatorPrivileges .NOOP_OPERATOR_PRIVILEGES_SERVICE );
11031103 }
11041104
1105- // TODO ensure internal extensions only
1106- SetOnce <CloudApiKeyService > cloudApiKeyService = new SetOnce <>();
1107- for (var extension : securityExtensions ) {
1108- CloudApiKeyService inner = extension .getCloudApiKeyService (extensionComponents );
1109- if (inner != null ) {
1110- cloudApiKeyService .set (inner );
1111- }
1112- }
1113- if (cloudApiKeyService .get () == null ) {
1114- cloudApiKeyService .set (new CloudApiKeyService .Noop ());
1115- }
1116- components .add (cloudApiKeyService .get ());
1105+ final CloudApiKeyService cloudApiKeyService = createCloudApiKeyService (extensionComponents );
1106+
1107+ components .add (cloudApiKeyService );
11171108
11181109 authcService .set (
11191110 new AuthenticationService (
@@ -1127,7 +1118,7 @@ Collection<Object> createComponents(
11271118 apiKeyService ,
11281119 serviceAccountService ,
11291120 operatorPrivilegesService .get (),
1130- cloudApiKeyService . get () ,
1121+ cloudApiKeyService ,
11311122 telemetryProvider .getMeterRegistry ()
11321123 )
11331124 );
@@ -1263,6 +1254,37 @@ Collection<Object> createComponents(
12631254 return components ;
12641255 }
12651256
1257+ private CloudApiKeyService createCloudApiKeyService (SecurityExtension .SecurityComponents extensionComponents ) {
1258+ final SetOnce <CloudApiKeyService > cloudApiKeyServiceSetOnce = new SetOnce <>();
1259+ for (var extension : securityExtensions ) {
1260+ final CloudApiKeyService cloudApiKeyService = extension .getCloudApiKeyService (extensionComponents );
1261+ if (cloudApiKeyService != null ) {
1262+ if (false == isInternalExtension (extension )) {
1263+ throw new IllegalStateException (
1264+ "The ["
1265+ + extension .getClass ().getName ()
1266+ + "] extension tried to install a custom CloudApiKeyService. "
1267+ + "This functionality is not available to external extensions."
1268+ );
1269+ }
1270+ boolean success = cloudApiKeyServiceSetOnce .trySet (cloudApiKeyService );
1271+ if (false == success ) {
1272+ throw new IllegalStateException (
1273+ "The ["
1274+ + extension .getClass ().getName ()
1275+ + "] extension tried to install a custom CloudApiKeyService, but one has already been installed."
1276+ );
1277+ } else {
1278+ logger .debug ("CloudApiKeyService provided by extension [{}]" , extension .extensionName ());
1279+ }
1280+ }
1281+ }
1282+ if (cloudApiKeyServiceSetOnce .get () == null ) {
1283+ cloudApiKeyServiceSetOnce .set (new CloudApiKeyService .Noop ());
1284+ }
1285+ return cloudApiKeyServiceSetOnce .get ();
1286+ }
1287+
12661288 private ServiceAccountService createServiceAccountService (
12671289 List <Object > components ,
12681290 CacheInvalidatorRegistry cacheInvalidatorRegistry ,
0 commit comments