use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class ShiroWebModuleTest method testBindWebSecurityManager.
@Test
public void testBindWebSecurityManager() throws Exception {
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(WebSecurityManager.class);
}
@Provides
public ShiroModuleTest.MockRealm createRealm() {
return mockRealm;
}
@Override
protected void bindWebSecurityManager(AnnotatedBindingBuilder<? super WebSecurityManager> bind) {
bind.to(MyDefaultWebSecurityManager.class).asEagerSingleton();
}
});
SecurityManager securityManager = injector.getInstance(SecurityManager.class);
assertNotNull(securityManager);
assertTrue(securityManager instanceof MyDefaultWebSecurityManager);
WebSecurityManager webSecurityManager = injector.getInstance(WebSecurityManager.class);
assertNotNull(webSecurityManager);
assertTrue(webSecurityManager instanceof MyDefaultWebSecurityManager);
// SHIRO-435: Check both keys SecurityManager and WebSecurityManager are bound to the same instance
assertTrue(securityManager == webSecurityManager);
}
use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class ShiroModuleTest method testBindSecurityManager.
@Test
public void testBindSecurityManager() {
final MockRealm mockRealm = createMock(MockRealm.class);
Injector injector = Guice.createInjector(new ShiroModule() {
@Override
protected void configureShiro() {
bindRealm().to(MockRealm.class);
}
@Provides
public MockRealm createRealm() {
return mockRealm;
}
@Override
protected void bindSecurityManager(AnnotatedBindingBuilder<? super SecurityManager> bind) {
bind.to(MyDefaultSecurityManager.class);
}
});
SecurityManager securityManager = injector.getInstance(SecurityManager.class);
assertNotNull(securityManager);
assertTrue(securityManager instanceof MyDefaultSecurityManager);
}
use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class ShiroModuleTest method testBindSessionManager.
@Test
public void testBindSessionManager() {
final MockRealm mockRealm = createMock(MockRealm.class);
Injector injector = Guice.createInjector(new ShiroModule() {
@Override
protected void configureShiro() {
bindRealm().to(MockRealm.class);
}
@Provides
public MockRealm createRealm() {
return mockRealm;
}
@Override
protected void bindSessionManager(AnnotatedBindingBuilder<SessionManager> bind) {
bind.to(MyDefaultSessionManager.class);
}
});
DefaultSecurityManager securityManager = (DefaultSecurityManager) injector.getInstance(SecurityManager.class);
assertNotNull(securityManager);
assertNotNull(securityManager.getSessionManager());
assertTrue(securityManager.getSessionManager() instanceof MyDefaultSessionManager);
}
use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class ShiroModuleTest method basicInstantiation.
@Test
public void basicInstantiation() {
final MockRealm mockRealm = createMock(MockRealm.class);
Injector injector = Guice.createInjector(new ShiroModule() {
@Override
protected void configureShiro() {
bindRealm().to(MockRealm.class);
}
@Provides
public MockRealm createRealm() {
return mockRealm;
}
});
SecurityManager securityManager = injector.getInstance(SecurityManager.class);
assertNotNull(securityManager);
}
use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class ShiroModuleTest method testConfigure.
@Test
public void testConfigure() {
final MockRealm mockRealm = createMock(MockRealm.class);
AuthenticationToken authToken = createMock(AuthenticationToken.class);
AuthenticationInfo info = new SimpleAuthenticationInfo("mockUser", "password", "mockRealm");
expect(mockRealm.supports(authToken)).andReturn(true);
expect(mockRealm.getAuthenticationInfo(authToken)).andReturn(info);
replay(mockRealm);
Injector injector = Guice.createInjector(new ShiroModule() {
@Override
protected void configureShiro() {
bindRealm().to(MockRealm.class);
}
@Provides
public MockRealm createRealm() {
return mockRealm;
}
});
SecurityManager securityManager = injector.getInstance(SecurityManager.class);
assertNotNull(securityManager);
SecurityUtils.setSecurityManager(securityManager);
final Subject subject = new Subject.Builder(securityManager).buildSubject();
securityManager.login(subject, authToken);
verify(mockRealm);
}
Aggregations