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 ;
235237import static org .elasticsearch .cluster .metadata .IndexMetaData .INDEX_FORMAT_SETTING ;
236238import static org .elasticsearch .xpack .core .XPackSettings .HTTP_SSL_ENABLED ;
237239import static org .elasticsearch .xpack .security .support .SecurityIndexManager .SECURITY_TEMPLATE_NAME ;
238- import static org .elasticsearch .xpack .security .SecurityLifecycleService .SECURITY_INDEX_NAME ;
240+ import static org .elasticsearch .xpack .security .support . SecurityIndexManager .SECURITY_INDEX_NAME ;
239241import static org .elasticsearch .xpack .security .support .SecurityIndexManager .INTERNAL_INDEX_FORMAT ;
240242
241243public class Security extends Plugin implements ActionPlugin , IngestPlugin , NetworkPlugin , ClusterPlugin , DiscoveryPlugin , MapperPlugin ,
@@ -271,6 +273,8 @@ public class Security extends Plugin implements ActionPlugin, IngestPlugin, Netw
271273 private final SetOnce <ThreadContext > threadContext = new SetOnce <>();
272274 private final SetOnce <TokenService > tokenService = new SetOnce <>();
273275 private final SetOnce <SecurityActionFilter > securityActionFilter = new SetOnce <>();
276+ private final SetOnce <SecurityIndexManager > securityIndex = new SetOnce <>();
277+ private final SetOnce <IndexAuditTrail > indexAuditTrail = new SetOnce <>();
274278 private final List <BootstrapCheck > bootstrapChecks ;
275279 private final List <SecurityExtension > securityExtensions = new ArrayList <>();
276280 private volatile boolean indicesAdminFilteredFields ;
@@ -386,7 +390,6 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
386390 components .add (securityContext .get ());
387391
388392 // audit trails construction
389- IndexAuditTrail indexAuditTrail = null ;
390393 Set <AuditTrail > auditTrails = new LinkedHashSet <>();
391394 if (XPackSettings .AUDIT_ENABLED .get (settings )) {
392395 List <String > outputs = AUDIT_OUTPUTS_SETTING .get (settings );
@@ -401,8 +404,8 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
401404 auditTrails .add (new LoggingAuditTrail (settings , clusterService , threadPool ));
402405 break ;
403406 case IndexAuditTrail .NAME :
404- indexAuditTrail = new IndexAuditTrail (settings , client , threadPool , clusterService );
405- auditTrails .add (indexAuditTrail );
407+ indexAuditTrail . set ( new IndexAuditTrail (settings , client , threadPool , clusterService ) );
408+ auditTrails .add (indexAuditTrail . get () );
406409 break ;
407410 default :
408411 throw new IllegalArgumentException ("Unknown audit trail output [" + output + "]" );
@@ -414,20 +417,20 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
414417 components .add (auditTrailService );
415418 this .auditTrailService .set (auditTrailService );
416419
417- final SecurityLifecycleService securityLifecycleService =
418- new SecurityLifecycleService ( settings , clusterService , threadPool , client , indexAuditTrail );
419- final TokenService tokenService = new TokenService (settings , Clock .systemUTC (), client , securityLifecycleService , clusterService );
420+ securityIndex . set ( new SecurityIndexManager ( settings , client , SecurityIndexManager . SECURITY_INDEX_NAME , clusterService ));
421+
422+ final TokenService tokenService = new TokenService (settings , Clock .systemUTC (), client , securityIndex . get () , clusterService );
420423 this .tokenService .set (tokenService );
421424 components .add (tokenService );
422425
423426 // realms construction
424- final NativeUsersStore nativeUsersStore = new NativeUsersStore (settings , client , securityLifecycleService );
425- final NativeRoleMappingStore nativeRoleMappingStore = new NativeRoleMappingStore (settings , client , securityLifecycleService );
427+ final NativeUsersStore nativeUsersStore = new NativeUsersStore (settings , client , securityIndex . get () );
428+ final NativeRoleMappingStore nativeRoleMappingStore = new NativeRoleMappingStore (settings , client , securityIndex . get () );
426429 final AnonymousUser anonymousUser = new AnonymousUser (settings );
427430 final ReservedRealm reservedRealm = new ReservedRealm (env , settings , nativeUsersStore ,
428- anonymousUser , securityLifecycleService , threadPool .getThreadContext ());
431+ anonymousUser , securityIndex . get () , threadPool .getThreadContext ());
429432 Map <String , Realm .Factory > realmFactories = new HashMap <>(InternalRealms .getFactories (threadPool , resourceWatcherService ,
430- getSslService (), nativeUsersStore , nativeRoleMappingStore , securityLifecycleService ));
433+ getSslService (), nativeUsersStore , nativeRoleMappingStore , securityIndex . get () ));
431434 for (SecurityExtension extension : securityExtensions ) {
432435 Map <String , Realm .Factory > newRealms = extension .getRealms (resourceWatcherService );
433436 for (Map .Entry <String , Realm .Factory > entry : newRealms .entrySet ()) {
@@ -442,7 +445,7 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
442445 components .add (realms );
443446 components .add (reservedRealm );
444447
445- securityLifecycleService . securityIndex ().addIndexStateListener (nativeRoleMappingStore ::onSecurityIndexStateChange );
448+ securityIndex . get ().addIndexStateListener (nativeRoleMappingStore ::onSecurityIndexStateChange );
446449
447450 AuthenticationFailureHandler failureHandler = null ;
448451 String extensionName = null ;
@@ -466,15 +469,15 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
466469 components .add (authcService .get ());
467470
468471 final FileRolesStore fileRolesStore = new FileRolesStore (settings , env , resourceWatcherService , getLicenseState ());
469- final NativeRolesStore nativeRolesStore = new NativeRolesStore (settings , client , getLicenseState (), securityLifecycleService );
472+ final NativeRolesStore nativeRolesStore = new NativeRolesStore (settings , client , getLicenseState (), securityIndex . get () );
470473 final ReservedRolesStore reservedRolesStore = new ReservedRolesStore ();
471474 List <BiConsumer <Set <String >, ActionListener <Set <RoleDescriptor >>>> rolesProviders = new ArrayList <>();
472475 for (SecurityExtension extension : securityExtensions ) {
473476 rolesProviders .addAll (extension .getRolesProviders (settings , resourceWatcherService ));
474477 }
475478 final CompositeRolesStore allRolesStore = new CompositeRolesStore (settings , fileRolesStore , nativeRolesStore ,
476479 reservedRolesStore , rolesProviders , threadPool .getThreadContext (), getLicenseState ());
477- securityLifecycleService . securityIndex ().addIndexStateListener (allRolesStore ::onSecurityIndexStateChange );
480+ securityIndex . get ().addIndexStateListener (allRolesStore ::onSecurityIndexStateChange );
478481 // to keep things simple, just invalidate all cached entries on license change. this happens so rarely that the impact should be
479482 // minimal
480483 getLicenseState ().addListener (allRolesStore ::invalidateAll );
@@ -485,8 +488,6 @@ Collection<Object> createComponents(Client client, ThreadPool threadPool, Cluste
485488 components .add (allRolesStore ); // for SecurityFeatureSet and clear roles cache
486489 components .add (authzService );
487490
488- components .add (securityLifecycleService );
489-
490491 ipFilter .set (new IPFilter (settings , auditTrailService , clusterService .getClusterSettings (), getLicenseState ()));
491492 components .add (ipFilter .get ());
492493 DestructiveOperations destructiveOperations = new DestructiveOperations (settings , clusterService .getClusterSettings ());
0 commit comments