public static <T extends Credential> T getCredential(final RequestContext context, final @NonNull Class<T> clazz) {
        val credential = getCredential(context);
        if (credential == null) {
            return null;
        }
        if (!clazz.isAssignableFrom(credential.getClass())) {
            throw new ClassCastException("credential [" + credential.getId()
                + " is of type " + credential.getClass()
                + " when we were expecting " + clazz);
        }
        return (T) credential;
    }
Gets credential.

@param <T>     the type parameter
@param context the context
@param clazz   the clazz
@return the credential
core/cas-server-core-web-api/src/main/java/org/apereo/cas/web/support/WebUtils.java