private static Throwable getRootCause(final Throwable exception, final Class<?> cause) {
        var rootCause = exception.getCause();
        if (rootCause != null) {
            do {
                if (rootCause.getClass().equals(cause)) {
                    return rootCause;
                }
                rootCause = rootCause.getCause();
            } while (rootCause != null);
        }
        return null;
    }
This is {@link AbstractSecurityFilter}.

@author Misagh Moayyed
@since 6.1.0
core/cas-server-core-web-api/src/main/java/org/apereo/cas/web/support/filters/AbstractSecurityFilter.java