[ 
https://issues.apache.org/jira/browse/CAMEL-22849?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Nikita updated CAMEL-22849:
---------------------------
    Description: 
AS2 server routes configured with *requestUriPattern* wildcards (e.g. 
{*}/receiver/{*}{*}) no longer resolve the correct *AS2ConsumerConfiguration{*} 
for incoming requests.
When an AS2 request is sent to a concrete path like */receiver/test-1,* the 
server logs:
{code:java}
No AS2 consumer configuration found for canonical path: /receiver/test-1.
Encrypted messages will likely fail.{code}
Debugging shows that *AS2ServerConnection.consumerConfigurations* contains the 
configuration under the key {*}/receiver/{*},* but 
*getConfigurationForPath(String path)* performs an exact map lookup using the 
resolved request path ({*}/receiver/test-1{*}), which results in null.
This behavior breaks encrypted and/or signed AS2 messages, because the server 
cannot locate the appropriate consumer configuration for decryption and 
signature validation.
This worked correctly in Camel, for example, 3.22.x and appears to be a 
regression in Camel 4.14.3.

*Environment*
 * Camel version: 4.14.x (observed on {*}4.14.3{*})
 * Previous working version: 3.22.x
 * Component: camel-as2
 * Server endpoint: as2:server/listen
 * Configuration example:
 ** requestUriPattern={*}/receiver/{*}*

*Steps to Reproduce*
 # Configure an AS2 server route with: 
*as2("server/listen?requestUriPattern=/receiver/*&serverPortNumber=8190")*
 # Enable encryption and/or signing on the server.
 # Send an AS2 request to: */receiver/test-1*
 # Observe that the server logs a warning and does not apply the consumer 
configuration.

*Expected Result*

The AS2 server should resolve the consumer configuration when the incoming 
request path matches the configured *requestUriPattern* wildcard.

*Actual Result*

The server only attempts an exact match on the canonical request path and 
ignores wildcard patterns, resulting in no configuration being found.

*Suggested Solution*

Update *getConfigurationForPath(String path)* to support wildcard (pattern) 
matching instead of exact key lookup only.
If the incoming request path matches a configured pattern, return the 
corresponding *AS2ConsumerConfiguration* immediately.

*Conceptual example*

 
{code:java}
Optional<AS2ConsumerConfiguration> getConfigurationForPath(String path) {
    AS2ConsumerConfiguration exact = consumerConfigurations.get(path);
    if (exact != null) {
        return Optional.of(exact);
    }
    for (Map.Entry<String, AS2ConsumerConfiguration> entry : 
consumerConfigurations.entrySet()) {
        String pattern = entry.getKey(); // e.g. "/receiver/*"
        if (matches(pattern, path)) {
            return Optional.of(entry.getValue());
        }
    }
    return Optional.empty();
}
boolean matches(String pattern, String path) {
    // simple wildcard support, e.g. '*' matches any characters
}
{code}
This would restore compatibility with *requestUriPattern* behavior from Camel 
3.x and prevent encrypted AS2 messages from failing due to missing 
configuration.

  was:
AS2 server routes configured with *requestUriPattern* wildcards (e.g. 
{*}/receiver/{*}{*}) no longer resolve the correct *AS2ConsumerConfiguration{*} 
for incoming requests.
When an AS2 request is sent to a concrete path like */receiver/test-1,* the 
server logs:
{code:java}
No AS2 consumer configuration found for canonical path: /receiver/test-1.
Encrypted messages will likely fail.{code}
Debugging shows that *AS2ServerConnection.consumerConfigurations* contains the 
configuration under the key {*}/receiver/{*},* but 
*getConfigurationForPath(String path)* performs an exact map lookup using the 
resolved request path ({*}/receiver/test-1{*}), which results in null.
This behavior breaks encrypted and/or signed AS2 messages, because the server 
cannot locate the appropriate consumer configuration for decryption and 
signature validation.
This worked correctly in Camel, for example, 3.22.x and appears to be a 
regression in Camel 4.14.3.

*Environment*
 * Camel version: 4.14.x (observed on {*}4.14.3{*})
 * Previous working version: 3.22.x
 * Component: camel-as2
 * Server endpoint: as2:server/listen
 * Configuration example:
 ** requestUriPattern={*}/receiver/{*}*

*Steps to Reproduce*
 # Configure an AS2 server route with: 
as2("server/listen?requestUriPattern=/receiver/*&serverPortNumber=8190")
 # Enable encryption and/or signing on the server.
 # Send an AS2 request to: /receiver/test-1
 # Observe that the server logs a warning and does not apply the consumer 
configuration.

*Expected Result*

The AS2 server should resolve the consumer configuration when the incoming 
request path matches the configured *requestUriPattern* wildcard.

*Actual Result*

The server only attempts an exact match on the canonical request path and 
ignores wildcard patterns, resulting in no configuration being found.

*Suggested Solution*

Update *getConfigurationForPath(String path)* to support wildcard (pattern) 
matching instead of exact key lookup only.
If the incoming request path matches a configured pattern, return the 
corresponding *AS2ConsumerConfiguration* immediately.

*Conceptual example*

 
{code:java}
Optional<AS2ConsumerConfiguration> getConfigurationForPath(String path) {
    AS2ConsumerConfiguration exact = consumerConfigurations.get(path);
    if (exact != null) {
        return Optional.of(exact);
    }
    for (Map.Entry<String, AS2ConsumerConfiguration> entry : 
consumerConfigurations.entrySet()) {
        String pattern = entry.getKey(); // e.g. "/receiver/*"
        if (matches(pattern, path)) {
            return Optional.of(entry.getValue());
        }
    }
    return Optional.empty();
}
boolean matches(String pattern, String path) {
    // simple wildcard support, e.g. '*' matches any characters
}
{code}
This would restore compatibility with *requestUriPattern* behavior from Camel 
3.x and prevent encrypted AS2 messages from failing due to missing 
configuration.


> AS2 server/listen does not resolve requestUriPattern wildcards when selecting 
> consumer configuration
> ----------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-22849
>                 URL: https://issues.apache.org/jira/browse/CAMEL-22849
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-as2
>    Affects Versions: 4.14.3
>         Environment: *Environment*
>  * Camel version: 4.14.x (observed on {*}4.14.3{*})
>  * Previous working version: 3.22.x
>  * Component: camel-as2
>  * Server endpoint: as2:server/listen
>  * Configuration example:
>  ** requestUriPattern={*}/receiver/*{*}
>            Reporter: Nikita
>            Priority: Major
>         Attachments: AS2.png
>
>
> AS2 server routes configured with *requestUriPattern* wildcards (e.g. 
> {*}/receiver/{*}{*}) no longer resolve the correct 
> *AS2ConsumerConfiguration{*} for incoming requests.
> When an AS2 request is sent to a concrete path like */receiver/test-1,* the 
> server logs:
> {code:java}
> No AS2 consumer configuration found for canonical path: /receiver/test-1.
> Encrypted messages will likely fail.{code}
> Debugging shows that *AS2ServerConnection.consumerConfigurations* contains 
> the configuration under the key {*}/receiver/{*},* but 
> *getConfigurationForPath(String path)* performs an exact map lookup using the 
> resolved request path ({*}/receiver/test-1{*}), which results in null.
> This behavior breaks encrypted and/or signed AS2 messages, because the server 
> cannot locate the appropriate consumer configuration for decryption and 
> signature validation.
> This worked correctly in Camel, for example, 3.22.x and appears to be a 
> regression in Camel 4.14.3.
> *Environment*
>  * Camel version: 4.14.x (observed on {*}4.14.3{*})
>  * Previous working version: 3.22.x
>  * Component: camel-as2
>  * Server endpoint: as2:server/listen
>  * Configuration example:
>  ** requestUriPattern={*}/receiver/{*}*
> *Steps to Reproduce*
>  # Configure an AS2 server route with: 
> *as2("server/listen?requestUriPattern=/receiver/*&serverPortNumber=8190")*
>  # Enable encryption and/or signing on the server.
>  # Send an AS2 request to: */receiver/test-1*
>  # Observe that the server logs a warning and does not apply the consumer 
> configuration.
> *Expected Result*
> The AS2 server should resolve the consumer configuration when the incoming 
> request path matches the configured *requestUriPattern* wildcard.
> *Actual Result*
> The server only attempts an exact match on the canonical request path and 
> ignores wildcard patterns, resulting in no configuration being found.
> *Suggested Solution*
> Update *getConfigurationForPath(String path)* to support wildcard (pattern) 
> matching instead of exact key lookup only.
> If the incoming request path matches a configured pattern, return the 
> corresponding *AS2ConsumerConfiguration* immediately.
> *Conceptual example*
>  
> {code:java}
> Optional<AS2ConsumerConfiguration> getConfigurationForPath(String path) {
>     AS2ConsumerConfiguration exact = consumerConfigurations.get(path);
>     if (exact != null) {
>         return Optional.of(exact);
>     }
>     for (Map.Entry<String, AS2ConsumerConfiguration> entry : 
> consumerConfigurations.entrySet()) {
>         String pattern = entry.getKey(); // e.g. "/receiver/*"
>         if (matches(pattern, path)) {
>             return Optional.of(entry.getValue());
>         }
>     }
>     return Optional.empty();
> }
> boolean matches(String pattern, String path) {
>     // simple wildcard support, e.g. '*' matches any characters
> }
> {code}
> This would restore compatibility with *requestUriPattern* behavior from Camel 
> 3.x and prevent encrypted AS2 messages from failing due to missing 
> configuration.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to