Example usage for org.apache.shiro.config IniFactorySupport loadDefaultClassPathIni

List of usage examples for org.apache.shiro.config IniFactorySupport loadDefaultClassPathIni

Introduction

In this page you can find the example usage for org.apache.shiro.config IniFactorySupport loadDefaultClassPathIni.

Prototype

public static Ini loadDefaultClassPathIni() 

Source Link

Document

Returns a new Ini instance created from the default classpath:shiro.ini file, or null if the file does not exist.

Usage

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

License:Apache License

/**
 * {@inheritDoc}/*from w ww  . ja va 2 s .  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);
}