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


Java WebEnvironment类代码示例

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


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

示例1: getWebEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
/**
 * 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
 */
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;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:31,代码来源:WebUtils.java

示例2: contextInitialized

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Override
public void contextInitialized( ServletContextEvent sce )
{
    configuration.refresh();
    ShiroIniConfiguration config = configuration.get();
    String iniResourcePath = config.iniResourcePath().get() == null ? "classpath:shiro.ini" : config.iniResourcePath().get();
    sce.getServletContext().setInitParameter( "shiroConfigLocations", iniResourcePath );
    WebEnvironment env = initEnvironment( sce.getServletContext() );

    if ( realmsRefs != null && realmsRefs.iterator().hasNext() ) {

        // Register Realms Services
        RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager();
        Collection<Realm> iniRealms = new ArrayList<Realm>( realmSecurityManager.getRealms() );
        for ( ServiceReference<Realm> realmRef : realmsRefs ) {
            iniRealms.add( realmRef.get() );
            LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
        }
        realmSecurityManager.setRealms( iniRealms );

    }

}
 
开发者ID:apache,项目名称:polygene-java,代码行数:24,代码来源:EnvironmentLoaderService.java

示例3: setup

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Override
protected void setup() {

    String configFile = getSettings().getString("shiro.configurationFile", "classpath:conf/shiro.ini");
    Ini ini = Ini.fromResourcePath(configFile);

    IniWebEnvironment webEnvironment = new IniWebEnvironment();
    webEnvironment.setIni(ini);
    webEnvironment.setServletContext(getServletContext());
    webEnvironment.init();

    bind(WebEnvironment.class).toInstance(webEnvironment);
    bind(SecurityManager.class).toInstance(webEnvironment.getSecurityManager());
    bind(WebSecurityManager.class).toInstance(webEnvironment.getWebSecurityManager());

    String basePath = Strings.nullToEmpty(getSettings().getString(RestServlet.SETTING_URL, null)).trim();
    filter(basePath + "/*").through(ShiroFilter.class);

    install(new AopModule());
}
 
开发者ID:gitblit,项目名称:fathom,代码行数:21,代码来源:ShiroModule.java

示例4: createEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
/**
 * Registers the ModularWebEnvironment to the specified servlet context.
 *
 * @param sc current servlet context
 * @throws IllegalStateException
 *      if an existing WebEnvironment has already been initialized and associated with
 *      the specified {@code ServletContext} or if ModularWebEnvironment is not
 *      prepared to be associated
 */
@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
    if (environment == null) {
        String errMsg = "ModularWebEnvironment must be initialized before setting it "
                + "to servlet context";
        log.error(errMsg);
        throw new IllegalStateException(errMsg);
    }

    environment.setServletContext(sc);

    customizeEnvironment(environment);

    LifecycleUtils.init(environment);

    return environment;
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:27,代码来源:ModularEnvironmentLoader.java

示例5: testInitSecurityFilter

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Test
public void testInitSecurityFilter() throws Exception {
    // expect initializing environment
    expect(environmentLoaderMock.initEnvironment(servletContextMock)).
        andReturn(createMock(WebEnvironment.class));

    expectSettingDefaultLoginUrl();
    expectSettingDefaultPasswordParam();
    expectSettingDefaultRememberMeParam();
    expectSettingDefaultSuccessUrl();
    expectSettingDefaultUsernameParam();

    expect(servletContextMock.getAttribute(EnvironmentLoader.ENVIRONMENT_ATTRIBUTE_KEY)).andReturn(null);

    // perform test
    replayAll();
    filter.init();
    verifyAll();
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:20,代码来源:SecurityFilterImplTest.java

示例6: createEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
    DefaultWebEnvironment webEnvironment = (DefaultWebEnvironment) super.createEnvironment(sc);

    webEnvironment.setSecurityManager(securityManager);
    webEnvironment.setFilterChainResolver(filterChainResolver);

    return webEnvironment;
}
 
开发者ID:nebrass,项目名称:pairing-shiro-javaee7,代码行数:10,代码来源:ShiroListener.java

示例7: init

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

示例8: initEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
public WebEnvironment initEnvironment(ServletContext servletContext) throws IllegalStateException {

        if (servletContext.getAttribute(ENVIRONMENT_ATTRIBUTE_KEY) != null) {
            String msg = "There is already a Shiro environment associated with the current ServletContext.  " +
                    "Check if you have multiple EnvironmentLoader* definitions in your web.xml!";
            throw new IllegalStateException(msg);
        }

        servletContext.log("Initializing Shiro environment");
        LOGGER.info("Starting Shiro environment initialization.");

        long startTime = System.currentTimeMillis();

        try {
            WebEnvironment environment = createEnvironment(servletContext);
            servletContext.setAttribute(ENVIRONMENT_ATTRIBUTE_KEY, environment);

            LOGGER.debug("Published WebEnvironment as ServletContext attribute with name [{}]",
                    ENVIRONMENT_ATTRIBUTE_KEY);

            if (LOGGER.isInfoEnabled()) {
                long elapsed = System.currentTimeMillis() - startTime;
                LOGGER.info("Shiro environment initialized in {} ms.", elapsed);
            }

            return environment;
        } catch (RuntimeException ex) {
            LOGGER.error(ex, "Shiro environment initialization failed");
            servletContext.setAttribute(ENVIRONMENT_ATTRIBUTE_KEY, ex);
            throw ex;
        } catch (Error err) {
            LOGGER.error(err, "Shiro environment initialization failed");
            servletContext.setAttribute(ENVIRONMENT_ATTRIBUTE_KEY, err);
            throw err;
        }
    }
 
