Java 类org.apache.shiro.authc.AuthenticationListener 实例源码

项目:bootique-shiro    文件:ShiroModule.java   
@Provides
@Singleton
SecurityManager provideSecurityManager(
        SessionManager sessionManager,
        RememberMeManager rememberMeManager,
        Realms realms,
        Set<AuthenticationListener> authListeners) {


    DefaultSecurityManager manager = new DefaultSecurityManager(realms.getRealms());
    ((AbstractAuthenticator) manager.getAuthenticator()).setAuthenticationListeners(authListeners);
    manager.setSessionManager(sessionManager);
    manager.setRememberMeManager(rememberMeManager);

    return manager;
}
项目:bootique-shiro    文件:ShiroModuleIT.java   
@Test
public void testFullStack_AuthListener() {

    Realm mockRealm = mockRealm();
    AuthenticationListener mockListener = mock(AuthenticationListener.class);

    BQRuntime runtime = testFactory.app()
            .module(b -> ShiroModule
                    .extend(b)
                    .addRealm(mockRealm)
                    .addAuthListener(mockListener))
            .autoLoadModules()
            .createRuntime();

    Subject subject = new Subject.Builder(runtime.getInstance(SecurityManager.class)).buildSubject();
    assertFalse(subject.isAuthenticated());

    // try bad login
    try {
        subject.login(new UsernamePasswordToken("uname", "badpassword"));
        Assert.fail("Should have thrown on bad auth");
    } catch (AuthenticationException authEx) {
        verify(mockListener).onFailure(any(AuthenticationToken.class), any(AuthenticationException.class));
    }

    // try good login
    subject.login(new UsernamePasswordToken("uname", "password"));
    verify(mockListener).onSuccess(any(AuthenticationToken.class), any(AuthenticationInfo.class));
}
项目:bootique-shiro    文件:ShiroWebModule.java   
@Singleton
@Provides
WebSecurityManager provideWebSecurityManager(
        SessionManager sessionManager,
        RememberMeManager rememberMeManager,
        Realms realms,
        Set<AuthenticationListener> authListeners) {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(realms.getRealms());

    // TODO: from here the code is copied from ShiroModule ... error prone... use factory or something
    ((AbstractAuthenticator) securityManager.getAuthenticator()).setAuthenticationListeners(authListeners);
    securityManager.setSessionManager(sessionManager);
    securityManager.setRememberMeManager(rememberMeManager);
    return securityManager;
}
项目:bootique-shiro    文件:ShiroModuleExtender.java   
protected Multibinder<AuthenticationListener> contributeListeners() {
    return listeners != null ? listeners : (listeners = newSet(AuthenticationListener.class));
}
项目:bootique-shiro    文件:ShiroModuleExtender.java   
/**
 * @param listener a listener instance.
 * @return this extender instance.
 * @since 0.25
 */
public ShiroModuleExtender addAuthListener(AuthenticationListener listener) {
    contributeListeners().addBinding().toInstance(listener);
    return this;
}
项目:bootique-shiro    文件:ShiroModuleExtender.java   
/**
 * @param listenerType a class of the auth listener
 * @return this extender instance.
 * @since 0.25
 */
public ShiroModuleExtender addAuthListener(Class<? extends AuthenticationListener> listenerType) {
    contributeListeners().addBinding().to(listenerType);
    return this;
}