201201import org .elasticsearch .xpack .core .security .authc .RealmConfig ;
202202import org .elasticsearch .xpack .core .security .authc .RealmSettings ;
203203import org .elasticsearch .xpack .core .security .authc .Subject ;
204- import org .elasticsearch .xpack .core .security .authc .apikey .CustomTokenAuthenticator ;
204+ import org .elasticsearch .xpack .core .security .authc .apikey .CustomAuthenticator ;
205205import org .elasticsearch .xpack .core .security .authc .service .NodeLocalServiceAccountTokenStore ;
206206import org .elasticsearch .xpack .core .security .authc .service .ServiceAccountTokenStore ;
207207import org .elasticsearch .xpack .core .security .authc .support .UserRoleMapper ;
@@ -1068,9 +1068,7 @@ Collection<Object> createComponents(
10681068 operatorPrivilegesService .set (OperatorPrivileges .NOOP_OPERATOR_PRIVILEGES_SERVICE );
10691069 }
10701070
1071- final Collection <CustomTokenAuthenticator > customTokenAuthenticator = createCustomApiKeyAuthenticator (extensionComponents );
1072-
1073- components .add (customTokenAuthenticator );
1071+ final List <CustomAuthenticator > customAuthenticators = getCustomAuthenticatorFromExtensions (extensionComponents );
10741072
10751073 authcService .set (
10761074 new AuthenticationService (
@@ -1084,7 +1082,7 @@ Collection<Object> createComponents(
10841082 apiKeyService ,
10851083 serviceAccountService ,
10861084 operatorPrivilegesService .get (),
1087- customTokenAuthenticator ,
1085+ customAuthenticators ,
10881086 telemetryProvider .getMeterRegistry ()
10891087 )
10901088 );
@@ -1220,47 +1218,48 @@ Collection<Object> createComponents(
12201218 return components ;
12211219 }
12221220
1223- private List <CustomTokenAuthenticator > createCustomApiKeyAuthenticator (SecurityExtension .SecurityComponents extensionComponents ) {
1224- final Map <String , List <CustomTokenAuthenticator >> customApiKeyAuthenticatorByExtension = new HashMap <>();
1225- for (final SecurityExtension extension : securityExtensions ) {
1226- final List <CustomTokenAuthenticator > customTokenAuthenticator = extension . getCustomApiKeyAuthenticator (extensionComponents );
1227- if (customTokenAuthenticator != null ) {
1228- if (false == isInternalExtension (extension )) {
1221+ private List <CustomAuthenticator > getCustomAuthenticatorFromExtensions (SecurityExtension .SecurityComponents extensionComponents ) {
1222+ final Map <String , List <CustomAuthenticator >> customAuthenticatorsByExtension = new HashMap <>();
1223+ for (final SecurityExtension securityExtension : securityExtensions ) {
1224+ final List <CustomAuthenticator > customAuthenticators = securityExtension . getCustomAuthenticators (extensionComponents );
1225+ if (customAuthenticators != null ) {
1226+ if (false == isInternalExtension (securityExtension )) {
12291227 throw new IllegalStateException (
12301228 "The ["
1231- + extension .extensionName ()
1232- + "] extension tried to install a custom CustomApiKeyAuthenticator. "
1229+ + securityExtension .extensionName ()
1230+ + "] extension tried to install a "
1231+ + CustomAuthenticator .class .getSimpleName ()
1232+ + ". "
12331233 + "This functionality is not available to external extensions."
12341234 );
12351235 }
1236- customApiKeyAuthenticatorByExtension .put (extension .extensionName (), customTokenAuthenticator );
1236+ customAuthenticatorsByExtension .put (securityExtension .extensionName (), customAuthenticators );
12371237 }
12381238 }
12391239
1240- if (customApiKeyAuthenticatorByExtension .isEmpty ()) {
1240+ if (customAuthenticatorsByExtension .isEmpty ()) {
12411241 logger .debug (
1242- "No custom implementation for [{}]. Falling-back to noop implementation ." ,
1243- CustomTokenAuthenticator .class .getCanonicalName ()
1242+ "No custom implementations for [{}] provided by security extensions ." ,
1243+ CustomAuthenticator .class .getCanonicalName ()
12441244 );
1245- return List .of (new CustomTokenAuthenticator .Noop ());
1246-
1247- } else if (customApiKeyAuthenticatorByExtension .size () > 1 ) {
1245+ return List .of ();
1246+ } else if (customAuthenticatorsByExtension .size () > 1 ) {
12481247 throw new IllegalStateException (
1249- "Multiple extensions tried to install a custom CustomApiKeyAuthenticator : " + customApiKeyAuthenticatorByExtension .keySet ()
1248+ "Multiple extensions tried to install custom authenticators : " + customAuthenticatorsByExtension .keySet ()
12501249 );
1251-
12521250 } else {
1253- final var authenticatorByExtensionEntry = customApiKeyAuthenticatorByExtension .entrySet ().iterator ().next ();
1254- final List <CustomTokenAuthenticator > customTokenAuthenticators = authenticatorByExtensionEntry .getValue ();
1251+ final var authenticatorByExtensionEntry = customAuthenticatorsByExtension .entrySet ().iterator ().next ();
1252+ final List <CustomAuthenticator > customAuthenticators = authenticatorByExtensionEntry .getValue ();
12551253 final String extensionName = authenticatorByExtensionEntry .getKey ();
1256- for (CustomTokenAuthenticator authenticator : customTokenAuthenticators ) {
1254+ for (CustomAuthenticator authenticator : customAuthenticators ) {
12571255 logger .debug (
1258- "CustomApiKeyAuthenticator implementation [{}] provided by extension [{}]" ,
1256+ "{} implementation [{}] provided by extension [{}]" ,
1257+ CustomAuthenticator .class .getSimpleName (),
12591258 authenticator .getClass ().getCanonicalName (),
12601259 extensionName
12611260 );
12621261 }
1263- return customTokenAuthenticators ;
1262+ return customAuthenticators ;
12641263 }
12651264 }
12661265
0 commit comments