smolnar82 opened a new pull request, #1551: URL: https://github.com/apache/knox/pull/1551
[KNOX-3621](https://issues.apache.org/jira/browse/KNOX-3621) - Make the KnoxIDF token endpoint's user params lookup non-fatal and configurable ## What changes were proposed in this pull request? With the LDAP user params provider (`user.params.provider.ldap.*`) configured, the `authorization_code` and `refresh_token` grants look up the user in LDAP to add optional claims (name, email, roles, ...) to the access token. Any failure of that lookup (LDAP unreachable, bind failure, misconfiguration) escaped as an unhandled `RuntimeException`, so the grant failed with a 500. The auth code / refresh token is consumed before the lookup, so the client could not even retry with it. `/userinfo` looks the user up again anyway, so on the token endpoint the lookup is optional enrichment. - **Token endpoint: a failed lookup no longer fails the grant.** The token is issued without the user params claims, a WARN is logged (stack trace at DEBUG), and the grant's audit entry records `user_params=unavailable`. - **New KnoxIDF service param `knoxidf.token.user.params.enabled`** (default `true`, i.e. unchanged behavior). When `false`, the token endpoint uses the empty provider and never contacts LDAP; `/userinfo` still uses the configured provider. `UserParamsProviderFactory.getUserParamsProvider(ServletContext)` honors the switch (token endpoint), `getUserParamsProvider(ServletContext, true)` ignores it (`/userinfo`). - **`/userinfo`: a failed lookup answers `503` `temporarily_unavailable`** with a WARN and audit `reason=user_params_unavailable`, instead of a 500. Returning an empty profile would wrongly tell the client the user has no such claims. - **`LdapUserParamsProvider` logs static misconfiguration once at startup** as ERROR (missing/unresolvable `systemPasswordAlias`, search filter without `{0}`). The per-lookup fail-closed checks are unchanged and use the same messages. - New `KnoxIDFMessages` i18n interface for the above log messages. - Docs: `knox-site/docs/knoxidf/configuration.md` documents the new param and the failure behavior. Note: services that authorize on a user params claim in the access token (e.g. `roles`) will see a token without it if LDAP was down when the token was issued, until the token expires or is refreshed. ## How was this patch tested? - New unit tests: - `TokenResourceUserParamsTest`: auth code and refresh grants with a failing provider return 200 and audit `user_params=unavailable`; a successful lookup records nothing extra. - `UserInfoResourceUserParamsTest`: failing provider -> 503 `temporarily_unavailable` with a FAILURE audit `reason=user_params_unavailable`; successful provider -> claims served. - `UserParamsProviderFactoryTest`: provider selection with/without LDAP URL, switch unset/`true`/`false`/`FALSE`, and the explicit overload ignoring the switch. - Existing `LdapUserParamsProviderTest` covers constructing the provider with a missing/unresolvable alias and bad filters (now logged, still not thrown). - `mvn -pl gateway-service-knoxidf verify`: 312 tests pass; checkstyle, PMD, spotbugs, forbiddenapis, RAT and jacoco pass. ## Integration Tests No integration test added: the new behavior only shows when the LDAP lookup fails (or with the switch turned off), and the compose setup has no way to take LDAP down mid-flow. The default path (switch unset, LDAP reachable) is unchanged and remains covered by the existing KnoxIDF suites. No opt-in labels needed. ## Performance implications - Default (`knoxidf.token.user.params.enabled` unset/`true`): no change, one LDAP lookup per `authorization_code` / `refresh_token` grant as before. - With `knoxidf.token.user.params.enabled=false`: one LDAP round trip fewer per token grant; `/userinfo` is unchanged. - Failure path: the grant now completes instead of failing, so no client retries with a new authorization flow; no new remote calls, caching or locking. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