开发者ID:Teddy-Zhu,项目名称:SilentGo,代码行数:37,代码来源:ShiroLoader.java

示例9: createEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
protected WebEnvironment createEnvironment(ServletContext sc) {

        Class<?> clazz = determineWebEnvironmentClass(sc);
        if (!MutableWebEnvironment.class.isAssignableFrom(clazz)) {
            throw new ConfigurationException("Custom WebEnvironment class [" + clazz.getName() +
                    "] is not of required type [" + WebEnvironment.class.getName() + "]");
        }

        String configLocations = sc.getInitParameter(CONFIG_LOCATIONS_PARAM);
        boolean configSpecified = StringUtils.hasText(configLocations);

        if (configSpecified && !(ResourceConfigurable.class.isAssignableFrom(clazz))) {
            String msg = "WebEnvironment class [" + clazz.getName() + "] does not implement the " +
                    ResourceConfigurable.class.getName() + "interface.  This is required to accept any " +
                    "configured " + CONFIG_LOCATIONS_PARAM + "value(s).";
            throw new ConfigurationException(msg);
        }

        MutableWebEnvironment environment = (MutableWebEnvironment) ClassUtils.newInstance(clazz);

        environment.setServletContext(sc);

        if (configSpecified && (environment instanceof ResourceConfigurable)) {
            ((ResourceConfigurable) environment).setConfigLocations(configLocations);
        }

        customizeEnvironment(environment);

        //environment.setWebSecurityManager(defaultWebSecurityManager);


        //LifecycleUtils.initialBuild(environment);

        return environment;
    }
 
开发者ID:Teddy-Zhu,项目名称:SilentGo,代码行数:36,代码来源:ShiroLoader.java

示例10: createEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
    WebEnvironment webEnvironment = super.createEnvironment(sc);
    RealmSecurityManager rsm = (RealmSecurityManager) webEnvironment.getSecurityManager();
    HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(HASHING_ALGORITHM);
    hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);
    jpaRealm.setCredentialsMatcher(hashedCredentialsMatcher);      
    Collection<Realm> realms = rsm.getRealms();
    realms.add(jpaRealm);
    rsm.setRealms(realms);
    ((DefaultWebEnvironment) webEnvironment).setSecurityManager(rsm);
    return webEnvironment;
}
 
开发者ID:felixhusse,项目名称:bookery,代码行数:14,代码来源:CDIAwareShiroEnvironmentLoader.java

