@@ -75,8 +75,7 @@ public class AppSecConfigServiceImpl implements AppSecConfigService {
75
75
private final ConfigurationPoller configurationPoller ;
76
76
private WafBuilder wafBuilder ;
77
77
78
- private MergedAsmFeatures mergedAsmFeatures ;
79
- private volatile boolean initialized ;
78
+ private final MergedAsmFeatures mergedAsmFeatures = new MergedAsmFeatures ();
80
79
81
80
private final ConcurrentHashMap <String , SubconfigListener > subconfigListeners =
82
81
new ConcurrentHashMap <>();
@@ -173,9 +172,7 @@ private class AppSecConfigChangesListener implements ProductListener {
173
172
@ Override
174
173
public void accept (ConfigKey configKey , byte [] content , PollingRateHinter pollingRateHinter )
175
174
throws IOException {
176
- if (!initialized ) {
177
- throw new IllegalStateException ();
178
- }
175
+ maybeInitializeDefaultConfig ();
179
176
180
177
if (content == null ) {
181
178
try {
@@ -219,8 +216,8 @@ public void accept(ConfigKey configKey, byte[] content, PollingRateHinter pollin
219
216
}
220
217
defaultConfigActivated = false ;
221
218
}
222
- super .accept (configKey , content , pollingRateHinter );
223
219
usedDDWafConfigKeys .add (configKey .toString ());
220
+ super .accept (configKey , content , pollingRateHinter );
224
221
}
225
222
226
223
@ Override
@@ -282,13 +279,7 @@ private void subscribeAsmFeatures() {
282
279
Product .ASM_FEATURES ,
283
280
AppSecFeaturesDeserializer .INSTANCE ,
284
281
(configKey , newConfig , hinter ) -> {
285
- if (!hasUserWafConfig && !defaultConfigActivated ) {
286
- // features activated in runtime
287
- init ();
288
- }
289
- if (!initialized ) {
290
- throw new IllegalStateException ();
291
- }
282
+ maybeInitializeDefaultConfig ();
292
283
if (newConfig == null ) {
293
284
mergedAsmFeatures .removeConfig (configKey );
294
285
} else {
@@ -305,10 +296,7 @@ private void subscribeAsmFeatures() {
305
296
306
297
private void distributeSubConfigurations (
307
298
String key , AppSecModuleConfigurer .Reconfiguration reconfiguration ) {
308
- if (usedDDWafConfigKeys .isEmpty () && !defaultConfigActivated && !hasUserWafConfig ) {
309
- // no config left in the WAF builder, add the default config
310
- init ();
311
- }
299
+ maybeInitializeDefaultConfig ();
312
300
for (Map .Entry <String , SubconfigListener > entry : subconfigListeners .entrySet ()) {
313
301
SubconfigListener listener = entry .getValue ();
314
302
try {
@@ -320,6 +308,13 @@ private void distributeSubConfigurations(
320
308
}
321
309
}
322
310
311
+ private void maybeInitializeDefaultConfig () {
312
+ if (usedDDWafConfigKeys .isEmpty () && !hasUserWafConfig && !defaultConfigActivated ) {
313
+ // no config left in the WAF builder, add the default config
314
+ init ();
315
+ }
316
+ }
317
+
323
318
@ Override
324
319
public void init () {
325
320
Map <String , Object > wafConfig ;
@@ -341,8 +336,8 @@ public void init() {
341
336
} else {
342
337
hasUserWafConfig = true ;
343
338
}
344
- this .mergedAsmFeatures = new MergedAsmFeatures ();
345
- this .initialized = true ;
339
+ this .mergedAsmFeatures . clear ();
340
+ this .usedDDWafConfigKeys . clear () ;
346
341
347
342
if (wafConfig .isEmpty ()) {
348
343
throw new IllegalStateException ("Expected default waf config to be available" );
0 commit comments