Example usage for org.apache.shiro.guice.web ShiroWebModule guiceFilterModule

List of usage examples for org.apache.shiro.guice.web ShiroWebModule guiceFilterModule

Introduction

In this page you can find the example usage for org.apache.shiro.guice.web ShiroWebModule guiceFilterModule.

Prototype

public static ServletModule guiceFilterModule() 

Source Link

Usage

From source file:org.cgiar.ccafs.ap.config.APGuiceContextListener.java

License:Open Source License

@Override
protected Injector getInjector() {
    return Guice.createInjector(new APShiroWebModule(this.servletContext), ShiroWebModule.guiceFilterModule(),
            new Struts2GuicePluginModule(), new APModule());
}

From source file:org.lbogdanov.poker.web.AppInitializer.java

License:Apache License

/**
 * {@inheritDoc}/*from w w  w  . j a  v a2s .  c om*/
 */
@Override
protected Injector getInjector() {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    try {
        InputStream settings = Resources.newInputStreamSupplier(Resources.getResource("settings.properties"))
                .getInput();
        Properties props = new Properties();
        try {
            props.load(settings);
        } finally {
            settings.close();
        }
        Settings.init(Maps.fromProperties(props));
    } catch (IOException ioe) {
        throw Throwables.propagate(ioe);
    }
    final boolean isDevel = DEVELOPMENT_MODE.asBool().or(false);
    Module shiroModule = new ShiroWebModule(servletContext) {

        @Override
        @SuppressWarnings("unchecked")
        protected void configureShiroWeb() {
            bind(String.class).annotatedWith(Names.named(InjectableOAuthFilter.FAILURE_URL_PARAM))
                    .toInstance("/");
            // TODO simple ini-based realm for development
            bindRealm().toInstance(new IniRealm(IniFactorySupport.loadDefaultClassPathIni()));
            bindRealm().to(InjectableOAuthRealm.class).in(Singleton.class);

            addFilterChain("/" + Constants.OAUTH_CLBK_FILTER_URL, Key.get(InjectableOAuthFilter.class));
            addFilterChain("/" + Constants.OAUTH_FILTER_URL,
                    config(CallbackUrlSetterFilter.class, Constants.OAUTH_CLBK_FILTER_URL),
                    Key.get(InjectableOAuthUserFilter.class));
        }

        @Provides
        @Singleton
        private OAuthProvider getOAuthProvider() {
            Google2Provider provider = new Google2Provider();
            provider.setKey(GOOGLE_OAUTH_KEY.asString().get());
            provider.setSecret(GOOGLE_OAUTH_SECRET.asString().get());
            provider.setCallbackUrl("example.com"); // fake URL, will be replaced by CallbackUrlSetterFilter
            provider.setScope(Google2Scope.EMAIL_AND_PROFILE);
            return provider;
        }

    };
    Module appModule = new ServletModule() {

        @Override
        protected void configureServlets() {
            ServerConfig dbConfig = new ServerConfig();
            String jndiDataSource = DB_DATA_SOURCE.asString().orNull();
            if (Strings.isNullOrEmpty(jndiDataSource)) { // use direct JDBC connection
                DataSourceConfig dsConfig = new DataSourceConfig();
                dsConfig.setDriver(DB_DRIVER.asString().get());
                dsConfig.setUrl(DB_URL.asString().get());
                dsConfig.setUsername(DB_USER.asString().orNull());
                dsConfig.setPassword(DB_PASSWORD.asString().orNull());
                dbConfig.setDataSourceConfig(dsConfig);
            } else {
                dbConfig.setDataSourceJndiName(jndiDataSource);
            }
            dbConfig.setName("PlanningPoker");
            dbConfig.setDefaultServer(true);
            dbConfig.addClass(Session.class);
            dbConfig.addClass(User.class);

            bind(EbeanServer.class).toInstance(EbeanServerFactory.create(dbConfig));
            bind(SessionService.class).to(SessionServiceImpl.class);
            bind(UserService.class).to(UserServiceImpl.class);
            bind(WebApplication.class).to(PokerWebApplication.class);
            bind(MeteorServlet.class).in(Singleton.class);
            bind(ObjectMapper.class).toProvider(new Provider<ObjectMapper>() {

                @Override
                public ObjectMapper get() {
                    SimpleModule module = new SimpleModule().addSerializer(UserSerializer.get());
                    return new ObjectMapper().registerModule(module);
                }

            }).in(Singleton.class);
            String wicketConfig = (isDevel ? RuntimeConfigurationType.DEVELOPMENT
                    : RuntimeConfigurationType.DEPLOYMENT).toString();
            ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
            params.put(ApplicationConfig.FILTER_CLASS, WicketFilter.class.getName())
                    .put(ApplicationConfig.PROPERTY_SESSION_SUPPORT, Boolean.TRUE.toString())
                    .put(ApplicationConfig.BROADCAST_FILTER_CLASSES, TrackMessageSizeFilter.class.getName())
                    .put(ApplicationConfig.BROADCASTER_CACHE, UUIDBroadcasterCache.class.getName())
                    .put(ApplicationConfig.SHOW_SUPPORT_MESSAGE, Boolean.FALSE.toString())
                    .put(WicketFilter.FILTER_MAPPING_PARAM, "/*")
                    .put(WebApplication.CONFIGURATION, wicketConfig)
                    .put(WicketFilter.APP_FACT_PARAM, GuiceWebApplicationFactory.class.getName())
                    .put("injectorContextAttribute", Injector.class.getName()).build();
            serve("/*").with(MeteorServlet.class, params.build());
        }

    };
    Stage stage = isDevel ? Stage.DEVELOPMENT : Stage.PRODUCTION;
    return Guice.createInjector(stage, ShiroWebModule.guiceFilterModule(), shiroModule, appModule);
}

