io.vertx.ext.web.handler.SessionHandler Java Examples

The following examples show how to use io.vertx.ext.web.handler.SessionHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertxVaadin.java    From vertx-vaadin with MIT License 6 votes vote down vote up
private void initSockJS(Router vaadinRouter, SessionHandler sessionHandler) {
    if (this.config.supportsSockJS()) {
        SockJSHandlerOptions options = new SockJSHandlerOptions()
            .setSessionTimeout(config().sessionTimeout())
            .setHeartbeatInterval(service.getDeploymentConfiguration().getHeartbeatInterval() * 1000);
        SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);

        SockJSPushHandler pushHandler = new SockJSPushHandler(service, sessionHandler, sockJSHandler);

        String pushPath = config.pushURL().replaceFirst("/$", "") + "/*";
        logger.debug("Setup PUSH communication on {}", pushPath);

        vaadinRouter.route(pushPath).handler(rc -> {
            if (ApplicationConstants.REQUEST_TYPE_PUSH.equals(rc.request().getParam(ApplicationConstants.REQUEST_TYPE_PARAMETER))) {
                pushHandler.handle(rc);
            } else {
                rc.next();
            }
        });
    } else {
        logger.info("PUSH communication over SockJS is disabled");
    }
}
 
Example #2
Source File: SessionManager.java    From festival with Apache License 2.0 5 votes vote down vote up
private void resolveAndSetSessionProperties(SessionHandler sessionHandler) {
    Boolean cookieHttpOnly = resourceReader.readProperty(ServerProperty.SERVER_COOKIE_HTTP_ONLY, Boolean.class);
    if (cookieHttpOnly != null) {
        sessionHandler.setCookieHttpOnlyFlag(cookieHttpOnly);
    }

    Boolean cookieSecure = resourceReader.readProperty(ServerProperty.SERVER_COOKIE_SECURE, Boolean.class);
    if (cookieSecure != null) {
        sessionHandler.setCookieSecureFlag(cookieSecure);
    }

    Long sessionTimeout = resourceReader.readProperty(ServerProperty.SERVER_SESSION_TIMEOUT, Long.class);
    if (sessionTimeout != null) {
        sessionHandler.setSessionTimeout(sessionTimeout);
    }

    String sessionCookieName = resourceReader.readProperty(ServerProperty.SERVER_SESSION_COOKIE_NAME, String.class);
    if (!StringUtils.isEmpty(sessionCookieName)) {
        sessionHandler.setSessionCookieName(sessionCookieName);
    }

    String sessionCookiePath = resourceReader.readProperty(ServerProperty.SERVER_SESSION_COOKIE_PATH, String.class);
    if (!StringUtils.isEmpty(sessionCookiePath)) {
        sessionHandler.setSessionCookiePath(sessionCookiePath);
    }

}
 
Example #3
Source File: SockJSTestBase.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
void startServers() throws Exception {
  CountDownLatch latch = new CountDownLatch(1);
  vertx.deployVerticle(() -> new AbstractVerticle() {
    @Override
    public void start(Promise<Void> startFuture) throws Exception {

      Router router = Router.router(vertx);
      router.route()
        .handler(SessionHandler.create(LocalSessionStore.create(vertx))
          .setNagHttps(false)
          .setSessionTimeout(60 * 60 * 1000));

      if (preSockJSHandlerSetup != null) {
        preSockJSHandlerSetup.accept(router);
      }

      SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
      SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
      sockJSHandler.socketHandler(socketHandler.get());
      router.route("/test/*").handler(sockJSHandler);

      vertx.createHttpServer(new HttpServerOptions().setPort(8080).setHost("localhost"))
        .requestHandler(router)
        .listen(ar -> {
          if (ar.succeeded()) {
            startFuture.complete();
          } else {
            startFuture.fail(ar.cause());
          }
        });
    }
  }, new DeploymentOptions().setInstances(numServers), onSuccess(id -> latch.countDown()));
  awaitLatch(latch);
}
 
Example #4
Source File: RouteWithSessionTest.java    From rest.vertx with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void start() {

    before();

    Router router = Router.router(vertx);
    SessionHandler handler = SessionHandler.create(LocalSessionStore.create(vertx));
    router.route().handler(handler);
    RestRouter.register(router, TestSessionRest.class);

    vertx.createHttpServer()
            .requestHandler(router)
            .listen(PORT);
}
 
