Search in sources :

Example 11 with SessionStore

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");
}
Also used : LocalSessionStore(io.vertx.ext.web.sstore.LocalSessionStore) SessionStore(io.vertx.ext.web.sstore.SessionStore) JsonObject(io.vertx.core.json.JsonObject) AuthProvider(io.vertx.ext.auth.AuthProvider) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) Test(org.junit.Test)

Example 12 with SessionStore

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()));
        }
    });
}
Also used : ClusteredSessionStore(io.vertx.ext.web.sstore.ClusteredSessionStore) SessionStore(io.vertx.ext.web.sstore.SessionStore) LocalSessionStore(io.vertx.ext.web.sstore.LocalSessionStore) SessionHandler(io.vertx.ext.web.handler.SessionHandler) HttpServerResponse(io.vertx.core.http.HttpServerResponse) CorsHandler(io.vertx.ext.web.handler.CorsHandler)

Aggregations

SessionStore (io.vertx.ext.web.sstore.SessionStore)12 LocalSessionStore (io.vertx.ext.web.sstore.LocalSessionStore)10 ClusteredSessionStore (io.vertx.ext.web.sstore.ClusteredSessionStore)6 JsonObject (io.vertx.core.json.JsonObject)4 AuthProvider (io.vertx.ext.auth.AuthProvider)4 Test (org.junit.Test)4 SessionHandler (io.vertx.ext.web.handler.SessionHandler)3 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)2 CorsHandler (io.vertx.ext.web.handler.CorsHandler)2 VxApiCertOptions (com.szmirren.vxApi.core.options.VxApiCertOptions)1 AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 VertxOptions (io.vertx.core.VertxOptions)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpMethod (io.vertx.core.http.HttpMethod)1 PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)1 PfxOptions (io.vertx.core.net.PfxOptions)1