NEXUS-6185: Back-port to nexus-2.7.x

Back-ported PR
https://github.com/sonatype/nexus-oss/pull/294

Commits
f6c647f4ba1b3c90ce7c4527c4bc035212b4f22c
5382859a8095d3a535bd1fbfbef7917aa0c60fe9
bed326d7d21fbe7085fac30904e793ad0f44525f