presto-plugin-toolkit/src/main/java/io/prestosql/plugin/base/security/PrincipalUserMatchRule.java/PrincipalUserMatchRule/match
class PrincipalUserMatchRule:    public Optional<Boolean> match(String principal, String user)
    {
        Matcher matcher = principalRegex.matcher(principal);

        if (!matcher.matches()) {
            return Optional.empty();
        }

        if (userRegex.isPresent()) {
            if (userRegex.get().matcher(user).matches()) {
                return Optional.of(allow);
            }
        }

        if (principalToUserSubstitution.isPresent()) {
            String userExtraction = matcher.replaceAll(principalToUserSubstitution.get());
            if (user.equals(userExtraction)) {
                return Optional.of(allow);
            }
        }

        return Optional.empty();
    }