Example usage for org.apache.shiro SecurityUtils getSecurityManager

List of usage examples for org.apache.shiro SecurityUtils getSecurityManager

Introduction

In this page you can find the example usage for org.apache.shiro SecurityUtils getSecurityManager.

Prototype

public static SecurityManager getSecurityManager() throws UnavailableSecurityManagerException 

Source Link

Document

Returns the SecurityManager accessible to the calling code.

Usage

From source file:uk.co.q3c.v7.base.shiro.AbstractShiroTest.java

License:Apache License

protected static V7SecurityManager getSecurityManager() {
    return (V7SecurityManager) SecurityUtils.getSecurityManager();
}

From source file:uk.co.q3c.v7.base.shiro.V7SecurityManagerTest.java

License:Apache License

@Test
public void listeners() {

    // given/*from ww w . jav  a2s  .c o m*/
    V7SecurityManager securityManager = (V7SecurityManager) SecurityUtils.getSecurityManager();
    securityManager.addListener(monitor1);
    securityManager.addListener(monitor2);
    UsernamePasswordToken token = new UsernamePasswordToken("xxx", "password");
    // when
    getSubject().login(token);
    // then
    // subject may get re-created, so cannot rely on the instance
    verify(monitor1, times(1)).updateStatus(any(Subject.class));
    verify(monitor2, times(1)).updateStatus(any(Subject.class));

    // when
    getSubject().logout();
    // 1 already recorded, plus 1 for logout
    verify(monitor1, times(2)).updateStatus(any(Subject.class));
    verify(monitor2, times(2)).updateStatus(any(Subject.class));
}

From source file:uk.q3c.krail.core.guice.DefaultBindingManagerTest.java

License:Apache License

@Test
public void startAndStop() throws Exception {

    //then//w  ww.  j a  v  a 2  s .  com
    assertThat(DefaultBindingManager.injector()).isNull();
    // given
    TestBindingManager bindingManager = new TestBindingManager();
    when(servletContextEvent.getServletContext()).thenReturn(servletContext);
    bindingManager.contextInitialized(servletContextEvent);
    when(service.getServiceKey()).thenReturn(new ServiceKey(LabelKey.Yes));
    logMonitor.addClassFilter(DefaultServicesModel.class);

    // when
    Injector injector = bindingManager.getInjector();
    // then
    assertThat(SecurityUtils.getSecurityManager()).isInstanceOf(KrailSecurityManager.class);
    assertThat(injector).isNotNull();
    assertThat(injector.getInstance(Dummy.class)).isNotNull();
    assertThat(DefaultBindingManager.injector()).isEqualTo(injector);

    // when
    bindingManager.contextDestroyed(servletContextEvent);

    // then
    assertThat(logMonitor.infoLogs()).contains("Stopping all services");

}

From source file:uk.q3c.krail.core.shiro.AbstractShiroTest.java

License:Apache License

protected static KrailSecurityManager getSecurityManager() {
    return (KrailSecurityManager) SecurityUtils.getSecurityManager();
}

From source file:uk.q3c.krail.core.shiro.ShiroVaadinModule.java

License:Apache License

@Provides
KrailSecurityManager providesSecurityManager() {
    return (KrailSecurityManager) SecurityUtils.getSecurityManager();
}