@Override
    public <T extends Service> T resolveService(final Service service, final Class<T> clazz) throws Throwable {
        val result = resolveService(service);
        if (result == null) {
            return null;
        }
        if (!clazz.isAssignableFrom(result.getClass())) {
            throw new ClassCastException("Object [" + result + " is of type " + result.getClass() + " when we were expecting " + clazz);
        }
        return (T) result;
    }
This is {@link DefaultAuthenticationServiceSelectionPlan}.

@author Misagh Moayyed
@since 5.1.0
core/cas-server-core-authentication-api/src/main/java/org/apereo/cas/authentication/DefaultAuthenticationServiceSelectionPlan.java