[2.7.x] NEXUS-6277: Backporting the 2nd set of changes

That were applied to master PR after it was created
and the 2.7.x backport did not contain it.

This applies the 3rd and 4th commit of the original PR
https://github.com/sonatype/nexus-oss/pull/354

CI
TBD