Skip to content

Commit e3abd81

Browse files
committed
More
1 parent 6966cea commit e3abd81

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/AuthenticatorChain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class AuthenticatorChain {
5454
AuthenticationContextSerializer authenticationSerializer,
5555
ServiceAccountAuthenticator serviceAccountAuthenticator,
5656
OAuth2TokenAuthenticator oAuth2TokenAuthenticator,
57-
PluggableApiKeyAuthenticator customApiKeyAuthenticator,
57+
PluggableApiKeyAuthenticator pluggableApiKeyAuthenticator,
5858
ApiKeyAuthenticator apiKeyAuthenticator,
5959
RealmsAuthenticator realmsAuthenticator
6060
) {
@@ -68,7 +68,7 @@ class AuthenticatorChain {
6868
this.allAuthenticators = List.of(
6969
serviceAccountAuthenticator,
7070
oAuth2TokenAuthenticator,
71-
customApiKeyAuthenticator,
71+
pluggableApiKeyAuthenticator,
7272
apiKeyAuthenticator,
7373
realmsAuthenticator
7474
);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/PluggableApiKeyAuthenticator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ public AuthenticationToken extractCredentials(Context context) {
3333
@Override
3434
public void authenticate(Context context, ActionListener<AuthenticationResult<Authentication>> listener) {
3535
final AuthenticationToken authenticationToken = context.getMostRecentAuthenticationToken();
36-
authenticator.authenticate(
37-
authenticationToken,
38-
ActionListener.wrap(
39-
listener::onResponse,
40-
ex -> listener.onFailure(context.getRequest().exceptionProcessingRequest(ex, authenticationToken))
41-
)
42-
);
36+
authenticator.authenticate(authenticationToken, ActionListener.wrap(response -> {
37+
if (response.isAuthenticated()) {
38+
listener.onResponse(response);
39+
} else if (response.getStatus() == AuthenticationResult.Status.TERMINATE) {
40+
listener.onFailure(context.getRequest().exceptionProcessingRequest(response.getException(), authenticationToken));
41+
} else if (response.getStatus() == AuthenticationResult.Status.CONTINUE) {
42+
listener.onResponse(AuthenticationResult.notHandled());
43+
}
44+
}, ex -> listener.onFailure(context.getRequest().exceptionProcessingRequest(ex, authenticationToken))));
4345
}
4446
}

0 commit comments

Comments
 (0)