Search in sources :

Example 1 with ServletContainerSessionManager

use of org.apache.shiro.web.session.mgt.ServletContainerSessionManager 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

Injector (com.google.inject.Injector)1 Provides (com.google.inject.Provides)1 ServletContext (javax.servlet.ServletContext)1 ShiroModuleTest (org.apache.shiro.guice.ShiroModuleTest)1 SecurityManager (org.apache.shiro.mgt.SecurityManager)1 SessionManager (org.apache.shiro.session.mgt.SessionManager)1 DefaultWebSecurityManager (org.apache.shiro.web.mgt.DefaultWebSecurityManager)1 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)1 DefaultWebSessionManager (org.apache.shiro.web.session.mgt.DefaultWebSessionManager)1 ServletContainerSessionManager (org.apache.shiro.web.session.mgt.ServletContainerSessionManager)1 Test (org.junit.Test)1