@Override
    public boolean canImpersonateInternal(final String username, final Principal surrogate, final Optional<? extends Service> service) {
        val surrogateSearchQuery = SpringExpressionLanguageValueResolver.getInstance()
            .resolve(casProperties.getAuthn().getSurrogate().getJdbc().getSurrogateSearchQuery());
        LOGGER.debug("Executing SQL query [{}]", surrogateSearchQuery);
        val count = jdbcTemplate.queryForObject(surrogateSearchQuery, Integer.class, surrogate.getId(), username);
        return Objects.requireNonNull(count) > 0;
    }
This is {@link SurrogateJdbcAuthenticationService}.

@author Misagh Moayyed
@since 5.2.0
support/cas-server-support-surrogate-authentication-jdbc/src/main/java/org/apereo/cas/authentication/surrogate/SurrogateJdbcAuthenticationService.java