Java Code Examples for io.vertx.reactivex.ext.web.RoutingContext#put()

The following examples show how to use io.vertx.reactivex.ext.web.RoutingContext#put() . 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: LoginErrorHandler.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext context) {
    final HttpServerRequest request = context.request();
    final String error = request.getParam(ERROR_PARAM);
    final String errorCode = request.getParam(ERROR_CODE_PARAM);
    final String errorDescription = request.getParam(ERROR_DESCRIPTION_PARAM);

    // no error to handle, continue
    if (error == null) {
        context.next();
        return;
    }

    // put error data in context
    Map<String, Object> errorContext = new HashMap<>();
    errorContext.put(ERROR_CODE_CONTEXT_KEY, errorCode);
    errorContext.put(ERROR_DESCRIPTION_CONTEXT_KEY, errorDescription);
    context.put(ERROR_CONTEXT_KEY, errorContext);
    context.next();
}
 
Example 2
Source File: MFAChallengeEndpoint.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
private void renderMFAPage(RoutingContext routingContext) {
    try {
        final Client client = routingContext.get(CLIENT_CONTEXT_KEY);
        final io.gravitee.am.model.User endUser = ((io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User) routingContext.user().getDelegate()).getUser();
        final Factor factor = getFactor(routingContext, client, endUser);
        final String error = routingContext.request().getParam(ERROR_PARAM);
        final String action = UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.request().uri(), null);
        routingContext.put("factor", factor);
        routingContext.put("action", action);
        routingContext.put(ERROR_PARAM, error);

        // render the mfa challenge page
        engine.render(routingContext.data(), getTemplateFileName(client), res -> {
            if (res.succeeded()) {
                routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
                routingContext.response().end(res.result());
            } else {
                logger.error("Unable to render MFA challenge page", res.cause());
                routingContext.fail(res.cause());
            }
        });
    } catch (Exception ex) {
        logger.error("An error occurs while rendering MFA challenge page", ex);
        routingContext.fail(503);
    }
}
 
Example 3
Source File: LoginEndpoint.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
private void prepareContext(RoutingContext routingContext, Client client) {
    // remove sensible client data
    routingContext.put(CLIENT_CONTEXT_KEY, new ClientProperties(client));
    // put domain in context data
    routingContext.put(DOMAIN_CONTEXT_KEY, domain);
    // put domain login settings in context data
    routingContext.put(ALLOW_FORGOT_PASSWORD_CONTEXT_KEY, domain.getLoginSettings() == null ? false : domain.getLoginSettings().isForgotPasswordEnabled());
    routingContext.put(ALLOW_REGISTER_CONTEXT_KEY, domain.getLoginSettings() == null ? false : domain.getLoginSettings().isRegisterEnabled());

    // put request in context
    EvaluableRequest evaluableRequest = new EvaluableRequest(new VertxHttpServerRequest(routingContext.request().getDelegate(), true));
    routingContext.put(REQUEST_CONTEXT_KEY, evaluableRequest);

    // put request parameters (backward compatibility)
    final String error = routingContext.request().getParam(ERROR_PARAM_KEY);
    Map<String, String> params = new HashMap<>();
    params.computeIfAbsent(ERROR_PARAM_KEY, val -> error);
    params.putAll(evaluableRequest.getParams().toSingleValueMap());
    routingContext.put(PARAM_CONTEXT_KEY, params);
}
 
Example 4
Source File: ForgotPasswordEndpoint.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    final HttpServerRequest request = routingContext.request();
    final String error = request.getParam(ERROR_PARAM);
    final String success = request.getParam(SUCCESS_PARAM);
    final String warning = request.getParam(WARNING_PARAM);
    final Client client = routingContext.get("client");
    // add query params to context
    routingContext.put(ERROR_PARAM, error);
    routingContext.put(SUCCESS_PARAM, success);
    routingContext.put(WARNING_PARAM, warning);
    routingContext.put(PARAM_CONTEXT_KEY, Collections.singletonMap(Parameters.CLIENT_ID, request.getParam(Parameters.CLIENT_ID)));

    // render the forgot password page
    engine.render(routingContext.data(), getTemplateFileName(client), res -> {
        if (res.succeeded()) {
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
            routingContext.response().end(res.result());
        } else {
            logger.error("Unable to render forgot password page", res.cause());
            routingContext.fail(res.cause());
        }
    });
}
 
