NEXUS-6139: Backport to Nexus 2.7.x

Backported fixes from master to 2.7.x

Pull requests
https://github.com/sonatype/nexus-oss/pull/262
https://github.com/sonatype/nexus-oss/pull/286

Issue
https://issues.sonatype.org/browse/NEXUS-6139

CI
TBD