@@ -131,12 +131,12 @@ private void authenticateWithCache(UsernamePasswordToken token, ActionListener<A
131
131
});
132
132
if (authenticationInCache .get ()) {
133
133
// there is a cached or an inflight authenticate request
134
- listenableCacheEntry .addListener (ActionListener . wrap ( cachedResult -> {
134
+ listenableCacheEntry .addListener (listener . delegateFailureAndWrap (( delegate , cachedResult ) -> {
135
135
final boolean credsMatch = cachedResult .verify (token .credentials ());
136
136
if (cachedResult .authenticationResult .isAuthenticated ()) {
137
137
if (credsMatch ) {
138
138
// cached credential hash matches the credential hash for this forestalled request
139
- handleCachedAuthentication (cachedResult .user , ActionListener . wrap ( authResult -> {
139
+ handleCachedAuthentication (cachedResult .user , delegate . delegateFailureAndWrap (( delegate2 , authResult ) -> {
140
140
if (authResult .isAuthenticated ()) {
141
141
logger .debug (
142
142
"realm [{}] authenticated user [{}], with roles [{}] (cached)" ,
@@ -152,8 +152,8 @@ private void authenticateWithCache(UsernamePasswordToken token, ActionListener<A
152
152
authResult .getMessage ()
153
153
);
154
154
}
155
- listener .onResponse (authResult );
156
- }, listener :: onFailure ));
155
+ delegate2 .onResponse (authResult );
156
+ }));
157
157
} else {
158
158
logger .trace (
159
159
"realm [{}], provided credentials for user [{}] do not match (known good) cached credentials,"
@@ -166,7 +166,7 @@ private void authenticateWithCache(UsernamePasswordToken token, ActionListener<A
166
166
// clear cache and try to reach the authentication source again because password
167
167
// might have changed there and the local cached hash got stale
168
168
cache .invalidate (token .principal (), listenableCacheEntry );
169
- authenticateWithCache (token , listener );
169
+ authenticateWithCache (token , delegate );
170
170
}
171
171
} else if (credsMatch ) {
172
172
// not authenticated but instead of hammering reuse the result. a new
@@ -178,7 +178,7 @@ private void authenticateWithCache(UsernamePasswordToken token, ActionListener<A
178
178
cachedResult .authenticationResult .getStatus (),
179
179
cachedResult .authenticationResult .getMessage ()
180
180
);
181
- listener .onResponse (cachedResult .authenticationResult );
181
+ delegate .onResponse (cachedResult .authenticationResult );
182
182
} else {
183
183
logger .trace (
184
184
"realm [{}], provided credentials for user [{}] do not match (possibly invalid) cached credentials,"
@@ -187,9 +187,9 @@ private void authenticateWithCache(UsernamePasswordToken token, ActionListener<A
187
187
token .principal ()
188
188
);
189
189
cache .invalidate (token .principal (), listenableCacheEntry );
190
- authenticateWithCache (token , listener );
190
+ authenticateWithCache (token , delegate );
191
191
}
192
- }, listener :: onFailure ), threadPool .executor (ThreadPool .Names .GENERIC ), threadPool .getThreadContext ());
192
+ }), threadPool .executor (ThreadPool .Names .GENERIC ), threadPool .getThreadContext ());
193
193
} else {
194
194
logger .trace (
195
195
"realm [{}] does not have a cached result for user [{}]; attempting fresh authentication" ,
0 commit comments