[MAGNOLIA-5723] HostBasedVirtualURIMapping should select the best matching configured host regardless of order Created: 21/Mar/14  Updated: 01/Apr/14  Resolved: 01/Apr/14

Status: Closed
Project: Magnolia
Component/s: content2bean, node2bean
Affects Version/s: 4.5.17, 5.2.3
Fix Version/s: 4.5.18

Type: Improvement Priority: Neutral
Reporter: Christian Ringele Assignee: Christopher Zimmermann
Resolution: Fixed Votes: 0
Labels: support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Cloners
is cloned by MAGNOLIA-5735 CLONE - HostBasedVirtualURIMapping sh... Closed
is cloned by MAGNOLIA-5735 CLONE - HostBasedVirtualURIMapping sh... Closed
relation
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Release notes required:
Yes
Date of First Response:

 Description   

The simple matching fails in the situation where one of the hosts to match is a subdomain. The matching should select the correct host in this situation as well.

For example, Host mappings are:
1. mysite.com
2. subdomain.mysite.com
Incoming request has host: subdomain.mysite.com

With the current matching strategy (simple check if requested host ends with mapping) both mappings would match, so order would be important.

We should ensure that if one mapping is a more accurate match, that it should be selected.
And for good measure, we should ensure that the configured mappings are evaluated in the order that they are in the configuration tree. (Though this is less important if the matching algorithm is improved.)



 Comments   
Comment by Christian Ringele [ 21/Mar/14 ]

Stefan has placed a code possibility into the support ticket.

Comment by Christopher Zimmermann [ 27/Mar/14 ]

HostBasedVirtualURIMapping evaluates the hosts in a new way - not simply taking the first match. Now it chooses the mapping that both matches the request host AND has the least number of additional characters.
This solves the problem where, if the order of the mappings was wrong, a request for a normal domain would incorrectly MATCH a host with a subdomain. For example a request for "fancy.mysite.com" would match the mapping "mysite.com" instead of the mapping "fancy.mysite.com" because it found it first.

HostBasedVirtualURIMapping now accepts a new configuration which is more logical and follows magnolia best practice.
In configuration, the "hosts" node is now depricated, but is still functional.
The new "mappings" configuration is to be used - primary difference is that "mappings" contains nodes instead of just properties with a "magic" key=value pair in the values.
Bonus - nodes have a preserved order (which properties do not).
Example:

 * [] virtualURIMapping
 *    [] default
 *     - class            info.magnolia.cms.beans.config.HostBasedVirtualURIMapping
 *     - fromURI          /
 *     - toURI            redirect:/.magnolia/pages/adminCentral.html
 *     [] mappings
 *      - [] com
 *        - host      www.acme.com
 *        - toURI     forward:/acme/en/index.html
 *      - [] de
 *        - host      www.acme.de
 *        - toURI     forward:/acme/de/index.html
Comment by Milan Divilek [ 31/Mar/14 ]

Reopen:

1. Please add from which version are "hosts" methods deprecated and which methods used instead.
2. I also don't like this "hardcoded" high value.

 int bestMatchValue = 10000; 

wouldn't be better to set it to negative value and then in "if" statements check it.

Otherwise it looks ok.

Generated at Mon Feb 12 04:07:47 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.