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;
}
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");
}
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));
}
}
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;
}
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;
}
Aggregations