From source file:org.seedstack.seed.web.internal.security.SecurityWebPlugin.java

License:Open Source License

@Override
public Collection<Module> provideOtherModules() {
    Collection<Module> modules = new ArrayList<Module>();
    if (servletContext != null) {
        modules.add(ShiroWebModule.guiceFilterModule());
    }//  w  w  w .  jav  a2s .  co  m
    return modules;
}

From source file:org.seedstack.seed.web.internal.security.WebSecurityProvider.java

License:Open Source License

@Override
public Module provideMainSecurityModule() {
    if (servletContext != null) {
        return Modules.combine(new WebSecurityModule(servletContext, props, scannedFilters, applicationId),
                ShiroWebModule.guiceFilterModule());
    } else {/*from w w  w.j av a2 s .c o m*/
        LOGGER.warn("No servlet context available, Web security disabled.");
        return null;
    }
}

From source file:org.seedstack.seed.web.security.internal.WebSecurityProvider.java

License:Mozilla Public License

@Override
public Module provideMainSecurityModule() {
    if (servletContext != null) {
        return Modules.combine(
                new WebSecurityModule(servletContext, props, scannedFilters, applicationId,
                        new SecurityGuiceConfigurer(securityConfiguration)),
                ShiroWebModule.guiceFilterModule());
    } else {/*w  ww  . jav a  2s .c  o m*/
        LOGGER.warn("No servlet context available, Web security disabled.");
        return null;
    }
}

From source file:streamflow.server.config.WebConfig.java

License:Apache License

@Override
protected Injector getInjector() {
    // Initialize the Streamflow Environment using STREAMFLOW_HOME if available
    StreamflowEnvironment.setStreamflowHome(System.getenv("STREAMFLOW_HOME"));
    StreamflowEnvironment.initialize();//  ww  w  .  j av a2 s  .c  om

    return Guice.createInjector(new ConfigModule(), new DatastoreModule(), new ServiceModule(),
            new EngineModule(), new JerseyModule(), new SecurityModule(servletContext),
            ShiroWebModule.guiceFilterModule());
}