示例11: createEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Override
protected WebEnvironment createEnvironment(ServletContext servletContext) {
  ShiroWebEnvironment environment = new ShiroWebEnvironment();
  environment.setServletContext(servletContext);
  String configLocations = StringUtils.trimToNull(servletContext.getInitParameter(CONFIG_LOCATIONS_PARAM));
  if (configLocations != null) {
    environment.setConfigLocations(configLocations);
  }
  environment.init();
  return environment;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:12,代码来源:ShiroSecurityEnvironmentLoader.java

示例12: createEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
/**
 * 
 * @param servletContext
 * @return 
 */
@Override
protected WebEnvironment createEnvironment(ServletContext servletContext) {
    
    final DefaultWebEnvironment environment = (DefaultWebEnvironment) 
            super.createEnvironment(servletContext);
    
    environment.setSecurityManager(this.webSecurityManager);
    environment.setFilterChainResolver(this.filterChainResolver);
    
    return environment;
}
 
开发者ID:arthurgregorio,项目名称:exemplos,代码行数:17,代码来源:ShiroListener.java

示例13: 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

示例14: createEnvironment

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Override
protected WebEnvironment createEnvironment(final ServletContext sc) {
	WebEnvironment environment = super.createEnvironment(sc);
	AuthorizingSecurityManager securityManager = (AuthorizingSecurityManager) environment.getSecurityManager();
	securityManager.setAuthorizer(this.authorizer);
	securityManager.setRealm(this.realm);
	return environment;
}
 
开发者ID:lsjunior,项目名称:shiro-cdi,代码行数:9,代码来源:SimpleEnvironmentLoaderListener.java

示例15: initialize

import org.apache.shiro.web.env.WebEnvironment; //导入依赖的package包/类
@Override
public boolean initialize(SilentGo me) throws AppBuildException {


    ShiroConfig config = (ShiroConfig) me.getConfig().getConfig(Name);

    me.getFactory(CacheFactory.class);
    PropKit prop = me.getConfig().getUserProp();

    RetryLimitHashedCredentialsMatcher retryLimitHashedCredentialsMatcher = new RetryLimitHashedCredentialsMatcher();
    retryLimitHashedCredentialsMatcher.setHashAlgorithmName(prop.getValue(Dict.SHIRO_CREDENTIALS_MATCHER_HASHALGORITHMNAME, "md5"));
    retryLimitHashedCredentialsMatcher.setHashIterations(prop.getInt(Dict.SHIRO_CREDENTIALS_MATCHER_HASHITERATIONS, 2));
    retryLimitHashedCredentialsMatcher.setStoredCredentialsHexEncoded(prop.getBool(Dict.SHIRO_CREDENTIALS_MATCHER_STOREDCREDENTIALSHEXENCODED, true));
    EhCacheManager ehCacheManager = new EhCacheManager();
    EhCache cache = (EhCache) me.getConfig().getCacheManager();
    ehCacheManager.setCacheManager(cache.getCacheManager());

    JavaUuidSessionIdGenerator sessionIdGenerator = new JavaUuidSessionIdGenerator();

    SimpleCookie sessionIdCookie = new SimpleCookie(prop.getValue(Dict.SHIRO_SESSION_COOKIENAME, "lc4e"));
    sessionIdCookie.setMaxAge(prop.getInt(Dict.SHIRO_SESSION_IDCOOKIE_MAXAGE, -1));
    sessionIdCookie.setHttpOnly(prop.getBool(Dict.SHIRO_SESSION_IDCOOKIE_HTTPONLY, true));

    SimpleCookie rememberMeCookie = new SimpleCookie(prop.getValue(Dict.SHIRO_SESSION_REMEMBER_COOKIENAME, "rlc4e"));
    rememberMeCookie.setHttpOnly(prop.getBool(Dict.SHIRO_SESSION_REMEMBER_ME_HTTPONLY, true));
    rememberMeCookie.setMaxAge(prop.getInt(Dict.SHIRO_SESSION_REMEMBER_ME_MAXAGE, 2592000));

    CookieRememberMeManager rememberMeManager = new CookieRememberMeManager();
    rememberMeManager.setCipherKey(Base64.decode(prop.getValue(Dict.SECURITY_KEY, "4AvVhmFLUs0KTA3Kprsdag==")));
    rememberMeManager.setCookie(rememberMeCookie);

    EnterpriseCacheSessionDAO sessionDAO = new EnterpriseCacheSessionDAO();
    sessionDAO.setActiveSessionsCacheName(prop.getValue(Dict.SHIRO_SESSION_ACTIVE_NAME, "shiro-activeSessionCache"));
    sessionDAO.setSessionIdGenerator(sessionIdGenerator);
    sessionDAO.setCacheManager(ehCacheManager);


    config.getRealm().setCredentialsMatcher(retryLimitHashedCredentialsMatcher);
    config.getRealm().setCachingEnabled(false);
    config.getRealm().setCacheManager(ehCacheManager);

    DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();

    sessionValidationScheduler = new QuartzSessionValidationScheduler(sessionManager);
    sessionValidationScheduler.setSessionValidationInterval(prop.getLong(Dict.SHIRO_SESSION_VALIDATIONINTERVAL, 1800000L));

    sessionManager.setGlobalSessionTimeout(prop.getLong(Dict.SHIRO_SESSION_GLOBALSESSIONTIMEOUT, 1800000L));
    sessionManager.setSessionDAO(sessionDAO);
    sessionManager.setSessionValidationInterval(prop.getLong(Dict.SHIRO_SESSION_VALIDATIONINTERVAL, 360000L));
    sessionManager.setSessionValidationScheduler(sessionValidationScheduler);
    sessionManager.setSessionIdCookieEnabled(prop.getBool(Dict.SHIRO_SESSION_IDCOOKIEENABLED, true));
    sessionManager.setSessionIdCookie(sessionIdCookie);


    sessionValidationScheduler.setSessionManager(sessionManager);

    defaultWebSecurityManager = new DefaultWebSecurityManager(config.getRealm());
    defaultWebSecurityManager.setCacheManager(ehCacheManager);
    defaultWebSecurityManager.setRememberMeManager(rememberMeManager);
    defaultWebSecurityManager.setSessionManager(sessionManager);


    ServletContext servletContext = me.getContext();

    ShiroLoader shiroLoader = new ShiroLoader();

    shiroLoader.initEnvironment(servletContext);
    WebEnvironment environment = (WebEnvironment) servletContext.getAttribute(ShiroLoader.ENVIRONMENT_ATTRIBUTE_KEY);
    ((MutableWebEnvironment) environment).setWebSecurityManager(defaultWebSecurityManager);
    servletContext.setAttribute(ShiroLoader.ENVIRONMENT_ATTRIBUTE_KEY, environment);

    return false;
}
 
开发者ID:Teddy-Zhu,项目名称:SilentGo,代码行数:74,代码来源:ShiroFactory.java


注:本文中的org.apache.shiro.web.env.WebEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。