Codota Logo
SessionHandler.create
Code IndexAdd Codota to your IDE (free)

How to use
create
method
in
io.vertx.ext.web.handler.SessionHandler

Best Java code snippets using io.vertx.ext.web.handler.SessionHandler.create (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: vert-x3/vertx-examples

 @Override
 public void start() throws Exception {

  Router router = Router.router(vertx);

  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));

  router.route().handler(routingContext -> {

   Session session = routingContext.session();

   Integer cnt = session.get("hitcount");
   cnt = (cnt == null ? 0 : cnt) + 1;

   session.put("hitcount", cnt);

   routingContext.response().putHeader("content-type", "text/html")
                .end("<html><body><h1>Hitcount: " + cnt + "</h1></body></html>");
  });

  vertx.createHttpServer().requestHandler(router).listen(8080);
 }
}
origin: vert-x3/vertx-examples

router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
origin: vert-x3/vertx-examples

router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
origin: vert-x3/vertx-examples

router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
origin: vert-x3/vertx-examples

router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
origin: vert-x3/vertx-web

@Test
public void testLastAccessed1() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store));
  AtomicReference<Session> rid = new AtomicReference<>();
  long start = System.currentTimeMillis();
  router.route().handler(rc -> {
    rid.set(rc.session());
    rc.response().end();
  });
  testRequest(HttpMethod.GET, "/", 200, "OK");
  assertTrue(rid.get().lastAccessed() - start < 500);
  start = System.currentTimeMillis();
  Thread.sleep(1000);
  testRequest(HttpMethod.GET, "/", 200, "OK");
  assertTrue(rid.get().lastAccessed() - start >= 1000);
}
origin: vert-x3/vertx-web

@Test
public void testLastAccessed2() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store));
  AtomicReference<Session> rid = new AtomicReference<>();
  router.route().handler(rc -> {
    rid.set(rc.session());
    rc.session().put("foo", "bar");
    vertx.setTimer(1000, tid -> rc.response().end());
  });
  testRequest(HttpMethod.GET, "/", 200, "OK");
  // accessed() is called after request too
  assertTrue(rid.get().lastAccessed() - System.currentTimeMillis() < 500);
}
origin: vert-x3/vertx-web

@Test
public void testIssue172_setnull() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store));
  AtomicReference<Session> rid = new AtomicReference<>();
  router.route().handler(rc -> {
    rid.set(rc.session());
    rc.session().put("foo", null);
    vertx.setTimer(1000, tid -> rc.response().end());
  });
  testRequest(HttpMethod.GET, "/", 200, "OK");
}
origin: vert-x3/vertx-web

@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, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig));
 addLoginHandler(router, authProvider);
 router.route("/eventbus/*").handler(sockJSHandler);
 testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foo"), "access_denied");
}
origin: vert-x3/vertx-web

@Test
public void testSessionCookieSecureFlagAndHttpOnlyFlags() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store).setCookieSecureFlag(true).setCookieHttpOnlyFlag(true));
  router.route().handler(rc -> rc.response().end());
  testRequest(HttpMethod.GET, "/", null, resp -> {
    String setCookie = resp.headers().get("set-cookie");
    assertTrue(setCookie.contains("; Secure"));
    assertTrue(setCookie.contains("; HTTPOnly"));
  }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testSessionCookieSecureFlag() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store).setCookieSecureFlag(true));
  router.route().handler(rc -> rc.response().end());
  testRequest(HttpMethod.GET, "/", null, resp -> {
    String setCookie = resp.headers().get("set-cookie");
    assertTrue(setCookie.contains("; Secure"));
  }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testSessionCookieHttpOnlyFlag() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store).setCookieHttpOnlyFlag(true));
  router.route().handler(rc -> rc.response().end());
  testRequest(HttpMethod.GET, "/", null, resp -> {
    String setCookie = resp.headers().get("set-cookie");
    assertTrue(setCookie.contains("; HTTPOnly"));
  }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testSessionCookiePath() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store).setSessionCookiePath("/path"));
  router.route().handler(rc -> rc.response().end());
  testRequest(HttpMethod.GET, "/", null, resp -> {
    String setCookie = resp.headers().get("set-cookie");
    assertTrue(setCookie.contains("Path=/path"));
  }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testSessionCookieName() throws Exception {
  router.route().handler(CookieHandler.create());
  String sessionCookieName = "acme.sillycookie";
  router.route().handler(SessionHandler.create(store).setSessionCookieName(sessionCookieName));
  router.route().handler(rc -> rc.response().end());
  testRequest(HttpMethod.GET, "/", null, resp -> {
    String setCookie = resp.headers().get("set-cookie");
    assertTrue(setCookie.startsWith(sessionCookieName + "="));
  }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Test
public void testSessionFields() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store));
  AtomicReference<String> rid = new AtomicReference<>();
  router.route().handler(rc -> {
    Session sess = rc.session();
    assertNotNull(sess);
    assertTrue(System.currentTimeMillis() - sess.lastAccessed() < 500);
    assertNotNull(sess.id());
    rid.set(sess.value());
    assertFalse(sess.isDestroyed());
    assertEquals(SessionHandler.DEFAULT_SESSION_TIMEOUT, sess.timeout());
    rc.response().end();
  });
  testRequest(HttpMethod.GET, "/", null, resp -> {
    String setCookie = resp.headers().get("set-cookie");
    assertTrue(setCookie.startsWith(SessionHandler.DEFAULT_SESSION_COOKIE_NAME + "="));
    int pos = setCookie.indexOf("; Path=" + SessionHandler.DEFAULT_SESSION_COOKIE_PATH);
    String sessID = setCookie.substring(18, pos);
    assertEquals(rid.get(), sessID);
  }, 200, "OK", null);
}
origin: vert-x3/vertx-web

