@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); } }
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
protected SessionStore getSessionStore() { return LocalSessionStore.create(vertx); }
@Override public void setUp() throws Exception { super.setUp(); store = LocalSessionStore.create(vertx); }
@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"); }
@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()); }
protected SessionStore getSessionStore() { return LocalSessionStore.create(vertx); }
@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"); }
/** * Create a session store * @param vertx the Vert.x instance * @param sessionMapName name for map used to store sessions * @param reaperInterval how often, in ms, to check for expired sessions * @return the session store */ public static io.vertx.rxjava.ext.web.sstore.LocalSessionStore create(io.vertx.rxjava.core.Vertx vertx, String sessionMapName, long reaperInterval) { io.vertx.rxjava.ext.web.sstore.LocalSessionStore ret = io.vertx.rxjava.ext.web.sstore.LocalSessionStore.newInstance(io.vertx.ext.web.sstore.LocalSessionStore.create(vertx.getDelegate(), sessionMapName, reaperInterval)); return ret; }
/** * Create a session store * @param vertx the Vert.x instance * @param sessionMapName name for map used to store sessions * @param reaperInterval how often, in ms, to check for expired sessions * @return the session store */ public static io.vertx.rxjava.ext.web.sstore.LocalSessionStore create(io.vertx.rxjava.core.Vertx vertx, String sessionMapName, long reaperInterval) { io.vertx.rxjava.ext.web.sstore.LocalSessionStore ret = io.vertx.rxjava.ext.web.sstore.LocalSessionStore.newInstance(io.vertx.ext.web.sstore.LocalSessionStore.create(vertx.getDelegate(), sessionMapName, reaperInterval)); return ret; }
/** * Create a session store * @param vertx the Vert.x instance * @param sessionMapName name for map used to store sessions * @return the session store */ public static io.vertx.rxjava.ext.web.sstore.LocalSessionStore create(io.vertx.rxjava.core.Vertx vertx, String sessionMapName) { io.vertx.rxjava.ext.web.sstore.LocalSessionStore ret = io.vertx.rxjava.ext.web.sstore.LocalSessionStore.newInstance(io.vertx.ext.web.sstore.LocalSessionStore.create(vertx.getDelegate(), sessionMapName)); return ret; }
/** * Create a session store * @param vertx the Vert.x instance * @return the session store */ public static io.vertx.rxjava.ext.web.sstore.LocalSessionStore create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.web.sstore.LocalSessionStore ret = io.vertx.rxjava.ext.web.sstore.LocalSessionStore.newInstance(io.vertx.ext.web.sstore.LocalSessionStore.create(vertx.getDelegate())); return ret; }
/** * Create a session store * @param vertx the Vert.x instance * @param sessionMapName name for map used to store sessions * @return the session store */ public static io.vertx.rxjava.ext.web.sstore.LocalSessionStore create(io.vertx.rxjava.core.Vertx vertx, String sessionMapName) { io.vertx.rxjava.ext.web.sstore.LocalSessionStore ret = io.vertx.rxjava.ext.web.sstore.LocalSessionStore.newInstance(io.vertx.ext.web.sstore.LocalSessionStore.create(vertx.getDelegate(), sessionMapName)); return ret; }
/** * Create a session store * @param vertx the Vert.x instance * @return the session store */ public static io.vertx.rxjava.ext.web.sstore.LocalSessionStore create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.web.sstore.LocalSessionStore ret = io.vertx.rxjava.ext.web.sstore.LocalSessionStore.newInstance(io.vertx.ext.web.sstore.LocalSessionStore.create(vertx.getDelegate())); return ret; }
@Override public void setUp() throws Exception { super.setUp(); store = LocalSessionStore.create(vertx); }
private void doLoginCommon(Handler<RoutingContext> handler, Set<String> authorities) throws Exception { router.route().handler(BodyHandler.create()); router.route().handler(CookieHandler.create()); SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); router.route().handler(UserSessionHandler.create(authProvider)); AuthHandler authHandler = RedirectAuthHandler.create(authProvider); if (authorities != null) { authHandler.addAuthorities(authorities); } router.route("/protected/*").handler(authHandler); router.route("/protected/somepage").handler(handler); String loginHTML = createloginHTML(); router.route("/loginpage").handler(rc -> rc.response().putHeader("content-type", "text/html").end(loginHTML)); if (formLoginHandler == null) { formLoginHandler = FormLoginHandler.create(authProvider); } router.route("/login").handler(formLoginHandler); testRequest(HttpMethod.GET, "/protected/somepage", null, resp -> { String location = resp.headers().get("location"); assertNotNull(location); assertEquals("/loginpage", location); String setCookie = resp.headers().get("set-cookie"); assertNotNull(setCookie); sessionCookie.set(setCookie); }, 302, "Found", null); testRequest(HttpMethod.GET, "/loginpage", req -> req.putHeader("cookie", sessionCookie.get()), resp -> { }, 200, "OK", loginHTML); }
router.route().handler(BodyHandler.create()); router.route().handler(CookieHandler.create()); SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); router.route().handler(UserSessionHandler.create(authProvider));