protected <T> T getAttributeAsType(final String name, Class<T> clazz, T defaultValue) {
        val value = getAttribute(name);
        if (value != null && clazz.isAssignableFrom(value.getClass())) {
            return clazz.cast(value);
        }
        else {
            return defaultValue;
        }
    }
<p>getAttributeAsType.</p>

@param name a {@link String} object
@param clazz a {@link Class} object
@param defaultValue a T object
@param <T> a T class
@return a T object
pac4j-core/src/main/java/org/pac4j/core/profile/CommonProfile.java