7
7
8
8
import org .apache .logging .log4j .Logger ;
9
9
import org .apache .lucene .util .SetOnce ;
10
+ import org .elasticsearch .ElasticsearchTimeoutException ;
10
11
import org .elasticsearch .Version ;
11
12
import org .elasticsearch .action .ActionListener ;
12
13
import org .elasticsearch .action .ActionRequest ;
16
17
import org .elasticsearch .bootstrap .BootstrapCheck ;
17
18
import org .elasticsearch .client .Client ;
18
19
import org .elasticsearch .cluster .ClusterState ;
20
+ import org .elasticsearch .cluster .health .ClusterHealthStatus ;
19
21
import org .elasticsearch .cluster .metadata .IndexMetaData ;
20
22
import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
21
23
import org .elasticsearch .cluster .metadata .IndexTemplateMetaData ;
232
234
import static org .elasticsearch .cluster .metadata .IndexMetaData .INDEX_FORMAT_SETTING ;
233
235
import static org .elasticsearch .xpack .core .XPackSettings .HTTP_SSL_ENABLED ;
234
236
import static org .elasticsearch .xpack .security .support .SecurityIndexManager .SECURITY_TEMPLATE_NAME ;
235
- import static org .elasticsearch .xpack .security .SecurityLifecycleService .SECURITY_INDEX_NAME ;
237
+ import static org .elasticsearch .xpack .security .support . SecurityIndexManager .SECURITY_INDEX_NAME ;
236
238
import static org .elasticsearch .xpack .security .support .SecurityIndexManager .INTERNAL_INDEX_FORMAT ;
237
239
238
240
public class Security extends Plugin implements ActionPlugin , IngestPlugin , NetworkPlugin , ClusterPlugin ,
@@ -261,6 +263,8 @@ public class Security extends Plugin implements ActionPlugin, IngestPlugin, Netw
261
263
private final SetOnce <ThreadContext > threadContext = new SetOnce <>();
262
264
private final SetOnce <TokenService > tokenService = new SetOnce <>();
263
265
private final SetOnce <SecurityActionFilter > securityActionFilter = new SetOnce <>();
266
+ private final SetOnce <SecurityIndexManager > securityIndex = new SetOnce <>();
267
+ private final SetOnce <IndexAuditTrail > indexAuditTrail = new SetOnce <>();
264
268
private final List <BootstrapCheck > bootstrapChecks ;
265
269
private final List <SecurityExtension > securityExtensions = new ArrayList <>();
266
270
@@ -368,7 +372,6 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
368
372
components .add (securityContext .get ());
369
373
370
374
// audit trails construction
371
- IndexAuditTrail indexAuditTrail = null ;
372
375
Set <AuditTrail > auditTrails = new LinkedHashSet <>();
373
376
if (XPackSettings .AUDIT_ENABLED .get (settings )) {
374
377
List <String > outputs = AUDIT_OUTPUTS_SETTING .get (settings );
@@ -383,8 +386,8 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
383
386
auditTrails .add (new LoggingAuditTrail (settings , clusterService , threadPool ));
384
387
break ;
385
388
case IndexAuditTrail .NAME :
386
- indexAuditTrail = new IndexAuditTrail (settings , client , threadPool , clusterService );
387
- auditTrails .add (indexAuditTrail );
389
+ indexAuditTrail . set ( new IndexAuditTrail (settings , client , threadPool , clusterService ) );
390
+ auditTrails .add (indexAuditTrail . get () );
388
391
break ;
389
392
default :
390
393
throw new IllegalArgumentException ("Unknown audit trail output [" + output + "]" );
@@ -396,20 +399,20 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
396
399
components .add (auditTrailService );
397
400
this .auditTrailService .set (auditTrailService );
398
401
399
- final SecurityLifecycleService securityLifecycleService =
400
- new SecurityLifecycleService ( settings , clusterService , threadPool , client , indexAuditTrail );
401
- final TokenService tokenService = new TokenService (settings , Clock .systemUTC (), client , securityLifecycleService , clusterService );
402
+ securityIndex . set ( new SecurityIndexManager ( settings , client , SecurityIndexManager . SECURITY_INDEX_NAME , clusterService ));
403
+
404
+ final TokenService tokenService = new TokenService (settings , Clock .systemUTC (), client , securityIndex . get () , clusterService );
402
405
this .tokenService .set (tokenService );
403
406
components .add (tokenService );
404
407
405
408
// realms construction
406
- final NativeUsersStore nativeUsersStore = new NativeUsersStore (settings , client , securityLifecycleService );
407
- final NativeRoleMappingStore nativeRoleMappingStore = new NativeRoleMappingStore (settings , client , securityLifecycleService );
409
+ final NativeUsersStore nativeUsersStore = new NativeUsersStore (settings , client , securityIndex . get () );
410
+ final NativeRoleMappingStore nativeRoleMappingStore = new NativeRoleMappingStore (settings , client , securityIndex . get () );
408
411
final AnonymousUser anonymousUser = new AnonymousUser (settings );
409
412
final ReservedRealm reservedRealm = new ReservedRealm (env , settings , nativeUsersStore ,
410
- anonymousUser , securityLifecycleService , threadPool .getThreadContext ());
413
+ anonymousUser , securityIndex . get () , threadPool .getThreadContext ());
411
414
Map <String , Realm .Factory > realmFactories = new HashMap <>(InternalRealms .getFactories (threadPool , resourceWatcherService ,
412
- getSslService (), nativeUsersStore , nativeRoleMappingStore , securityLifecycleService ));
415
+ getSslService (), nativeUsersStore , nativeRoleMappingStore , securityIndex . get () ));
413
416
for (SecurityExtension extension : securityExtensions ) {
414
417
Map <String , Realm .Factory > newRealms = extension .getRealms (resourceWatcherService );
415
418
for (Map .Entry <String , Realm .Factory > entry : newRealms .entrySet ()) {
@@ -424,7 +427,7 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
424
427
components .add (realms );
425
428
components .add (reservedRealm );
426
429
427
- securityLifecycleService . securityIndex ().addIndexStateListener (nativeRoleMappingStore ::onSecurityIndexStateChange );
430
+ securityIndex . get ().addIndexStateListener (nativeRoleMappingStore ::onSecurityIndexStateChange );
428
431
429
432
AuthenticationFailureHandler failureHandler = null ;
430
433
String extensionName = null ;
@@ -449,15 +452,15 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
449
452
components .add (authcService .get ());
450
453
451
454
final FileRolesStore fileRolesStore = new FileRolesStore (settings , env , resourceWatcherService , getLicenseState ());
452
- final NativeRolesStore nativeRolesStore = new NativeRolesStore (settings , client , getLicenseState (), securityLifecycleService );
455
+ final NativeRolesStore nativeRolesStore = new NativeRolesStore (settings , client , getLicenseState (), securityIndex . get () );
453
456
final ReservedRolesStore reservedRolesStore = new ReservedRolesStore ();
454
457
List <BiConsumer <Set <String >, ActionListener <Set <RoleDescriptor >>>> rolesProviders = new ArrayList <>();
455
458
for (SecurityExtension extension : securityExtensions ) {
456
459
rolesProviders .addAll (extension .getRolesProviders (settings , resourceWatcherService ));
457
460
}
458
461
final CompositeRolesStore allRolesStore = new CompositeRolesStore (settings , fileRolesStore , nativeRolesStore ,
459
462
reservedRolesStore , rolesProviders , threadPool .getThreadContext (), getLicenseState ());
460
- securityLifecycleService . securityIndex ().addIndexStateListener (allRolesStore ::onSecurityIndexStateChange );
463
+ securityIndex . get ().addIndexStateListener (allRolesStore ::onSecurityIndexStateChange );
461
464
// to keep things simple, just invalidate all cached entries on license change. this happens so rarely that the impact should be
462
465
// minimal
463
466
getLicenseState ().addListener (allRolesStore ::invalidateAll );
@@ -468,8 +471,6 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
468
471
components .add (allRolesStore ); // for SecurityFeatureSet and clear roles cache
469
472
components .add (authzService );
470
473
471
- components .add (securityLifecycleService );
472
-
473
474
ipFilter .set (new IPFilter (settings , auditTrailService , clusterService .getClusterSettings (), getLicenseState ()));
474
475
components .add (ipFilter .get ());
475
476
DestructiveOperations destructiveOperations = new DestructiveOperations (settings , clusterService .getClusterSettings ());
0 commit comments