router.route().handler(CookieHandler.create());
SessionStore store = getSessionStore();
router.route().handler(SessionHandler.create(store));
origin: vert-x3/vertx-web

@Test
public void testSessionIdLength() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store));
  router.route("/1").handler(rc -> {
    // previous id must match
    assertFalse("abc".equals(rc.session().id()));
    rc.response().end();
  });
  testRequest(HttpMethod.GET, "/1", req -> req.putHeader("cookie", "vertx-web.session=abc; Path=/"), resp -> {
    String setCookie = resp.headers().get("set-cookie");
    assertNotNull(setCookie);
  }, 200, "OK", null);
}
origin: vert-x3/vertx-web

@Override
public void setUp() throws Exception {
 super.setUp();
 JsonObject authConfig = new JsonObject().put("properties_path", "classpath:login/loginusers.properties");
 AuthProvider authProvider = ShiroAuth.create(vertx, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig));
 // create a chain
 chain = ChainAuthHandler.create();
 chain
  .append(JWTAuthHandler.create(null))
  .append(BasicAuthHandler.create(authProvider))
  .append(RedirectAuthHandler.create(authProvider));
 router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
 router.route().handler(chain);
 router.route().handler(ctx -> ctx.response().end());
}
origin: vert-x3/vertx-web

@Test
public void testSendRequiresAuthorityHasAuthority() throws Exception {
 sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks")));
 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, new ShiroAuthOptions().setType(ShiroAuthRealmType.PROPERTIES).setConfig(authConfig));
 addLoginHandler(router, authProvider);
 router.route("/eventbus/*").handler(sockJSHandler);
 testSend("foo");
}
origin: vert-x3/vertx-web

@Test
public void testSessionCookieAttack() throws Exception {
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(store));
  // faking that there was some auth error
  router.route().handler(rc -> rc.fail(401));
  testRequest(HttpMethod.GET, "/", null, resp -> assertNull(resp.headers().get("set-cookie")), 401,
      "Unauthorized", null);
}
io.vertx.ext.web.handlerSessionHandlercreate

Javadoc

Create a session handler

Popular methods of SessionHandler

  • setCookieHttpOnlyFlag
    Sets whether the 'HttpOnly' flag should be set for the session cookie. When set this flag instructs
  • setCookieSecureFlag
    Sets whether the 'secure' flag should be set for the session cookie. When set this flag instructs br
  • setSessionCookieName
    Set the session cookie name
  • setSessionCookiePath
    Set the session cookie path
  • setSessionTimeout
    Set the session timeout
  • handle
  • setMinLength
    Set expected session id minimum length.
  • setNagHttps
    Set whether a nagging log warning should be written if the session handler is accessed over HTTP, no

Popular in Java

  • Creating JSON documents from java classes using gson
  • addToBackStack (FragmentTransaction)
  • getExternalFilesDir (Context)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • Permission (java.security)
    Abstract class for representing access to a system resource. All permissions have a name (whose inte
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Dictionary (java.util)
    The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to valu
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now