Search in sources :

Example 1 with SecurityUtil

use of io.javalin.core.security.SecurityUtil in project javalin by tipsy.

the class JavalinConfig method applyUserConfig.

public static void applyUserConfig(Javalin app, JavalinConfig config, Consumer<JavalinConfig> userConfig) {
    // apply user config to the default config
    userConfig.accept(config);
    AtomicBoolean anyHandlerAdded = new AtomicBoolean(false);
    app.events(listener -> {
        listener.handlerAdded(x -> anyHandlerAdded.set(true));
        listener.wsHandlerAdded(x -> anyHandlerAdded.set(true));
    });
    config.getPluginsExtending(PluginLifecycleInit.class).forEach(plugin -> {
        plugin.init(app);
        if (anyHandlerAdded.get()) {
            // check if any "init" added a handler
            throw new PluginInitLifecycleViolationException(((Plugin) plugin).getClass());
        }
    });
    config.inner.plugins.values().forEach(plugin -> plugin.apply(app));
    if (config.enforceSsl) {
        app.before(SecurityUtil::sslRedirect);
    }
    config.inner.appAttributes.putIfAbsent(JSON_MAPPER_KEY, new JavalinJackson());
    app.attribute(maxRequestSizeKey, config.maxRequestSize);
    config.inner.appAttributes.putIfAbsent(CONTEXT_RESOLVER_KEY, new ContextResolver());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PluginInitLifecycleViolationException(io.javalin.core.plugin.PluginInitLifecycleViolationException) JavalinJackson(io.javalin.plugin.json.JavalinJackson) PluginLifecycleInit(io.javalin.core.plugin.PluginLifecycleInit) SecurityUtil(io.javalin.core.security.SecurityUtil) ContextResolver(io.javalin.http.ContextResolver)

Aggregations

PluginInitLifecycleViolationException (io.javalin.core.plugin.PluginInitLifecycleViolationException)1 PluginLifecycleInit (io.javalin.core.plugin.PluginLifecycleInit)1 SecurityUtil (io.javalin.core.security.SecurityUtil)1 ContextResolver (io.javalin.http.ContextResolver)1 JavalinJackson (io.javalin.plugin.json.JavalinJackson)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1