smolnar82 opened a new pull request, #1521:
URL: https://github.com/apache/knox/pull/1521

   [KNOX-3582](https://issues.apache.org/jira/browse/KNOX-3582) - Honor 
knox.token.exp.server-managed in PasscodeTokenResourceBase
   
   ## What changes were proposed in this pull request?
   
   `PasscodeTokenResourceBase#setupTokenStateService` always assigned the token 
state service. As a result, an explicit `knox.token.exp.server-managed=false` 
was ignored for the `CLIENTID`, `APIKEY` and KnoxIDF resources, and every token 
they issued was stored and marked managed. It also left the resource 
inconsistent: the parent `TokenResource#init` skipped building the token MAC 
because of the `false` setting, while `tokenStateService` was still set, so 
`persistTokenDetails` failed with an NPE.
   
   Changes:
   - `setupTokenStateService` keeps `true` as the default for topologies that 
don't declare the setting, using the wrapper's lowest-precedence default param. 
It then reads the effective value with `isServerManagedTokenStateEnabled` (now 
`protected`) and assigns `tokenStateService` only when it is enabled. An 
explicit value, plain or extension-prefixed (for example 
`knoxidf.knox.token.exp.server-managed`), is honored. A blank value falls back 
to the gateway-level setting, as it does for `KNOXTOKEN`.
   - When it is disabled, an INFO message is logged for the topology.
   - The token hash key alias is still generated in both cases, because the 
KnoxIDF token endpoint always builds a `TokenMAC` from it.
   
   With `false`, the token endpoint issues unmanaged tokens. They are not 
stored, get `managed.token=false`, and cannot be revoked. This is meant for 
token-exchange-only topologies, where storing every short-lived token costs DB 
writes on the request path. Grants and endpoints that need stored state are not 
supported with this setting: the KnoxIDF `authorization_code` and 
`refresh_token` grants, authorize, registration, and API key and client 
credentials passcodes. The docs say so and recommend pairing the setting with 
`jwt.allowed.grant.types` (KNOX-3578).
   
   Docs:
   - `config_knox_token.md`: `CLIENTID`, `APIKEY` and KnoxIDF default the 
setting to `true`, and an explicit value is honored.
   - `knoxidf/configuration.md`: the new 
`knoxidf.knox.token.exp.server-managed` parameter and an "Unmanaged tokens" 
section.
   
   ## How was this patch tested?
   
   - New `PasscodeTokenResourceBaseServerManagedTest` (6 tests), covering the 
base resource, `OAuthResource`, `APIKeyResource` and 
`ClientCredentialsResource`:
     - not declared (even with the gateway default `false`) or `true`: token 
state is used;
     - `false`: no token state, and the hash key alias is still generated;
     - blank: falls back to the gateway default;
     - an extension-prefixed value wins over a plain one, and works on its own.
   - `mvn -pl gateway-service-knoxtoken,gateway-service-knoxidf install` with 
checkstyle: knoxtoken 152 tests and KnoxIDF 274 tests, all passing.
   
   ## Integration Tests
   
   No integration tests added. The existing compose topologies don't set the 
parameter, so they keep today's default behaviour (`true`). The unit tests 
above cover the new `false` path.
   


-- 
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]

Reply via email to