|
21 | 21 | import java.util.Map;
|
22 | 22 | import java.util.Objects;
|
23 | 23 | import java.util.Set;
|
| 24 | +import java.util.concurrent.ExecutionException; |
| 25 | +import java.util.concurrent.TimeUnit; |
| 26 | +import java.util.concurrent.TimeoutException; |
24 | 27 | import javax.naming.AuthenticationException;
|
25 | 28 | import javax.security.auth.callback.Callback;
|
26 | 29 | import javax.security.auth.callback.UnsupportedCallbackException;
|
@@ -126,8 +129,11 @@ protected void handleCallback(KopOAuthBearerValidatorCallback callback) {
|
126 | 129 | final String tenant = tokenAndTenant.getRight();
|
127 | 130 |
|
128 | 131 | try {
|
| 132 | + AuthData authData = AuthData.of(token.getBytes(StandardCharsets.UTF_8)); |
129 | 133 | final AuthenticationState authState = authenticationProvider.newAuthState(
|
130 |
| - AuthData.of(token.getBytes(StandardCharsets.UTF_8)), null, null); |
| 134 | + authData, null, null); |
| 135 | + // TODO: Use the configurable timeout |
| 136 | + authState.authenticateAsync(authData).get(10, TimeUnit.SECONDS); |
131 | 137 | final String role = authState.getAuthRole();
|
132 | 138 | AuthenticationDataSource authDataSource = authState.getAuthDataSource();
|
133 | 139 | callback.token(new KopOAuthBearerToken() {
|
@@ -168,7 +174,7 @@ public Long startTimeMs() {
|
168 | 174 | return Long.MAX_VALUE;
|
169 | 175 | }
|
170 | 176 | });
|
171 |
| - } catch (AuthenticationException e) { |
| 177 | + } catch (AuthenticationException | InterruptedException | ExecutionException | TimeoutException e) { |
172 | 178 | log.error("OAuth validator callback handler new auth state failed: ", e);
|
173 | 179 | throw new OAuthBearerIllegalTokenException(OAuthBearerValidationResult.newFailure(e.getMessage()));
|
174 | 180 | }
|
|
0 commit comments