當前位置: 首頁>>代碼示例>>Java>>正文


Java WebUtils.getRequiredWebEnvironment方法代碼示例

本文整理匯總了Java中org.apache.shiro.web.util.WebUtils.getRequiredWebEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:Java WebUtils.getRequiredWebEnvironment方法的具體用法?Java WebUtils.getRequiredWebEnvironment怎麽用?Java WebUtils.getRequiredWebEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.web.util.WebUtils的用法示例。


在下文中一共展示了WebUtils.getRequiredWebEnvironment方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
/**
 * Configures this instance based on the existing {@link org.apache.shiro.web.env.WebEnvironment} instance
 * available to the currently accessible {@link #getServletContext() servletContext}.
 *
 * @see org.apache.shiro.web.env.EnvironmentLoaderListener
 * @since 1.2
 */
@Override
public void init() throws Exception {
    WebEnvironment env = WebUtils.getRequiredWebEnvironment(getServletContext());

    setSecurityManager(env.getWebSecurityManager());

    FilterChainResolver resolver = env.getFilterChainResolver();
    if (resolver != null) {
        setFilterChainResolver(resolver);
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:19,代碼來源:ShiroFilter.java

示例2: init

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
/**
 * @see org.apache.wicket.Application#init()
 */
@Override
public void init() {
	super.init();

	String version = "0.0.17";
	System.setProperty("MyOpenTraderWebVersion", version);

	// Check the properties
	PropertiesFactory pf = PropertiesFactory.getInstance();
	ServletContext context = this.getServletContext();
	String configDir = pf.getConfigDir();

	// If the configDir is already set, use this one otherwise get the
	// context
	if (configDir == null) {
		configDir = context.getRealPath("/WEB-INF/conf");
		pf.setConfigDir(configDir);
	}

	System.out.println("*** STARTING NEW MYOPENTRADER WEB INSTANCE ***");
	System.out.println("Using Config directory: " + configDir);
	System.out.println("Using context path: " + context.getContextPath());
	System.out.println("**********");

	// Configure the log4j properties
	PropertyConfigurator.configure(pf.getConfigDir() + "/log4j.properties");

	// The following lines ensure that the context is set for SHIRO. If not,
	// the securityFactory will not get a subject
	WebEnvironment wm = WebUtils.getRequiredWebEnvironment(context);
	WebSecurityManager wsm = wm.getWebSecurityManager();
	ThreadContext.bind(wsm);

}
 
開發者ID:sgrotz,項目名稱:myopentrader,代碼行數:38,代碼來源:MyOpenTraderWeb.java

示例3: printDDBody

import org.apache.shiro.web.util.WebUtils; //導入方法依賴的package包/類
public static String printDDBody(String context_App_RealPath, HttpServletRequest request)
    {
        StringBuilder authInfoAndButtonHTMLBld = new StringBuilder();
        // todo: if commons is refactored as singleton, we could do this only once and store it as a class member (the currentUser object)
        boolean foundWebEnvInAppContext = false;
        if (Common.getCommon().getAppContext() != null)
        {
            WebEnvironment webEnv = WebUtils.getRequiredWebEnvironment(Common.getCommon().getAppContext());
            WebSecurityManager webSecurityManager = webEnv.getWebSecurityManager();
            if(webSecurityManager!=null) {
                SecurityUtils.setSecurityManager(webSecurityManager);
                foundWebEnvInAppContext = true;
                LOG.info("Success: Retrieved WebEnvironment from context! ");
            }
        }
//       // get the currently executing user:
//        Subject currentUser = SecurityUtils.getSubject();
        if (!foundWebEnvInAppContext) {
            LOG.info("Unable to retrieve WebEnvironment from context! ");
            Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
            org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
            SecurityUtils.setSecurityManager(securityManager);
        }


        // A simple Shiro environment is set up
        // get the currently executing user:
        Subject currentUser = SecurityUtils.getSubject();

        // Tests with session variables (todo: remove this after verifying what works and what not -session range / expiration / cleanup)
        Session session = currentUser.getSession();
        String value = (String) session.getAttribute("someKey");
        if(value == null || value.trim().isEmpty()) {
            LOG.info("Session did not have the value stored! ");
            session.setAttribute("someKey", "aValue");
            value = (String) session.getAttribute("someKey");
        }
        if (value.equals("aValue")) {
            LOG.info("Retrieved the correct value! [" + value + "]");
        }


        Field [] list = currentUser.getClass().getDeclaredFields();
        for(Field f:list)
        	LOG.info(f.getName());
        if (currentUser.isAuthenticated()) {
	     authInfoAndButtonHTMLBld.append("<div class=\"container\" style=\"padding-top: 100px;\">");
		    authInfoAndButtonHTMLBld.append("</div>");
        }
        else
        {
	     authInfoAndButtonHTMLBld.append("<div class=\"container\" style=\"padding-top: 100px;\">");
		    authInfoAndButtonHTMLBld.append("</div>");
	        authInfoAndButtonHTMLBld.append("<div id=\"notloggedin\" class=\"well\">");
		    authInfoAndButtonHTMLBld.append("Login to use the VITRO functionalities!");
		    authInfoAndButtonHTMLBld.append("</div>");
		   // authInfoAndButtonHTMLBld.append("<div id=\"logoHome\" align=\"center\">");
		   // authInfoAndButtonHTMLBld.append("<img src=" + request.getContextPath() +"/img/Vitrologo.jpg>");
		   // authInfoAndButtonHTMLBld.append("</div>");
        }


        StringBuilder strBuildToRet = new  StringBuilder();
        strBuildToRet.append("");

            

           // strBuildToRet.append("<div id=\"bar\"><table id=general_table><tr>");
           // strBuildToRet.append(menuWrapperfileContents);
        strBuildToRet.append(authInfoAndButtonHTMLBld.toString());
           // strBuildToRet.append("</tr></table></div>") ;
        
        return strBuildToRet.toString();
    }
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:75,代碼來源:Common.java


注:本文中的org.apache.shiro.web.util.WebUtils.getRequiredWebEnvironment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。