private static <T> T getAttributeByType(final String name, final Class<T> clazz, final Object attribute) {

        if (attribute == null) {
            return null;
        }

        if (!clazz.isAssignableFrom(attribute.getClass())) {
            throw new ClassCastException("Attribute [" + name
                    + " is of type " + attribute.getClass()
                    + " when we were expecting " + clazz);
        }

        return (T) attribute;
    }
Return authentication attribute with name

@param name Name of authentication attribute
@param clazz The class of the authentication attribute
@param <T> The type of the authentication attribute
@return the named attribute
pac4j-core/src/main/java/org/pac4j/core/profile/BasicUserProfile.java