Example #5
Source File: SockJSPushHandler.java    From vertx-vaadin with MIT License 5 votes vote down vote up
public SockJSPushHandler(VertxVaadinService service, SessionHandler sessionHandler, SockJSHandler sockJSHandler) {
    this.service = service;
    this.sessionHandler = sessionHandler;
    this.sockJSHandler = sockJSHandler;
    this.connectedSocketsLocalMap = socketsMap(service.getVertx());
    this.sockJSHandler.socketHandler(this::onConnect);
}
 
Example #6
Source File: SessionManager.java    From festival with Apache License 2.0 5 votes vote down vote up
public void registerSessionHandler() throws BeansException {
    SessionStore sessionStore = getOrCreateSessionStore();
    SessionHandler sessionHandler = SessionHandler.create(sessionStore);

    resolveAndSetSessionProperties(sessionHandler);

    AuthProvider authProvider = getAuthProvider();
    if (authProvider != null) {
        sessionHandler.setAuthProvider(authProvider);
    }

    router.route().handler(sessionHandler);
}
 
Example #7
Source File: VertxVaadin.java    From vertx-vaadin with MIT License 5 votes vote down vote up
private void initSockJS(Router vaadinRouter, SessionHandler sessionHandler) {
    logger.debug("Routing PUSH requests on /PUSH/* ");
    SockJSHandlerOptions options = new SockJSHandlerOptions()
        .setSessionTimeout(config().getLong("sessionTimeout", DEFAULT_SESSION_TIMEOUT))
        .setHeartbeatInterval(service.getDeploymentConfiguration().getHeartbeatInterval() * 1000);
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
    SockJSPushHandler pushHandler = new SockJSPushHandler(service, sessionHandler, sockJSHandler);
    vaadinRouter.route("/PUSH/*").handler(pushHandler);
}
 
Example #8
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setAuthProvider(AuthProvider authProvider) {
    this.authProvider = authProvider;
    return this;
}
 
Example #9
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setCookieless(boolean cookieless) {
  this.cookieless = cookieless;
  return this;
}
 
Example #10
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public SessionHandler setAuthProvider(AuthProvider authProvider) {
  return this;
}
 
Example #11
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setLazySession(boolean lazySession) {
  this.lazySession = lazySession;
  return this;
}
 
Example #12
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setCookieSameSite(CookieSameSite policy) {
  this.cookieSameSite = policy;
  return this;
}
 
Example #13
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setMinLength(int minLength) {
  this.minLength = minLength;
  return this;
}
 
Example #14
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setSessionCookiePath(String sessionCookiePath) {
  this.sessionCookiePath = sessionCookiePath;
  return this;
}
 
Example #15
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setSessionCookieName(String sessionCookieName) {
  this.sessionCookieName = sessionCookieName;
  return this;
}
 
Example #16
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setCookieHttpOnlyFlag(boolean httpOnly) {
  this.sessionCookieHttpOnly = httpOnly;
  return this;
}
 
Example #17
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setCookieSecureFlag(boolean secure) {
  this.sessionCookieSecure = secure;
  return this;
}
 
Example #18
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setNagHttps(boolean nag) {
  this.nagHttps = nag;
  return this;
}
 
Example #19
Source File: SessionHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setSessionTimeout(long timeout) {
  this.sessionTimeout = timeout;
  return this;
}
 
Example #20
Source File: RestAPIVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
/**
 * Enable clustered session storage in requests.
 *
 * @param router router instance
 */
protected void enableClusteredSession(Router router) {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(
    ClusteredSessionStore.create(vertx, "shopping.user.session")));
}
 
Example #21
Source File: RestAPIVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
/**
 * Enable local session storage in requests.
 *
 * @param router router instance
 */
protected void enableLocalSession(Router router) {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(
    LocalSessionStore.create(vertx, "shopping.user.session")));
}
 
Example #22
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setMinLength(int minLength) {
    this.minLength = minLength;
    return this;
}
 
Example #23
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setSessionCookiePath(String sessionCookiePath) {
    this.sessionCookiePath = sessionCookiePath;
    return this;
}
 
Example #24
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setSessionCookieName(String sessionCookieName) {
    this.sessionCookieName = sessionCookieName;
    return this;
}
 
Example #25
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setCookieHttpOnlyFlag(boolean httpOnly) {
    this.sessionCookieHttpOnly = httpOnly;
    return this;
}
 
Example #26
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setCookieSecureFlag(boolean secure) {
    this.sessionCookieSecure = secure;
    return this;
}
 
