oscerd opened a new pull request, #29144:
URL: https://github.com/apache/camel/pull/29144

   Fixes [CAMEL-26559](https://issues.apache.org/jira/browse/CAMEL-26559).
   
   ### Problem
   
   A YAML route that declares one of these classes under `beans:` fails under 
`camel run` unless the component is added with `--dep`:
   
   ```yaml
   - beans:
       - name: opaPolicy
         type: org.apache.camel.component.opa.security.OpaSecurityPolicy
         properties:
           serverUrl: http://localhost:8181
           policyPath: authz/allow
   ```
   
   ```
   Error creating bean: opaPolicy of type: 
#class:org.apache.camel.component.opa.security.OpaSecurityPolicy: class 
org.apache.camel.component.opa.security.OpaSecurityPolicy was not found (check 
the package name; a class from another library needs its dependency added)
   Caused by: java.lang.ClassNotFoundException: 
org.apache.camel.component.opa.security.OpaSecurityPolicy
   ```
   
   It fails even when the same file has an `opa:` endpoint, because YAML beans 
are created while the file is pre-parsed, before any endpoint downloads its 
component. `OpenFgaSecurityPolicy`, `SpiffeSecurityPolicy` and 
`SpiffeSSLContextParameters` behave the same. When a class is missing, 
`DependencyDownloaderClassResolver` finds its jar through the known 
dependencies (component classes only) or the catalog's pojo-bean metadata, and 
none of the four had a bean entry.
   
   ### Change
   
   - The four classes are catalog beans now, the way the route policies and the 
aggregation and idempotent repositories are: `@Metadata(label = "bean", ...)` 
and `@Configurer(metadataOnly = true)` on the class, `@Metadata` on each 
option. The catalog gets `beans/OpaSecurityPolicy.json` and the other three, 
with their coordinates, their `interfaceType` (`AuthorizationPolicy`, or 
`SSLContextParameters` for the SPIFFE one), and their options, including 
`required`, defaults, enums and the `secret` / `insecure:*` markers the 
endpoint options carry. That also documents the options for `camel doc` and 
other tooling that reads the catalog.
   - `OpenFgaSecurityPolicy` kept its options in an `OpenFgaConfiguration`, and 
the bean generator reads annotated fields only, so the policy now has fields of 
its own, as `OpaSecurityPolicy` does, and builds the endpoint configuration for 
its client and authorizer from them in `beforeWrap` (`toConfiguration()`). 
Defaults come from a fresh `OpenFgaConfiguration`, so the two cannot drift 
apart.
   - Regenerated: the configurers and bean JSON in the three components, the 
catalog's `beans` and `beans.properties`, and `ArtifactUtils` in camel-util, 
which maps each catalog bean to its artifact for runtime error hints.
   
   `SpiffeSSLContextParameters` inherits most of its options from 
`SSLContextParameters`. Its generated configurer covers only its own options; 
the inherited ones (`serverParameters.clientAuthentication`, 
`secureSocketProtocols`, ...) still bind through the reflection fallback, which 
`SpiffeBeanBindingTest` checks.
   
   No other security policy (`KeycloakSecurityPolicy`, `ShiroSecurityPolicy`, 
...) is in the bean catalog either; that is left out of this PR.
   
   ### Tests
   
   - `CamelCatalogTest.testSecurityBeanNamesItsComponent`: the catalog entry of 
each of the four has the class, `org.apache.camel` and the right artifact, the 
interface and a key option. That is the lookup `camel run` makes.
   - `OpenFgaSecurityPolicyOptionsTest`: every option of the policy reaches 
`toConfiguration()` (found by reflection, so a future option is covered too), 
the defaults match the endpoint's, and the options bind from a YAML-shaped map. 
Removing `setScopes` from `toConfiguration()` makes it fail with `[scopes] 
expected: "value-of-scopes" but was: null`.
   - `OpaSecurityPolicyBindingTest`, `SpiffeBeanBindingTest`: the options bind 
from a YAML-shaped map through `PropertyBindingSupport.setPropertiesOnTarget`, 
the call the YAML DSL makes, with the generated configurers in place.
   
   Full reactor (`clean install -DskipTests`) green; camel-opa (144), 
camel-openfga (150) and camel-spiffe (54) tests green, ITs included; 
camel-catalog 1123 tests green.
   
   ### End-to-end
   
   `camel run` (the launcher from this build, `--maven-settings` pointing at 
the build's local repository) on a YAML file declaring all four beans and no 
`opa:`, `openfga:` or `spiffe:` endpoint, without `--dep`:
   
   - with this catalog: `camel-opa`, `camel-openfga` and `camel-spiffe` are 
downloaded on demand and all four beans load with their properties;
   - with a catalog built from the same main without the entries: 
`ClassNotFoundException: 
org.apache.camel.component.opa.security.OpaSecurityPolicy`.
   
   ### Note
   
   CAMEL-26562 adds `useGlobalSslContextParameters` to both policies. Whichever 
of the two PRs lands second needs a rebase: the new field then needs its 
`@Metadata`, and it goes into the `POLICY_ONLY` set of 
`OpenFgaSecurityPolicyOptionsTest`. Related YAML work: CAMEL-26560 (#29138), 
CAMEL-26561 (#29137).
   
   _Claude Code on behalf of oscerd_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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