NEXUS-6179: Port to master

PR for 2.7 ported to master
https://github.com/sonatype/nexus-oss/pull/287

This PR is only for reference/history, is already voted +1
and is merged into nexus-2.7.x branch.

Once CI confirms, this will get merged to master.

CI
https://bamboo.zion.sonatype.com/browse/NX-OSSF0