[2.7.x] NEXUS-6219: Backport to 2.7.x

This one needed manual intervention, due to code changes between 2.7.x and master.

Original PR
https://github.com/sonatype/nexus-oss/pull/319

Issue
https://issues.sonatype.org/browse/NEXUS-6219

CI
TBD