List of usage examples for io.vertx.core.http HttpServerRequest isExpectMultipart
boolean isExpectMultipart();
From source file:de.braintags.netrelay.controller.authentication.FormLoginHandlerBt.java
License:Open Source License
@Override public void handle(RoutingContext context) { HttpServerRequest req = context.request(); if (req.method() != HttpMethod.POST) { context.fail(405); // Must be a POST } else {/*from ww w.ja v a 2s .c om*/ if (!req.isExpectMultipart()) { throw new IllegalStateException("Form body not parsed - did you forget to include a BodyHandler?"); } MultiMap params = req.formAttributes(); String username = params.get(usernameParam); String password = params.get(passwordParam); if (username == null || password == null) { LOGGER.warn("No username or password provided in form - did you forget to include a BodyHandler?"); context.fail(400); } else { JsonObject authInfo = new JsonObject().put("username", username).put("password", password); authProvider.authenticate(authInfo, res -> { if (res.succeeded()) { User user = res.result(); LOGGER.info("Login success, found user " + user); MemberUtil.setContextUser(context, user); if (redirectBySession(context)) { return; } // Either no session or no return url if (!redirectByDirectLoginUrl(context)) { // Just show a basic page req.response().end(DEFAULT_DIRECT_LOGGED_IN_OK_PAGE); } } else { LOGGER.info("authentication failed: " + res.cause()); handleAuthenticationError(context, res.cause()); } }); } } }
From source file:io.gravitee.am.gateway.handler.vertx.auth.handler.impl.FormLoginHandlerImpl.java
License:Apache License
@Override public void handle(RoutingContext context) { HttpServerRequest req = context.request(); if (req.method() != HttpMethod.POST) { context.fail(405); // Must be a POST } else {//from ww w.j a v a 2s. c o m if (!req.isExpectMultipart()) { throw new IllegalStateException("Form body not parsed - do you forget to include a BodyHandler?"); } MultiMap params = req.formAttributes(); String username = params.get(usernameParam); String password = params.get(passwordParam); String clientId = params.get(OAuth2Constants.CLIENT_ID); if (username == null || password == null) { log.warn("No username or password provided in form - did you forget to include a BodyHandler?"); context.fail(400); } else if (clientId == null) { log.warn("No client id in form - did you forget to include client_id query parameter ?"); context.fail(400); } else { Session session = context.session(); JsonObject authInfo = new JsonObject().put("username", username).put("password", password) .put(OAuth2Constants.CLIENT_ID, clientId); authProvider.authenticate(authInfo, res -> { if (res.succeeded()) { User user = res.result(); context.setUser(user); if (session != null) { // the user has upgraded from unauthenticated to authenticated // session should be upgraded as recommended by owasp session.regenerateId(); // Note : keep returnURLParam in session in case the user go to previous page // String returnURL = session.remove(returnURLParam); String returnURL = session.get(returnURLParam); if (returnURL != null) { // Now redirect back to the original url doRedirect(req.response(), returnURL); return; } } // Either no session or no return url if (directLoggedInOKURL != null) { // Redirect to the default logged in OK page - this would occur // if the user logged in directly at this URL without being redirected here first from another // url doRedirect(req.response(), directLoggedInOKURL); } else { // Just show a basic page req.response().end(DEFAULT_DIRECT_LOGGED_IN_OK_PAGE); } } else { try { Map<String, String> parameters = new HashMap<>(); parameters.put(OAuth2Constants.CLIENT_ID, clientId); parameters.put("error", "login_failed"); String uri = UriBuilderRequest.resolveProxyRequest( new io.vertx.reactivex.core.http.HttpServerRequest(req), req.uri(), parameters, false, false); doRedirect(context.response(), uri); } catch (URISyntaxException e) { context.fail(503); } } }); } } }
From source file:io.servicecomb.transport.rest.vertx.RestBodyHandler.java
License:Apache License
@Override public void handle(RoutingContext context) { HttpServerRequest request = context.request(); // we need to keep state since we can be called again on reroute Boolean handled = context.get(BODY_HANDLED); if (handled == null || !handled) { BHandler handler = new BHandler(context); request.handler(handler);//from w w w .ja va 2 s . c o m request.endHandler(v -> handler.end()); context.put(BODY_HANDLED, true); } else { // on reroute we need to re-merge the form params if that was desired if (mergeFormAttributes && request.isExpectMultipart()) { request.params().addAll(request.formAttributes()); } context.next(); } }