router.route("/loginhandler").handler(FormLoginHandler.create(authProvider));
router.route("/loginhandler").handler(FormLoginHandler.create(authProvider));
@Test public void testLoginChangeFormLoginHandlerParams() throws Exception { formLoginHandler = FormLoginHandler.create(authProvider); usernameParam = "username2"; passwordParam ="password2"; formLoginHandler.setUsernameParam(usernameParam).setPasswordParam(passwordParam); testLogin(); }
/** * Create a handler * @param authProvider the auth service to use * @return the handler */ public static io.vertx.rxjava.ext.web.handler.FormLoginHandler create(io.vertx.rxjava.ext.auth.AuthProvider authProvider) { io.vertx.rxjava.ext.web.handler.FormLoginHandler ret = io.vertx.rxjava.ext.web.handler.FormLoginHandler.newInstance(io.vertx.ext.web.handler.FormLoginHandler.create(authProvider.getDelegate())); return ret; }
/** * Create a handler * @param authProvider the auth service to use * @return the handler */ public static io.vertx.rxjava.ext.web.handler.FormLoginHandler create(io.vertx.rxjava.ext.auth.AuthProvider authProvider) { io.vertx.rxjava.ext.web.handler.FormLoginHandler ret = io.vertx.rxjava.ext.web.handler.FormLoginHandler.newInstance(io.vertx.ext.web.handler.FormLoginHandler.create(authProvider.getDelegate())); return ret; }
/** * Create a handler * @param authProvider the auth service to use * @param usernameParam the value of the form attribute which will contain the username * @param passwordParam the value of the form attribute which will contain the password * @param returnURLParam the value of the session attribute which will contain the return url * @param directLoggedInOKURL a url to redirect to if the user logs in directly at the url of the form login handler without being redirected here first * @return the handler */ public static io.vertx.rxjava.ext.web.handler.FormLoginHandler create(io.vertx.rxjava.ext.auth.AuthProvider authProvider, String usernameParam, String passwordParam, String returnURLParam, String directLoggedInOKURL) { io.vertx.rxjava.ext.web.handler.FormLoginHandler ret = io.vertx.rxjava.ext.web.handler.FormLoginHandler.newInstance(io.vertx.ext.web.handler.FormLoginHandler.create(authProvider.getDelegate(), usernameParam, passwordParam, returnURLParam, directLoggedInOKURL)); return ret; }
@Test public void testFormLoginHandlerDirectDefaultResponse() throws Exception { formLoginHandler = FormLoginHandler.create(authProvider); usernameParam = "username2"; passwordParam ="password2"; formLoginHandler.setUsernameParam(usernameParam).setPasswordParam(passwordParam); router.route().handler(LoggerHandler.create()); router.route().handler(BodyHandler.create()); router.route().handler(CookieHandler.create()); router.route("/login").handler(formLoginHandler); testRequest(HttpMethod.POST, "/login", sendLoginRequestConsumer(), resp -> { }, 200, "OK", "<html><body><h1>Login successful</h1></body></html>"); }
/** * Create a handler * @param authProvider the auth service to use * @param usernameParam the value of the form attribute which will contain the username * @param passwordParam the value of the form attribute which will contain the password * @param returnURLParam the value of the session attribute which will contain the return url * @param directLoggedInOKURL a url to redirect to if the user logs in directly at the url of the form login handler without being redirected here first * @return the handler */ public static io.vertx.rxjava.ext.web.handler.FormLoginHandler create(io.vertx.rxjava.ext.auth.AuthProvider authProvider, String usernameParam, String passwordParam, String returnURLParam, String directLoggedInOKURL) { io.vertx.rxjava.ext.web.handler.FormLoginHandler ret = io.vertx.rxjava.ext.web.handler.FormLoginHandler.newInstance(io.vertx.ext.web.handler.FormLoginHandler.create(authProvider.getDelegate(), usernameParam, passwordParam, returnURLParam, directLoggedInOKURL)); return ret; }
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("/login").handler(FormLoginHandler.create(authProvider));
@Test public void testFormLoginHandlerDirectSpecifyLoggedInURL() throws Exception { formLoginHandler = FormLoginHandler.create(authProvider); usernameParam = "username2"; passwordParam ="password2"; String loggedInDirectOKPage = "/youloggedinokpage.html"; formLoginHandler.setUsernameParam(usernameParam).setPasswordParam(passwordParam).setDirectLoggedInOKURL(loggedInDirectOKPage); router.route().handler(LoggerHandler.create()); router.route().handler(BodyHandler.create()); router.route().handler(CookieHandler.create()); router.route("/login").handler(formLoginHandler); testRequest(HttpMethod.POST, "/login", sendLoginRequestConsumer(), resp -> { String location = resp.headers().get("location"); assertNotNull(location); assertEquals(loggedInDirectOKPage, location); }, 302, "Found", null); }
@Test public void testLoginChangeFormLoginHandlerParams() throws Exception { formLoginHandler = FormLoginHandler.create(authProvider); usernameParam = "username2"; passwordParam ="password2"; formLoginHandler.setUsernameParam(usernameParam).setPasswordParam(passwordParam); testLogin(); }
@Test public void testFormLoginHandlerDirectDefaultResponse() throws Exception { formLoginHandler = FormLoginHandler.create(authProvider); usernameParam = "username2"; passwordParam ="password2"; formLoginHandler.setUsernameParam(usernameParam).setPasswordParam(passwordParam); router.route().handler(LoggerHandler.create()); router.route().handler(BodyHandler.create()); router.route().handler(CookieHandler.create()); router.route("/login").handler(formLoginHandler); testRequest(HttpMethod.POST, "/login", sendLoginRequestConsumer(), resp -> { }, 200, "OK", "<html><body><h1>Login successful</h1></body></html>"); }
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("/login").handler(FormLoginHandler.create(authProvider));
@Test public void testFormLoginHandlerDirectSpecifyLoggedInURL() throws Exception { formLoginHandler = FormLoginHandler.create(authProvider); usernameParam = "username2"; passwordParam ="password2"; String loggedInDirectOKPage = "/youloggedinokpage.html"; formLoginHandler.setUsernameParam(usernameParam).setPasswordParam(passwordParam).setDirectLoggedInOKURL(loggedInDirectOKPage); router.route().handler(LoggerHandler.create()); router.route().handler(BodyHandler.create()); router.route().handler(CookieHandler.create()); router.route("/login").handler(formLoginHandler); testRequest(HttpMethod.POST, "/login", sendLoginRequestConsumer(), resp -> { String location = resp.headers().get("location"); assertNotNull(location); assertEquals(loggedInDirectOKPage, location); }, 302, "Found", null); }