default <T> T getAttributeAs(final String name, final Class<T> clazz) {
        val attribute = getAttributes().get(name);
        if (attribute == null) {
            return null;
        }
        if (!clazz.isAssignableFrom(attribute.getClass())) {
            throw new ClassCastException("Attribute " + name + '[' + attribute
                + " is of type " + attribute.getClass() + " when we were expecting " + clazz);
        }
        return (T) attribute;
    }
Gets attribute as requested type.

@param <T>   the type parameter
@param name  the name
@param clazz the clazz
@return the attribute as
api/cas-server-core-api-authentication/src/main/java/org/apereo/cas/authentication/principal/Service.java