class AdminPermissionChecker {

    public static boolean hasAdministrativePermissions(@NotNull Session session, String... additionalAdminAuthorizableIds) throws RepositoryException {
        String userId = session.getUserID();
        if (ADMIN_USER.equals(userId) || SYSTEM_USER.equals(userId)) {
            return true;
        }
        List<String> additionalAdminIds = Arrays.asList(Optional.ofNullable(additionalAdminAuthorizableIds).orElse(new String[0]));
        if (additionalAdminIds.contains(userId)) {
            return true;
        }
        if (!(session instanceof JackrabbitSession)) {
            log.warn("could not evaluate group permissions but just user name");
            return false;
        }

        JackrabbitSession jackrabbitSession = (JackrabbitSession) session;
        Authorizable authorizable = jackrabbitSession.getUserManager().getAuthorizable(userId);
        if (authorizable == null) {
            return false;
        }

        Iterator<Group> groupIterator = authorizable.memberOf();
        while (groupIterator.hasNext()) {
            String groupId = groupIterator.next().getID();
            if (ADMINISTRATORS_GROUP.equals(groupId)) {
                return true;
            }
            if (additionalAdminIds.contains(groupId)) {
                return true;
            }
        }

        return false;
    }

}