use of io.vertx.ext.web.sstore.SessionStore in project vertx-web by vert-x3.
the class EventbusBridgeTest method testSendRequiresAuthorityHasnotAuthority.
@Test
public void testSendRequiresAuthorityHasnotAuthority() throws Exception {
sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("pick_nose")));
router.clear();
router.route().handler(CookieHandler.create());
SessionStore store = LocalSessionStore.create(vertx);
router.route().handler(SessionHandler.create(store));
JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties");
AuthProvider authProvider = ShiroAuth.create(vertx, ShiroAuthRealmType.PROPERTIES, authConfig);
addLoginHandler(router, authProvider);
router.route("/eventbus/*").handler(sockJSHandler);
testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foo"), "access_denied");
}
use of io.vertx.ext.web.sstore.SessionStore in project VX-API-Gateway by EliMirren.
the class VxApiApplication method createHttpServer.
/**
* 创建http服务器
*
* @param createHttp
*/
public void createHttpServer(Handler<AsyncResult<Void>> createHttp) {
this.httpRouter = Router.router(vertx);
httpRouter.route().handler(this::filterBlackIP);
httpRouter.route().handler(CookieHandler.create());
SessionStore sessionStore = null;
if (vertx.isClustered()) {
sessionStore = ClusteredSessionStore.create(vertx);
} else {
sessionStore = LocalSessionStore.create(vertx);
}
SessionHandler sessionHandler = SessionHandler.create(sessionStore);
sessionHandler.setSessionCookieName(appOption.getSessionCookieName());
sessionHandler.setSessionTimeout(appOption.getSessionTimeOut());
httpRouter.route().handler(sessionHandler);
httpRouter.route().handler(BodyHandler.create().setUploadsDirectory("../temp/file-uploads").setBodyLimit(appOption.getContentLength()));
// 跨域处理
if (corsOptions != null) {
CorsHandler corsHandler = CorsHandler.create(corsOptions.getAllowedOrigin());
corsHandler.allowedHeaders(corsOptions.getAllowedHeaders()).allowCredentials(corsOptions.isAllowCredentials()).exposedHeaders(corsOptions.getExposedHeaders()).allowedMethods(corsOptions.getAllowedMethods()).maxAgeSeconds(corsOptions.getMaxAgeSeconds());
httpRouter.route().handler(corsHandler);
}
// 如果在linux系统开启epoll
if (vertx.isNativeTransportEnabled()) {
serverOptions.setTcpFastOpen(true).setTcpCork(true).setTcpQuickAck(true).setReusePort(true);
}
// 404页面
httpRouter.route().order(999999).handler(rct -> {
HttpServerResponse response = rct.response();
if (appOption.getNotFoundContentType() != null) {
response.putHeader("Content-Type", appOption.getNotFoundContentType());
}
response.end(appOption.getNotFoundResult());
});
// 创建http服务器
vertx.createHttpServer(serverOptions).requestHandler(httpRouter::accept).listen(serverOptions.getHttpPort(), res -> {
if (res.succeeded()) {
System.out.println(MessageFormat.format("{0} Running on port {1} by HTTP", appOption.getAppName(), Integer.toString(serverOptions.getHttpPort())));
createHttp.handle(Future.succeededFuture());
} else {
System.out.println("create HTTP Server failed : " + res.cause());
createHttp.handle(Future.failedFuture(res.cause()));
}
});
}
Aggregations