77
88import org .apache .logging .log4j .Logger ;
99import org .apache .lucene .util .SetOnce ;
10+ import org .elasticsearch .ElasticsearchTimeoutException ;
1011import org .elasticsearch .Version ;
1112import org .elasticsearch .action .ActionListener ;
1213import org .elasticsearch .action .ActionRequest ;
1617import org .elasticsearch .bootstrap .BootstrapCheck ;
1718import org .elasticsearch .client .Client ;
1819import org .elasticsearch .cluster .ClusterState ;
20+ import org .elasticsearch .cluster .health .ClusterHealthStatus ;
1921import org .elasticsearch .cluster .metadata .IndexMetaData ;
2022import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
2123import org .elasticsearch .cluster .metadata .IndexTemplateMetaData ;
232234import static org .elasticsearch .cluster .metadata .IndexMetaData .INDEX_FORMAT_SETTING ;
233235import static org .elasticsearch .xpack .core .XPackSettings .HTTP_SSL_ENABLED ;
234236import 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 ;
236238import static org .elasticsearch .xpack .security .support .SecurityIndexManager .INTERNAL_INDEX_FORMAT ;
237239
238240public class Security extends Plugin implements ActionPlugin , IngestPlugin , NetworkPlugin , ClusterPlugin ,
@@ -261,6 +263,8 @@ public class Security extends Plugin implements ActionPlugin, IngestPlugin, Netw
261263 private final SetOnce <ThreadContext > threadContext = new SetOnce <>();
262264 private final SetOnce <TokenService > tokenService = new SetOnce <>();
263265 private final SetOnce <SecurityActionFilter > securityActionFilter = new SetOnce <>();
266+ private final SetOnce <SecurityIndexManager > securityIndex = new SetOnce <>();
267+ private final SetOnce <IndexAuditTrail > indexAuditTrail = new SetOnce <>();
264268 private final List <BootstrapCheck > bootstrapChecks ;
265269 private final List <SecurityExtension > securityExtensions = new ArrayList <>();
266270
@@ -368,7 +372,6 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
368372 components .add (securityContext .get ());
369373
370374 // audit trails construction
371- IndexAuditTrail indexAuditTrail = null ;
372375 Set <AuditTrail > auditTrails = new LinkedHashSet <>();
373376 if (XPackSettings .AUDIT_ENABLED .get (settings )) {
374377 List <String > outputs = AUDIT_OUTPUTS_SETTING .get (settings );
@@ -383,8 +386,8 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
383386 auditTrails .add (new LoggingAuditTrail (settings , clusterService , threadPool ));
384387 break ;
385388 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 () );
388391 break ;
389392 default :
390393 throw new IllegalArgumentException ("Unknown audit trail output [" + output + "]" );
@@ -396,20 +399,20 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
396399 components .add (auditTrailService );
397400 this .auditTrailService .set (auditTrailService );
398401
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 );
402405 this .tokenService .set (tokenService );
403406 components .add (tokenService );
404407
405408 // 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 () );
408411 final AnonymousUser anonymousUser = new AnonymousUser (settings );
409412 final ReservedRealm reservedRealm = new ReservedRealm (env , settings , nativeUsersStore ,
410- anonymousUser , securityLifecycleService , threadPool .getThreadContext ());
413+ anonymousUser , securityIndex . get () , threadPool .getThreadContext ());
411414 Map <String , Realm .Factory > realmFactories = new HashMap <>(InternalRealms .getFactories (threadPool , resourceWatcherService ,
412- getSslService (), nativeUsersStore , nativeRoleMappingStore , securityLifecycleService ));
415+ getSslService (), nativeUsersStore , nativeRoleMappingStore , securityIndex . get () ));
413416 for (SecurityExtension extension : securityExtensions ) {
414417 Map <String , Realm .Factory > newRealms = extension .getRealms (resourceWatcherService );
415418 for (Map .Entry <String , Realm .Factory > entry : newRealms .entrySet ()) {
@@ -424,7 +427,7 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
424427 components .add (realms );
425428 components .add (reservedRealm );
426429
427- securityLifecycleService . securityIndex ().addIndexStateListener (nativeRoleMappingStore ::onSecurityIndexStateChange );
430+ securityIndex . get ().addIndexStateListener (nativeRoleMappingStore ::onSecurityIndexStateChange );
428431
429432 AuthenticationFailureHandler failureHandler = null ;
430433 String extensionName = null ;
@@ -449,15 +452,15 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
449452 components .add (authcService .get ());
450453
451454 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 () );
453456 final ReservedRolesStore reservedRolesStore = new ReservedRolesStore ();
454457 List <BiConsumer <Set <String >, ActionListener <Set <RoleDescriptor >>>> rolesProviders = new ArrayList <>();
455458 for (SecurityExtension extension : securityExtensions ) {
456459 rolesProviders .addAll (extension .getRolesProviders (settings , resourceWatcherService ));
457460 }
458461 final CompositeRolesStore allRolesStore = new CompositeRolesStore (settings , fileRolesStore , nativeRolesStore ,
459462 reservedRolesStore , rolesProviders , threadPool .getThreadContext (), getLicenseState ());
460- securityLifecycleService . securityIndex ().addIndexStateListener (allRolesStore ::onSecurityIndexStateChange );
463+ securityIndex . get ().addIndexStateListener (allRolesStore ::onSecurityIndexStateChange );
461464 // to keep things simple, just invalidate all cached entries on license change. this happens so rarely that the impact should be
462465 // minimal
463466 getLicenseState ().addListener (allRolesStore ::invalidateAll );
@@ -468,8 +471,6 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
468471 components .add (allRolesStore ); // for SecurityFeatureSet and clear roles cache
469472 components .add (authzService );
470473
471- components .add (securityLifecycleService );
472-
473474 ipFilter .set (new IPFilter (settings , auditTrailService , clusterService .getClusterSettings (), getLicenseState ()));
474475 components .add (ipFilter .get ());
475476 DestructiveOperations destructiveOperations = new DestructiveOperations (settings , clusterService .getClusterSettings ());
0 commit comments