core/src/main/java/org/sakaiproject/nakamura/api/lite/StorageClientUtils.java
public static Session adaptToSession(Object source) {
        if (source instanceof SessionAdaptable) {
            return ((SessionAdaptable) source).getSession();
        } else {
            // assume this is a JCR session of someform, in which case there
            // should be a SparseUserManager
            Object userManager = safeMethod(source, "getUserManager", new Object[0], new Class[0]);
            if (userManager != null) {
                return (Session) safeMethod(userManager, "getSession", new Object[0], new Class[0]);
            }
            return null;
        }
    }
public static Session adaptToSession(Object source) {
        if (source instanceof SessionAdaptable) {
            return ((SessionAdaptable) source).getSession();
        } else {
            // assume this is a JCR session of someform, in which case there
            // should be a SparseUserManager
            Object userManager = safeMethod(source, "getUserManager", new Object[0], new Class[0]);
            if (userManager != null) {
                return (Session) safeMethod(userManager, "getSession", new Object[0], new Class[0]);
            }
            return null;
        }
    }
Adapt an object to a session. I haven't used typing here becuase I don't
want to bind to the Jars in question and create dependencies.

@param source
the input object that the method
@return