Search in sources :

Example 1 with ClientProperties

use of io.gravitee.am.model.safe.ClientProperties in project gravitee-access-management by gravitee-io.

the class ThymeleafDataHelper method generateData.

public static Map<String, Object> generateData(RoutingContext context, Domain domain, Client client) {
    final Map<String, Object> data = new HashMap<>(context.data());
    if (domain != null) {
        data.put(ConstantKeys.DOMAIN_CONTEXT_KEY, new DomainProperties(domain));
    }
    if (client != null) {
        data.put(ConstantKeys.CLIENT_CONTEXT_KEY, new ClientProperties(client));
    }
    // context may contain User or UserProperties according to the execution path
    Object user = context.get(ConstantKeys.USER_CONTEXT_KEY);
    if (user != null && user instanceof User) {
        data.put(ConstantKeys.USER_CONTEXT_KEY, new UserProperties((User) user));
    }
    return data;
}
Also used : DomainProperties(io.gravitee.am.model.safe.DomainProperties) ClientProperties(io.gravitee.am.model.safe.ClientProperties) User(io.gravitee.am.model.User) UserProperties(io.gravitee.am.model.safe.UserProperties) HashMap(java.util.HashMap)

Example 2 with ClientProperties

use of io.gravitee.am.model.safe.ClientProperties in project gravitee-access-management by gravitee-io.

the class IdentifierFirstLoginEndpoint method renderLoginPage.

