public static WebEnvironment getWebEnvironment(ServletContext sc, String attrName) {
        if (sc == null) {
            throw new IllegalArgumentException("ServletContext argument must not be null.");
        }
        Object attr = sc.getAttribute(attrName);
        if (attr == null) {
            return null;
        }
        if (attr instanceof RuntimeException) {
            throw (RuntimeException) attr;
        }
        if (attr instanceof Error) {
            throw (Error) attr;
        }
        if (attr instanceof Exception) {
            throw new IllegalStateException((Exception) attr);
        }
        if (!(attr instanceof WebEnvironment)) {
            throw new IllegalStateException("Context attribute is not of type WebEnvironment: " + attr);
        }
        return (WebEnvironment) attr;
    }
Find the Shiro {@link WebEnvironment} for this web application.

@param sc       ServletContext to find the web application context for
@param attrName the name of the ServletContext attribute to look for
@return the desired WebEnvironment for this web app, or <code>null</code> if none
@since 1.2
web/src/main/java/org/apache/shiro/web/util/WebUtils.java