Example usage for org.apache.shiro.guice ShiroModule ShiroModule

List of usage examples for org.apache.shiro.guice ShiroModule ShiroModule

Introduction

In this page you can find the example usage for org.apache.shiro.guice ShiroModule ShiroModule.

Prototype

ShiroModule

Source Link

Usage

From source file:org.atteo.moonshine.shiro.ShiroService.java

License:Apache License

@Override
public Module configure() {
    return new PrivateModule() {
        @Override/*from   w w  w .  j ava 2s.  c  o  m*/
        protected void configure() {
            install(new ShiroModule() {
                @Override
                protected void configureShiro() {
                    Multibinder<Realm> setBinder = Multibinder.newSetBinder(binder(), Realm.class);
                    for (RealmService realm : realms) {
                        if (realm.getId() == null) {
                            setBinder.addBinding().to(Realm.class);
                        } else {
                            setBinder.addBinding().to(Key.get(Realm.class, Names.named(realm.getId())));
                        }

                    }

                    try {
                        // Guice will initialize manager with list of realms
                        bind(WebSecurityManager.class)
                                .toConstructor(DefaultWebSecurityManager.class.getConstructor(Collection.class))
                                .asEagerSingleton();
                    } catch (NoSuchMethodException e) {
                        addError(e);
                    }
                    expose(WebSecurityManager.class);
                }

                @Override
                protected void bindSessionManager(AnnotatedBindingBuilder<SessionManager> bind) {
                    // make configurable
                    bind.to(DefaultWebSessionManager.class).asEagerSingleton();
                }
            });
            FilterChainResolver filterChainResolver = new FilterChainResolver() {
                @Override
                public FilterChain getChain(ServletRequest request, ServletResponse response,
                        FilterChain chain) {
                    return null;
                }
            };
            bind(FilterChainResolver.class).toInstance(filterChainResolver);

            bind(GuiceShiroFilter.class).asEagerSingleton();

            install(ShiroWebModule.guiceFilterModule(prefix));
            if (aop) {
                install(new ShiroAopModule());
            }

            expose(SecurityManager.class);
            expose(WebSecurityManager.class);
        }
    };
}

From source file:org.seedstack.seed.security.fixtures.AdditionalSecurityProvider.java

License:Open Source License

@Override
public Module provideAdditionalSecurityModule() {
    return new ShiroModule() {
        @Override/*from   w ww .  j  a v a 2 s . c o  m*/
        protected void configureShiro() {
            try {
                bind(org.apache.shiro.mgt.SecurityManager.class).annotatedWith(Names.named("test"))
                        .toConstructor(DefaultSecurityManager.class.getConstructor(Collection.class))
                        .asEagerSingleton();
            } catch (NoSuchMethodException e) {
                throw new RuntimeException("Internal error", e);
            }

            expose(SecurityManager.class).annotatedWith(Names.named("test"));
        }
    };
}