6
6
package org .elasticsearch .license ;
7
7
8
8
import org .apache .logging .log4j .LogManager ;
9
+ import org .apache .logging .log4j .Logger ;
9
10
import org .elasticsearch .Version ;
10
11
import org .elasticsearch .common .Nullable ;
11
12
import org .elasticsearch .common .Strings ;
13
+ import org .elasticsearch .common .logging .DeprecationLogger ;
12
14
import org .elasticsearch .common .logging .LoggerMessageFormat ;
13
15
import org .elasticsearch .common .settings .Settings ;
14
16
import org .elasticsearch .license .License .OperationMode ;
@@ -266,30 +268,56 @@ private static class Status {
266
268
}
267
269
}
268
270
271
+ private final Logger logger ;
272
+ private final DeprecationLogger deprecationLogger ;
269
273
private final List <LicenseStateListener > listeners ;
274
+
270
275
private final boolean isSecurityEnabled ;
271
276
private final boolean isSecurityExplicitlyEnabled ;
272
277
273
278
private Status status = new Status (OperationMode .TRIAL , true );
274
279
private boolean isSecurityEnabledByTrialVersion ;
275
280
276
281
public XPackLicenseState (Settings settings ) {
282
+ this .logger = LogManager .getLogger (getClass ());
283
+ this .deprecationLogger = new DeprecationLogger (logger );
277
284
this .listeners = new CopyOnWriteArrayList <>();
278
285
this .isSecurityEnabled = XPackSettings .SECURITY_ENABLED .get (settings );
279
- // 6.0+ requires TLS for production licenses, so if TLS is enabled and security is enabled
280
- // we can interpret this as an explicit enabling of security if the security enabled
281
- // setting is not explicitly set
282
- this .isSecurityExplicitlyEnabled = isSecurityEnabled &&
283
- (settings .hasValue (XPackSettings .SECURITY_ENABLED .getKey ()) || XPackSettings .TRANSPORT_SSL_ENABLED .get (settings ));
286
+ this .isSecurityExplicitlyEnabled = checkSecurityExplicitlyEnabled (settings );
284
287
this .isSecurityEnabledByTrialVersion = false ;
285
288
}
286
289
290
+ /**
291
+ * 6.0+ requires TLS for production licenses, so if TLS is enabled and security is enabled
292
+ * we can interpret this as an explicit enabling of security if the security enabled
293
+ * setting is not explicitly set.
294
+ * This behaviour is deprecated, and will be removed in 7.0
295
+ */
296
+ private boolean checkSecurityExplicitlyEnabled (Settings settings ) {
297
+ if (isSecurityEnabled ) {
298
+ if (settings .hasValue (XPackSettings .SECURITY_ENABLED .getKey ())) {
299
+ return true ;
300
+ }
301
+ if (XPackSettings .TRANSPORT_SSL_ENABLED .get (settings )) {
302
+ deprecationLogger .deprecated ("Automatically enabling security because [{}] is true. " +
303
+ "This behaviour will be removed in a future version of Elasticsearch. " +
304
+ "Please set [{}] to true" ,
305
+ XPackSettings .TRANSPORT_SSL_ENABLED .getKey (),
306
+ XPackSettings .SECURITY_ENABLED .getKey ());
307
+ return true ;
308
+ }
309
+ }
310
+ return false ;
311
+ }
312
+
287
313
private XPackLicenseState (XPackLicenseState xPackLicenseState ) {
288
314
this .listeners = xPackLicenseState .listeners ;
289
315
this .isSecurityEnabled = xPackLicenseState .isSecurityEnabled ;
290
316
this .isSecurityExplicitlyEnabled = xPackLicenseState .isSecurityExplicitlyEnabled ;
291
317
this .status = xPackLicenseState .status ;
292
318
this .isSecurityEnabledByTrialVersion = xPackLicenseState .isSecurityEnabledByTrialVersion ;
319
+ this .logger = xPackLicenseState .logger ;
320
+ this .deprecationLogger = xPackLicenseState .deprecationLogger ;
293
321
}
294
322
295
323
/**
@@ -309,8 +337,12 @@ void update(OperationMode mode, boolean active, @Nullable Version mostRecentTria
309
337
// Before 6.3, Trial licenses would default having security enabled.
310
338
// If this license was generated before that version, then treat it as if security is explicitly enabled
311
339
if (mostRecentTrialVersion == null || mostRecentTrialVersion .before (Version .V_6_3_0 )) {
312
- LogManager . getLogger ( getClass ()) .info ("Automatically enabling security for older trial license ({})" ,
340
+ logger .info ("Automatically enabling security for older trial license ({})" ,
313
341
mostRecentTrialVersion == null ? "[pre 6.1.0]" : mostRecentTrialVersion .toString ());
342
+ deprecationLogger .deprecated (
343
+ "Automatically enabling security because the current trial license was generated before 6.3.0. " +
344
+ "This behaviour will be removed in a future version of Elasticsearch. " +
345
+ "Please set [{}] to true" , XPackSettings .SECURITY_ENABLED .getKey ());
314
346
isSecurityEnabledByTrialVersion = true ;
315
347
}
316
348
}
0 commit comments