private void renderLoginPage(RoutingContext routingContext) {
    final Client client = routingContext.get(CLIENT_CONTEXT_KEY);
    // remove sensible client data
    routingContext.put(CLIENT_CONTEXT_KEY, new ClientProperties(client));
    // put domain in context data
    routingContext.put(DOMAIN_CONTEXT_KEY, domain);
    // put request in context
    final HttpServerRequest request = routingContext.request();
    EvaluableRequest evaluableRequest = new EvaluableRequest(new VertxHttpServerRequest(request.getDelegate(), true));
    routingContext.put(REQUEST_CONTEXT_KEY, evaluableRequest);
    // put login settings in context
    LoginSettings loginSettings = LoginSettings.getInstance(domain, client);
    var optionalSettings = ofNullable(loginSettings).filter(Objects::nonNull);
    routingContext.put(ALLOW_REGISTER_CONTEXT_KEY, optionalSettings.map(LoginSettings::isRegisterEnabled).orElse(false));
    routingContext.put(ALLOW_PASSWORDLESS_CONTEXT_KEY, optionalSettings.map(LoginSettings::isPasswordlessEnabled).orElse(false));
    // put error in context
    final String error = request.getParam(ERROR_PARAM_KEY);
    final String errorDescription = request.getParam(ERROR_DESCRIPTION_PARAM_KEY);
    routingContext.put(ERROR_PARAM_KEY, error);
    routingContext.put(ERROR_DESCRIPTION_PARAM_KEY, errorDescription);
    // put parameters in context (backward compatibility)
    Map<String, String> params = new HashMap<>(evaluableRequest.getParams().toSingleValueMap());
    params.put(ERROR_PARAM_KEY, error);
    params.put(ERROR_DESCRIPTION_PARAM_KEY, errorDescription);
    routingContext.put(PARAM_CONTEXT_KEY, params);
    // put actions in context
    final MultiMap queryParams = RequestUtils.getCleanedQueryParams(request);
    routingContext.put(ACTION_KEY, resolveProxyRequest(request, routingContext.get(CONTEXT_PATH) + "/login/identifier", queryParams, true));
    routingContext.put(REGISTER_ACTION_KEY, UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/register", queryParams, true));
    routingContext.put(WEBAUTHN_ACTION_KEY, UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/webauthn/login", queryParams, true));
    final Map<String, Object> data = generateData(routingContext, domain, client);
    data.putAll(botDetectionManager.getTemplateVariables(domain, client));
    this.renderPage(routingContext, data, client, logger, "Unable to render Identifier-first login page");
}
Also used : ClientProperties(io.gravitee.am.model.safe.ClientProperties) HashMap(java.util.HashMap) HttpServerRequest(io.vertx.reactivex.core.http.HttpServerRequest) VertxHttpServerRequest(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest) EvaluableRequest(io.gravitee.am.gateway.handler.context.EvaluableRequest) VertxHttpServerRequest(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest) MultiMap(io.vertx.reactivex.core.MultiMap) LoginSettings(io.gravitee.am.model.login.LoginSettings) Objects(java.util.Objects) Client(io.gravitee.am.model.oidc.Client)

Example 3 with ClientProperties

use of io.gravitee.am.model.safe.ClientProperties in project gravitee-access-management by gravitee-io.

the class LoginEndpoint method prepareContext.

private void prepareContext(RoutingContext routingContext, Client client) {
    // remove sensible client data
    routingContext.put(ConstantKeys.CLIENT_CONTEXT_KEY, new ClientProperties(client));
    // put domain in context data
    routingContext.put(ConstantKeys.DOMAIN_CONTEXT_KEY, domain);
    // put login settings in context data
    LoginSettings loginSettings = LoginSettings.getInstance(domain, client);
    var optionalSettings = ofNullable(loginSettings).filter(Objects::nonNull);
    boolean isIdentifierFirstLoginEnabled = optionalSettings.map(LoginSettings::isIdentifierFirstEnabled).orElse(false);
    routingContext.put(ALLOW_FORGOT_PASSWORD_CONTEXT_KEY, optionalSettings.map(LoginSettings::isForgotPasswordEnabled).orElse(false));
    routingContext.put(ALLOW_REGISTER_CONTEXT_KEY, optionalSettings.map(LoginSettings::isRegisterEnabled).orElse(false));
    routingContext.put(ALLOW_PASSWORDLESS_CONTEXT_KEY, optionalSettings.map(LoginSettings::isPasswordlessEnabled).orElse(false));
    routingContext.put(HIDE_FORM_CONTEXT_KEY, optionalSettings.map(LoginSettings::isHideForm).orElse(false));
    routingContext.put(IDENTIFIER_FIRST_LOGIN_CONTEXT_KEY, isIdentifierFirstLoginEnabled);
    // put request in context
    EvaluableRequest evaluableRequest = new EvaluableRequest(new VertxHttpServerRequest(routingContext.request().getDelegate(), true));
    routingContext.put(REQUEST_CONTEXT_KEY, evaluableRequest);
    // put error in context
    final String error = routingContext.request().getParam(ConstantKeys.ERROR_PARAM_KEY);
    final String errorDescription = routingContext.request().getParam(ConstantKeys.ERROR_DESCRIPTION_PARAM_KEY);
    routingContext.put(ConstantKeys.ERROR_PARAM_KEY, error);
    routingContext.put(ConstantKeys.ERROR_DESCRIPTION_PARAM_KEY, errorDescription);
    // put parameters in context (backward compatibility)
    Map<String, String> params = new HashMap<>(evaluableRequest.getParams().toSingleValueMap());
    params.put(ConstantKeys.ERROR_PARAM_KEY, error);
    params.put(ConstantKeys.ERROR_DESCRIPTION_PARAM_KEY, errorDescription);
    final String loginHint = routingContext.request().getParam(Parameters.LOGIN_HINT);
    if (loginHint != null) {
        params.put(ConstantKeys.USERNAME_PARAM_KEY, loginHint);
    }
    routingContext.put(ConstantKeys.PARAM_CONTEXT_KEY, params);
    // put action urls in context
    final MultiMap queryParams = getCleanedQueryParams(routingContext.request());
    routingContext.put(ACTION_KEY, resolveProxyRequest(routingContext.request(), routingContext.request().path(), queryParams, true));
    routingContext.put(FORGOT_ACTION_KEY, resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/forgotPassword", queryParams, true));
    routingContext.put(REGISTER_ACTION_KEY, resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/register", queryParams, true));
    routingContext.put(WEBAUTHN_ACTION_KEY, resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/webauthn/login", queryParams, true));
    if (isIdentifierFirstLoginEnabled) {
        routingContext.put(LOGIN_IDENTIFIER_ACTION_KEY, resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/login/identifier", queryParams, true));
    }
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) ClientProperties(io.gravitee.am.model.safe.ClientProperties) HashMap(java.util.HashMap) LoginSettings(io.gravitee.am.model.login.LoginSettings) Objects(java.util.Objects) EvaluableRequest(io.gravitee.am.gateway.handler.context.EvaluableRequest) VertxHttpServerRequest(io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest)

Example 4 with ClientProperties

use of io.gravitee.am.model.safe.ClientProperties in project gravitee-access-management by gravitee-io.

the class TokenServiceImpl method createExecutionContext.

private ExecutionContext createExecutionContext(OAuth2Request request, Client client, User user) {
    ExecutionContext simpleExecutionContext = new SimpleExecutionContext(request, null);
    ExecutionContext executionContext = executionContextFactory.create(simpleExecutionContext);
    executionContext.setAttribute("client", new ClientProperties(client));
    if (user != null) {
        executionContext.setAttribute("user", new UserProperties(user));
    }
    // put authorization request in context
    if (request.getResponseType() != null && !request.getResponseType().isEmpty()) {
        executionContext.setAttribute("authorizationRequest", request);
    } else {
        executionContext.setAttribute("tokenRequest", request);
    }
    Object authFlowAttributes = request.getContext().get(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
    if (authFlowAttributes != null) {
        executionContext.setAttribute(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY, authFlowAttributes);
        request.getContext().remove(ConstantKeys.AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY);
    }
    return executionContext;
}
Also used : ClientProperties(io.gravitee.am.model.safe.ClientProperties) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext) UserProperties(io.gravitee.am.model.safe.UserProperties) SimpleExecutionContext(io.gravitee.gateway.api.context.SimpleExecutionContext)

Example 5 with ClientProperties

use of io.gravitee.am.model.safe.ClientProperties in project gravitee-access-management by gravitee-io.

the class EmailServiceImpl method prepareEmailParams.

private Map<String, Object> prepareEmailParams(Domain domain, Application client, User user, Integer expiresAfter, String redirectUri) {
    // generate a JWT to store user's information and for security purpose
    final Map<String, Object> claims = new HashMap<>();
    claims.put(Claims.iat, new Date().getTime() / 1000);
    claims.put(Claims.exp, new Date(System.currentTimeMillis() + (expiresAfter * 1000)).getTime() / 1000);
    claims.put(Claims.sub, user.getId());
    if (user.getClient() != null) {
        claims.put(Claims.aud, user.getClient());
    }
    String token = jwtBuilder.sign(new JWT(claims));
    String redirectUrl = domainService.buildUrl(domain, redirectUri + "?token=" + token);
    if (client != null) {
        redirectUrl += "&client_id=" + client.getSettings().getOauth().getClientId();
    }
    Map<String, Object> params = new HashMap<>();
    params.put("user", new UserProperties(user));
    params.put("url", redirectUrl);
    params.put("token", token);
    params.put("expireAfterSeconds", expiresAfter);
    params.put("domain", new DomainProperties(domain));
    if (client != null) {
        params.put("client", new ClientProperties(client));
    }
    return params;
}
Also used : DomainProperties(io.gravitee.am.model.safe.DomainProperties) ClientProperties(io.gravitee.am.model.safe.ClientProperties) UserProperties(io.gravitee.am.model.safe.UserProperties) HashMap(java.util.HashMap) JWT(io.gravitee.am.common.jwt.JWT) FreeMarkerTemplateUtils.processTemplateIntoString(org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString) Date(java.util.Date)

Aggregations

ClientProperties (io.gravitee.am.model.safe.ClientProperties)8 UserProperties (io.gravitee.am.model.safe.UserProperties)6 HashMap (java.util.HashMap)4 JWT (io.gravitee.am.common.jwt.JWT)3 DomainProperties (io.gravitee.am.model.safe.DomainProperties)3 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)3 SimpleExecutionContext (io.gravitee.gateway.api.context.SimpleExecutionContext)3 VertxHttpServerRequest (io.gravitee.am.gateway.handler.common.vertx.core.http.VertxHttpServerRequest)2 EvaluableRequest (io.gravitee.am.gateway.handler.context.EvaluableRequest)2 User (io.gravitee.am.model.User)2 LoginSettings (io.gravitee.am.model.login.LoginSettings)2 Client (io.gravitee.am.model.oidc.Client)2 MultiMap (io.vertx.reactivex.core.MultiMap)2 Objects (java.util.Objects)2 InvalidTokenException (io.gravitee.am.common.exception.oauth2.InvalidTokenException)1 RequiredClaims (io.gravitee.am.common.exception.uma.RequiredClaims)1 UmaException (io.gravitee.am.common.exception.uma.UmaException)1 GrantType (io.gravitee.am.common.oauth2.GrantType)1 Parameters (io.gravitee.am.common.oauth2.Parameters)1 TokenType (io.gravitee.am.common.oauth2.TokenType)1