Example #27
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setNagHttps(boolean nag) {
    this.nagHttps = nag;
    return this;
}
 
Example #28
Source File: SessionHandlerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public SessionHandler setSessionTimeout(long timeout) {
    this.sessionTimeout = timeout;
    return this;
}
 
Example #29
Source File: CloudIamAuthNexusProxyVerticle.java    From nexus-proxy with Apache License 2.0 4 votes vote down vote up
@Override
protected void preconfigureRouting(final Router router) {
    router.route().handler(CookieHandler.create());
    router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)).setSessionTimeout(SESSION_TTL));
}
 
Example #30
Source File: ClientVerticle.java    From VX-API-Gateway with MIT License 4 votes vote down vote up
@Override
public void start(Promise<Void> fut) throws Exception {
	LOG.info("start Client Verticle ...");
	thisVertxName = System.getProperty("thisVertxName", "VX-API");
	Router router = Router.router(vertx);
	router.route().handler(FaviconHandler.create(getFaviconPath()));
	router.route().handler(BodyHandler.create().setUploadsDirectory(getUploadsDirectory()));
	if (vertx.isClustered()) {
		router.route().handler(
				SessionHandler.create(ClusteredSessionStore.create(vertx)).setSessionCookieName(VxApiGatewayAttribute.SESSION_COOKIE_NAME));
	} else {
		router.route()
				.handler(SessionHandler.create(LocalSessionStore.create(vertx)).setSessionCookieName(VxApiGatewayAttribute.SESSION_COOKIE_NAME));
	}
	// 通过html的方式管理应用网关
	// TemplateEngine create = FreeMarkerTemplateEngine.create(vertx);
	// TemplateHandler tempHandler = TemplateHandler.create(create, getTemplateRoot(), CONTENT_VALUE_HTML_UTF8);
	TemplateHandler tempHandler = new FreeMarkerTemplateHander(vertx, getTemplateRoot(), CONTENT_VALUE_HTML_UTF8);
	router.getWithRegex(".+\\.ftl").handler(tempHandler);
	// 权限相关
	router.route("/static/*").handler(VxApiClientStaticAuth.create());
	router.route("/static/*").handler(this::staticAuth);
	router.route("/loginOut").handler(this::loginOut);
	router.route("/static/CreateAPI.html").handler(this::staticAPI);
	router.route("/static/CreateAPP.html").handler(this::staticAPP);

	router.route("/static/*").handler(StaticHandler.create(getStaticRoot()));
	// 查看系统信息
	router.route("/static/sysInfo").handler(this::sysInfo);
	router.route("/static/sysReplaceIpList").handler(this::sysReplaceIpList);
	// Application相关
	router.route("/static/findAPP").handler(this::findAPP);
	router.route("/static/getAPP/:name").handler(this::getAPP);
	router.route("/static/addAPP").handler(this::addAPP);
	router.route("/static/delAPP/:name").handler(this::delAPP);
	router.route("/static/updtAPP/:name").handler(this::loadUpdtAPP);
	router.route("/static/updtAPP").handler(this::updtAPP);

	router.route("/static/deployAPP/:name").handler(this::deployAPP);
	router.route("/static/unDeployAPP/:name").handler(this::unDeployAPP);
	// API相关
	router.route("/static/findAPI/:name").handler(this::findAPI);
	router.route("/static/getAPI/:name").handler(this::getAPI);
	router.route("/static/addAPI").handler(this::addAPI);
	router.route("/static/updtAPI/:name").handler(this::loadUpdtAPI);
	router.route("/static/updtAPI").handler(this::updtAPI);
	router.route("/static/delAPI/:appName/:apiName").handler(this::delAPI);

	router.route("/static/startAllAPI/:appName").handler(this::startAllAPI);
	router.route("/static/startAPI/:apiName").handler(this::startAPI);
	router.route("/static/stopAPI/:appName/:apiName").handler(this::stopAPI);

	router.route("/static/trackInfo/:appName/:apiName").handler(this::getTrackInfo);
	// 欢迎页
	router.route("/").handler(this::welcome);
	vertx.createHttpServer().requestHandler(router).listen(config().getInteger("clientPort", 5256), res -> {
		if (res.succeeded()) {
			LOG.info("start Clinet Verticle successful");
			fut.complete();
		} else {
			LOG.info("start Clinet Verticle unsuccessful");
			fut.fail(res.cause());
		}
	});
}