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.