Example 5
Source File: ErrorEndpoint.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
private void renderErrorPage(RoutingContext routingContext, Client client) {
    final HttpServerRequest request = routingContext.request();
    final String error = request.getParam(ERROR_PARAM);
    String errorDescription = request.getParam(ERROR_DESCRIPTION_PARAM);
    if (errorDescription != null) {
        try {
            errorDescription = java.net.URLDecoder.decode(request.getParam(ERROR_DESCRIPTION_PARAM), StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException e) {
            // unable to decode UTF-8 encoded query parameter
        }
    }
    routingContext.put(ERROR_PARAM, error);
    routingContext.put(ERROR_DESCRIPTION_PARAM, errorDescription);
    engine.render(routingContext.data(), getTemplateFileName(client), res -> {
        if (res.succeeded()) {
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
            routingContext.response().end(res.result());
        } else {
            routingContext.fail(res.cause());
        }
    });
}
 
Example 6
Source File: FreeMarkerTemplateRenderer.java    From redpipe with Apache License 2.0 5 votes vote down vote up
@Override
public Single<Response> render(String name, Map<String, Object> variables) {
	RoutingContext context = ResteasyProviderFactory.getContextData(RoutingContext.class);
	for (Entry<String, Object> entry : variables.entrySet()) {
		context.put(entry.getKey(), entry.getValue());
	}
	context.put("route", new RouterFunction());
	return templateEngine.rxRender(context, name)
			.map(buffer -> Response.ok(buffer, Template.parseMediaType(name, ".ftl")).build());
}
 
Example 7
Source File: ResetPasswordEndpoint.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    final HttpServerRequest request = routingContext.request();
    final String error = request.getParam(ERROR_PARAM);
    final String success = request.getParam(SUCCESS_PARAM);
    final String warning = request.getParam(WARNING_PARAM);
    final String token = request.getParam(TOKEN_PARAM);
    // add query params to context
    routingContext.put(ERROR_PARAM, error);
    routingContext.put(SUCCESS_PARAM, success);
    routingContext.put(WARNING_PARAM, warning);
    routingContext.put(TOKEN_PARAM, token);

    // retrieve user who want to reset password
    User user = routingContext.get("user");
    routingContext.put("user", user);

    // retrieve client (if exists)
    Client client = routingContext.get("client");

    // render the reset password page
    engine.render(routingContext.data(), getTemplateFileName(client), res -> {
        if (res.succeeded()) {
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
            routingContext.response().end(res.result());
        } else {
            logger.error("Unable to render reset password page", res.cause());
            routingContext.fail(res.cause());
        }
    });
}
 
Example 8
Source File: RegisterEndpoint.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    final HttpServerRequest request = routingContext.request();
    final String error = request.getParam(ERROR_PARAM);
    final String success = request.getParam(SUCCESS_PARAM);
    final String warning = request.getParam(WARNING_PARAM);
    final String token = request.getParam(TOKEN_PARAM);
    final Client client = routingContext.get("client");
    // add query params to context
    routingContext.put(ERROR_PARAM, error);
    routingContext.put(SUCCESS_PARAM, success);
    routingContext.put(WARNING_PARAM, warning);
    routingContext.put(TOKEN_PARAM, token);

    // set client_id
    Map<String, String> params = new HashMap<>();
    params.put(Parameters.CLIENT_ID, request.getParam(Parameters.CLIENT_ID));
    routingContext.put(PARAM_CONTEXT_KEY, params);

    // render the registration confirmation page
    engine.render(routingContext.data(), getTemplateFileName(client), res -> {
        if (res.succeeded()) {
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
            routingContext.response().end(res.result());
        } else {
            logger.error("Unable to render registration page", res.cause());
            routingContext.fail(res.cause());
        }
    });
}
 
Example 9
Source File: RegisterConfirmationEndpoint.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext routingContext) {
    final HttpServerRequest request = routingContext.request();
    final String error = request.getParam(ERROR_PARAM);
    final String success = request.getParam(SUCCESS_PARAM);
    final String warning = request.getParam(WARNING_PARAM);
    final String token = request.getParam(TOKEN_PARAM);
    // add query params to context
    routingContext.put(ERROR_PARAM, error);
    routingContext.put(SUCCESS_PARAM, success);
    routingContext.put(WARNING_PARAM, warning);
    routingContext.put(TOKEN_PARAM, token);

    // retrieve user who want to register
    User user = routingContext.get("user");
    routingContext.put("user", user);

    // retrieve client (if exists)
    Client client = routingContext.get("client");

    // check if user has already completed its registration
    if (user != null && user.isPreRegistration() && user.isRegistrationCompleted()) {
        Map<String, String> parameters = new LinkedHashMap<>();
        parameters.put(Parameters.CLIENT_ID, client.getClientId());
        parameters.put(ERROR_PARAM, "invalid_registration_context");
        redirectToPage(routingContext, parameters);
        return;
    }

    // render the registration confirmation page
    engine.render(routingContext.data(), getTemplateFileName(client), res -> {
        if (res.succeeded()) {
            routingContext.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML);
            routingContext.response().end(res.result());
        } else {
            logger.error("Unable to render registration confirmation page", res.cause());
            routingContext.fail(res.cause());
        }
    });
}
 
Example 10
Source File: UserConsentPrepareContextHandler.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private void prepareContext(RoutingContext context, Client client, io.gravitee.am.model.User user, AuthorizationRequest authorizationRequest) {
    context.put(CLIENT_CONTEXT_KEY, client);
    context.put(USER_CONTEXT_KEY, user);
    context.put(AUTHORIZATION_REQUEST_CONTEXT_KEY, authorizationRequest);

    // add id_token if exists
    String idToken = context.session().get(ID_TOKEN_SESSION_CONTEXT_KEY);
    if (idToken != null) {
        context.put(ID_TOKEN_CONTEXT_KEY, idToken);
    }
}