@Override
    public boolean isAuthenticationRequired(SubjectConnectionReference conn) {
        Subject subject = conn.getSubject();

        if (subject.isAuthenticated()) {
            //already authenticated:
            return false;
        }
        //subject is not authenticated.  Authentication is required by default for all accounts other than
        //the anonymous user (if enabled) or the vm account (if enabled)
        if (isAnonymousAccessAllowed()) {
            if (isAnonymousAccount(subject)) {
                return false;
            }
        }

        if (!isVmConnectionAuthenticationRequired()) {
            if (isSystemAccount(subject)) {
                return false;
            }
        }

        return true;
    }
@Test
    public void testIsAuthenticationRequiredWhenAlreadyRequired() {
        Subject subject = new SubjectAdapter() {
            @Override
            public boolean isAuthenticated() {
                return true;
            }
        };
        SubjectConnectionReference sc = new SubjectConnectionReference(new ConnectionContext(), new ConnectionInfo(),
                new DefaultEnvironment(), subject);

        assertFalse(policy.isAuthenticationRequired(sc));
    }