当前位置: 首页>>代码示例>>Java>>正文


Java WebEnvironment.getWebSecurityManager方法代码示例

本文整理汇总了Java中org.apache.shiro.web.env.WebEnvironment.getWebSecurityManager方法的典型用法代码示例。如果您正苦于以下问题:Java WebEnvironment.getWebSecurityManager方法的具体用法?Java WebEnvironment.getWebSecurityManager怎么用?Java WebEnvironment.getWebSecurityManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.web.env.WebEnvironment的用法示例。


在下文中一共展示了WebEnvironment.getWebSecurityManager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.apache.shiro.web.env.WebEnvironment; //导入方法依赖的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

示例2: init

import org.apache.shiro.web.env.WebEnvironment; //导入方法依赖的package包/类
@Override
public void init() {
    logger.debug("Initializing dispatcher");
    DispatcherLogic.init(configuration);

    logger.info("Initializing ehcache service");
    cacheManager = CacheManager.newInstance();
    servletContext.setAttribute(EHCACHE_MANAGER, cacheManager);

    logger.info("Initializing Shiro environment");
    WebEnvironment environment = environmentLoader.initEnvironment(servletContext);
    logger.debug("Publishing the Application Realm in the servlet context");
    RealmSecurityManager rsm = (RealmSecurityManager) environment.getWebSecurityManager();

    File pagesDirectory = new File(applicationDirectory, "pages");
    logger.info("Pages directory: " + pagesDirectory);
    ElementsFileUtils.ensureDirectoryExistsAndWarnIfNotWritable(pagesDirectory);

    if(configuration.getBoolean(PortofinoProperties.GROOVY_PRELOAD_PAGES, true)) {
        logger.info("Preloading pages");
        preloadPageActions(pagesDirectory);
    }
    if(configuration.getBoolean(PortofinoProperties.GROOVY_PRELOAD_CLASSES, true)) {
        logger.info("Preloading Groovy classes");
        preloadGroovyClasses(groovyClasspath);
    }
    servletContext.setAttribute(PAGES_DIRECTORY, pagesDirectory);

    logger.debug("Creating pageactions registry");
    PageActionRegistry pageActionRegistry = new PageActionRegistry();
    pageActionRegistry.register(CustomAction.class);
    pageActionRegistry.register(DefaultLoginAction.class);
    servletContext.setAttribute(PAGE_ACTIONS_REGISTRY, pageActionRegistry);

    servletContext.setAttribute(TEMPLATES_REGISTRY, new TemplateRegistry());

    cacheResetListenerRegistry.getCacheResetListeners().add(new ConfigurationCacheResetListener());

    SimpleMenuAppender link = SimpleMenuAppender.link(
            "configuration", "settings", null, "Settings", SettingsAction.URL_BINDING, 0.5);
    adminMenu.menuAppenders.add(link);

    logger.debug("Creating SecurityGroovyRealm");
    try {
        SecurityGroovyRealm realm = new SecurityGroovyRealm(classLoader, servletContext);
        LifecycleUtils.init(realm);
        rsm.setRealm(realm);
        status = ModuleStatus.ACTIVE;
    } catch (Exception  e) {
        logger.error("Security.groovy not found or invalid", e);
        status = ModuleStatus.FAILED;
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:54,代码来源:PageactionsModule.java

示例3: printDDBody

import org.apache.shiro.web.env.WebEnvironment; //导入方法依赖的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.env.WebEnvironment.getWebSecurityManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。