k-krawczyk opened a new pull request, #30258:
URL: https://github.com/apache/camel/pull/30258

   Fixes [CAMEL-27035](https://issues.apache.org/jira/browse/CAMEL-27035), the 
five points raised in the review of #30139.
   
   ### 1. A Map or a POJO in the plaintext header was encrypted as its 
toString()
   
   `OpenApiClientSupport.resolveString` reads the `CamelAlibabaKmsPlaintext` 
header with `getHeader(name, String.class)`,
   so a `Map` or a POJO reached KMS as the text of the object, while the same 
value in the message body has failed with
   an `InvalidPayloadException` since CAMEL-26258, which the 4.24 upgrade guide 
states. The header and the exchange
   property now fail with an `IllegalArgumentException`.
   
   A value is rejected only when the text the converter gives is the 
`toString()` of the object:
   
   ```java
   BodyFacts.kindOf(value) != BodyTypeRegistry.Kind.PAYLOAD && 
text.equals(value.toString())
   ```
   
   `ToStringTypeConverter` is registered with `canPromote = false` and returns 
exactly `value.toString()`, so that
   equality is the signal that no other converter read the value as text. Text, 
bytes, a stream, a file, a `char[]` and
   a `ByteBuffer` are read as before. The message names the class and never the 
value, which is the plaintext.
   `IllegalArgumentException` rather than `InvalidPayloadException`, since that 
exception is about the message body.
   
   ### 2. An invalid numberOfBytes failed every operation
   
   `KMSUtils.createClientConfigurations` resolved all six names for every 
exchange, and `ObjectConverter.toInteger` is a
   bare `Integer.valueOf`, so an empty or non-numeric 
`CamelAlibabaKmsNumberOfBytes` failed `encrypt` and `decrypt` with
   a `TypeConversionException`, although neither reads the value. It is now 
resolved only for `generateDataKey`, an empty
   value counts as unset, and a value that is not a number fails with a message 
that names the header.
   
   The shared `OpenApiClientSupport.resolveInteger` is untouched: 
camel-alibaba-mns has the same trap in `delaySeconds`
   and `priority`, which is another component and another ticket.
   
   ### 3. region was marked as required
   
   `region` or `endpoint` is required, and the `kmsClient` option replaces 
both, which the option description already
   said and `KMSUtils.createClient` already enforces with "Region or endpoint 
is required". The `required = true` marker
   is gone and the description says which of the two is needed.
   
   ### 4 and 5. The operation header, and the metadata nothing read
   
   `KMSHeaders` gets the `OPERATION` constant, so `CamelAlibabaKmsOperation` 
appears in the header list of the component
   JSON, the endpoint DSL and the doc page; the producer has always read it. 
`KMSProperties` is now plain constants that
   point at `KMSHeaders`, so the seven `@Metadata` texts it carried, which the 
build never read, are gone. Both follow
   #30048 for camel-alibaba-mns.
   
   ### Tests
   
   9 tests in a new `KMSInputTest`, on the Mockito `Client` of 
`EncryptPlaintextTest`, so no credentials are needed: the
   operation header picks the operation, a text and a bytes plaintext header 
still reach KMS, a `Map` header and a POJO
   exchange property fail without a request, an invalid number of bytes does 
not fail `encrypt` and does fail
   `generateDataKey`, an empty one counts as unset, and `32` is sent as a 
number. With the old resolution restored, 5 of
   the 9 fail. The module is green with `-Psourcecheck` (18 tests).
   
   ### Docs
   
   The plaintext paragraph of the component page, the regenerated component 
JSON, catalog copies and endpoint DSL, and an
   entry in the 4.24 upgrade guide for the plaintext header, the number of 
bytes and the required marker of `region`.
   
   cc @oscerd @davsclaus
   
   _Reported by Claude Code on behalf of Karol Krawczyk_
   


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