@Override
    public void checkQueryIntegrity(Identity identity, AccessControlContext context, String query)
    {
        requireNonNull(identity, "identity is null");
        requireNonNull(query, "query is null");

        authenticationCheck(() -> systemAccessControl.get().checkQueryIntegrity(identity, context, query));
    }
@Test
    public void testCheckQueryIntegrity()
    {
        AccessControlManager accessControlManager = new AccessControlManager(createTestTransactionManager());
        AccessControlContext context = new AccessControlContext(new QueryId(QUERY_ID), Optional.empty(), Collections.emptySet(), Optional.empty(), WarningCollector.NOOP, new RuntimeStats());

        TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("test");
        accessControlManager.addSystemAccessControlFactory(accessControlFactory);
        accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
        String testQuery = "test_query";

        accessControlManager.checkQueryIntegrity(
                new Identity(
                        USER_NAME,
                        Optional.of(PRINCIPAL),
                        ImmutableMap.of(),
                        ImmutableMap.of(QUERY_TOKEN_FIELD, testQuery),
                        ImmutableMap.of(),
                        Optional.empty(),
                        Optional.empty()),
                context,
                testQuery);
        assertEquals(accessControlFactory.getCheckedUserName(), USER_NAME);
        assertEquals(accessControlFactory.getCheckedPrincipal(), Optional.of(PRINCIPAL));
        assertEquals(accessControlFactory.getCheckedQuery(), testQuery);

        assertThrows(
                AccessDeniedException.class,
                () -> accessControlManager.checkQueryIntegrity(
                        new Identity(
                                USER_NAME,
                                Optional.of(PRINCIPAL),
                                ImmutableMap.of(),
                                ImmutableMap.of(QUERY_TOKEN_FIELD, testQuery + " modified"),
                                ImmutableMap.of(),
                                Optional.empty(),
                                Optional.empty()),
                        context,
                        testQuery));
    }