use of io.knotx.server.configuration.KnotxCSRFConfig in project knotx by Cognifide.
the class KnotxServerVerticle method start.
@Override
public void start(Future<Void> fut) {
LOGGER.info("Starting <{}>", this.getClass().getSimpleName());
KnotxCSRFConfig csrfConfig = configuration.getCsrfConfig();
CSRFHandler csrfHandler = CSRFHandler.create(csrfConfig.getSecret()).setNagHttps(// Generates warning message in log if https is not used
true).setCookieName(csrfConfig.getCookieName()).setCookiePath(csrfConfig.getCookiePath()).setHeaderName(csrfConfig.getHeaderName()).setTimeout(csrfConfig.getTimeout());
Router router = Router.router(vertx);
if (configuration.getAccessLogConfig().isEnabled()) {
router.route().handler(LoggerHandler.create(configuration.getAccessLogConfig().isImmediate(), configuration.getAccessLogConfig().getFormat()));
}
router.route().handler(KnotxHeaderHandler.create(configuration));
router.route().handler(SupportedMethodsAndPathsHandler.create(configuration));
router.route().handler(CookieHandler.create());
router.route().handler(BodyHandler.create(configuration.getFileUploadDirectory()).setBodyLimit(configuration.getFileUploadLimit()));
router.route().handler(KnotxContextHandler.create());
configuration.getDefaultFlow().getEngineRouting().forEach((key, value) -> {
value.forEach(criteria -> {
if (criteria.isCsrfEnabled()) {
router.route().method(key).pathRegex(criteria.path()).handler(csrfHandler);
}
router.route().method(key).pathRegex(criteria.path()).handler(KnotxRepositoryHandler.create(vertx, configuration));
router.route().method(key).pathRegex(criteria.path()).handler(KnotxSplitterHandler.create(vertx, configuration));
router.route().method(key).pathRegex(criteria.path()).handler(KnotxEngineHandler.create(vertx, configuration, criteria.address(), criteria.onTransition()));
router.route().method(key).pathRegex(criteria.path()).handler(KnotxAssemblerHandler.create(vertx, configuration));
});
});
if (configuration.getCustomFlow().getEngineRouting() != null) {
configuration.getCustomFlow().getEngineRouting().forEach((key, value) -> {
value.forEach(criteria -> {
if (criteria.isCsrfEnabled()) {
router.route().method(key).pathRegex(criteria.path()).handler(csrfHandler);
}
router.route().method(key).pathRegex(criteria.path()).handler(KnotxGatewayContextHandler.create(vertx, configuration, criteria.address()));
router.route().method(key).pathRegex(criteria.path()).handler(KnotxEngineHandler.create(vertx, configuration, criteria.address(), criteria.onTransition()));
router.route().method(key).pathRegex(criteria.path()).handler(KnotxGatewayResponseProviderHandler.create(vertx, configuration));
});
});
}
router.route().failureHandler(ErrorHandler.create(configuration.displayExceptionDetails()));
createHttpServer().requestHandler(request -> {
try {
router.accept(request);
} catch (IllegalArgumentException ex) {
LOGGER.warn("Problem decoding Query String", ex);
request.response().setStatusCode(BAD_REQUEST.code()).setStatusMessage(BAD_REQUEST.reasonPhrase()).end("Invalid characters in Query Parameter");
}
}).rxListen().subscribe(ok -> {
LOGGER.info("Knot.x HTTP Server started. Listening on port {}", configuration.getServerOptions().getInteger("port"));
fut.complete();
}, error -> {
LOGGER.error("Unable to start Knot.x HTTP Server.", error.getCause());
fut.fail(error);
});
}
Aggregations