Search in sources :

Example 16 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project Ganster-CMS by Gangster-trio.

the class ShiroConfig method securityManager.

@Bean(name = "securityManager")
public SecurityManager securityManager() {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    // 设置realm
    securityManager.setRealm(shiroRealm());
    return securityManager;
}
Also used : DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 17 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project dropwizard-shiro by silb.

the class ShiroBundle method createFilter.

/**
 * Create the Shiro filter. Overriding this method allows for complete customization of how Shiro is initialized.
 */
protected Filter createFilter(final T configuration) {
    ShiroConfiguration shiroConfig = narrow(configuration);
    final IniWebEnvironment shiroEnv = new IniWebEnvironment();
    shiroEnv.setConfigLocations(shiroConfig.iniConfigs());
    shiroEnv.init();
    AbstractShiroFilter shiroFilter = new AbstractShiroFilter() {

        @Override
        public void init() throws Exception {
            Collection<Realm> realms = createRealms(configuration);
            WebSecurityManager securityManager = realms.isEmpty() ? shiroEnv.getWebSecurityManager() : new DefaultWebSecurityManager(realms);
            setSecurityManager(securityManager);
            setFilterChainResolver(shiroEnv.getFilterChainResolver());
        }
    };
    return shiroFilter;
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) AbstractShiroFilter(org.apache.shiro.web.servlet.AbstractShiroFilter) IniWebEnvironment(org.apache.shiro.web.env.IniWebEnvironment) Realm(org.apache.shiro.realm.Realm)

Example 18 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project wechat by dllwh.

the class ShiroConfig method securityManager.

/**
 * @方法描述 : Shiro安全管理配置
 * @return
 */
// @Bean("securityManager")
public DefaultWebSecurityManager securityManager() {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    // 自定义realm
    securityManager.setRealm(shiroRealm());
    // 自定义缓存实现 使用redis
    // securityManager.setCacheManager(cacheManager());
    // securityManager.setRememberMeManager(rememberMeManager);
    // 自定义session管理 使用redis
    securityManager.setSessionManager(sessionManager());
    return securityManager;
}
Also used : DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager)

Example 19 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project shiro by apache.

the class SampleShiroServletModule method bindWebSecurityManager.

@Override
protected void bindWebSecurityManager(AnnotatedBindingBuilder<? super WebSecurityManager> bind) {
    try {
        String cipherKey = loadShiroIni().getSectionProperty("main", "securityManager.rememberMeManager.cipherKey");
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        CookieRememberMeManager rememberMeManager = new CookieRememberMeManager();
        rememberMeManager.setCipherKey(Base64.decode(cipherKey));
        securityManager.setRememberMeManager(rememberMeManager);
        bind.toInstance(securityManager);
    } catch (MalformedURLException e) {
        // super.bindWebSecurityManager(bind) if you do not need rememberMe functionality
        throw new ConfigurationException("securityManager.rememberMeManager.cipherKey must be set in shiro.ini.");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ConfigurationException(org.apache.shiro.config.ConfigurationException) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) CookieRememberMeManager(org.apache.shiro.web.mgt.CookieRememberMeManager)

Example 20 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project shiro by apache.

the class ShiroWebModuleTest method basicInstantiation.

@Test
public void basicInstantiation() {
    final ShiroModuleTest.MockRealm mockRealm = createMock(ShiroModuleTest.MockRealm.class);
    ServletContext servletContext = createMock(ServletContext.class);
    Injector injector = Guice.createInjector(new ShiroWebModule(servletContext) {

        @Override
        protected void configureShiroWeb() {
            bindRealm().to(ShiroModuleTest.MockRealm.class);
            expose(SessionManager.class);
        }

        @Provides
        public ShiroModuleTest.MockRealm createRealm() {
            return mockRealm;
        }
    });
    // we're not getting a WebSecurityManager here b/c it's not exposed.  There didn't seem to be a good reason to
    // expose it outside of the Shiro module.
    SecurityManager securityManager = injector.getInstance(SecurityManager.class);
    assertNotNull(securityManager);
    assertTrue(securityManager instanceof WebSecurityManager);
    SessionManager sessionManager = injector.getInstance(SessionManager.class);
    assertNotNull(sessionManager);
    assertTrue(sessionManager instanceof ServletContainerSessionManager);
    assertTrue(((DefaultWebSecurityManager) securityManager).getSessionManager() instanceof ServletContainerSessionManager);
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) SecurityManager(org.apache.shiro.mgt.SecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) ServletContainerSessionManager(org.apache.shiro.web.session.mgt.ServletContainerSessionManager) SessionManager(org.apache.shiro.session.mgt.SessionManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) Provides(com.google.inject.Provides) ServletContainerSessionManager(org.apache.shiro.web.session.mgt.ServletContainerSessionManager) Injector(com.google.inject.Injector) ServletContext(javax.servlet.ServletContext) ShiroModuleTest(org.apache.shiro.guice.ShiroModuleTest) Test(org.junit.Test) ShiroModuleTest(org.apache.shiro.guice.ShiroModuleTest)

Aggregations

DefaultWebSecurityManager (org.apache.shiro.web.mgt.DefaultWebSecurityManager)21 ShiroFilterFactoryBean (org.apache.shiro.spring.web.ShiroFilterFactoryBean)9 Bean (org.springframework.context.annotation.Bean)9 Realm (org.apache.shiro.realm.Realm)6 CookieRememberMeManager (org.apache.shiro.web.mgt.CookieRememberMeManager)3 MalformedURLException (java.net.MalformedURLException)2 ConfigurationException (org.apache.shiro.config.ConfigurationException)2 IniRealm (org.apache.shiro.realm.text.IniRealm)2 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)2 DefaultWebSessionManager (org.apache.shiro.web.session.mgt.DefaultWebSessionManager)2 LdapRealm (org.apache.zeppelin.realm.LdapRealm)2 Test (org.junit.Test)2 Injector (com.google.inject.Injector)1 Provides (com.google.inject.Provides)1 ArrayList (java.util.ArrayList)1 Filter (javax.servlet.Filter)1 ServletContext (javax.servlet.ServletContext)1 Cookie (javax.servlet.http.Cookie)1 AuthenticationStrategy (org.apache.shiro.authc.pam.AuthenticationStrategy)1 ModularRealmAuthenticator (org.apache.shiro.authc.pam.ModularRealmAuthenticator)1