[Security] [Acl] [MaskBuilder] Refactor common code and reduce nesting

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | 
| License       | MIT
| Doc PR        |

Refactored some common code and moved a comparison to an earlier statement.