use of io.gravitee.am.model.safe.UserProperties 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.UserProperties in project gravitee-access-management by gravitee-io.
the class WebAuthnRegisterEndpoint method renderPage.
private void renderPage(RoutingContext routingContext) {
try {
// session validation
if (routingContext.session() == null) {
logger.warn("No session or session handler is missing.");
routingContext.fail(500);
return;
}
if (routingContext.user() == null) {
logger.warn("User must be authenticated to register WebAuthn credentials.");
routingContext.fail(401);
return;
}
final MultiMap queryParams = RequestUtils.getCleanedQueryParams(routingContext.request());
// check if user has skipped this step
final HttpServerRequest request = routingContext.request();
if (Boolean.parseBoolean(request.getParam(SKIP_WEBAUTHN_PARAM_KEY))) {
queryParams.remove(SKIP_WEBAUTHN_PARAM_KEY);
String returnURL = UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.get(CONTEXT_PATH) + "/oauth/authorize", queryParams, true);
routingContext.session().put(ConstantKeys.WEBAUTHN_SKIPPED_KEY, true);
// Now redirect back to the original url
doRedirect(routingContext.response(), returnURL);
return;
}
// prepare the context
final Client client = routingContext.get(ConstantKeys.CLIENT_CONTEXT_KEY);
final User user = ((io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User) routingContext.user().getDelegate()).getUser();
final UserProperties userProperties = new UserProperties(user);
final String action = UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.request().path(), queryParams, true);
final String skipAction = UriBuilderRequest.resolveProxyRequest(routingContext.request(), routingContext.request().path(), queryParams.set("skipWebAuthN", "true"), true);
routingContext.put(ConstantKeys.ACTION_KEY, action);
routingContext.put(ConstantKeys.SKIP_ACTION_KEY, skipAction);
routingContext.put(ConstantKeys.USER_CONTEXT_KEY, userProperties);
routingContext.put(ConstantKeys.PARAM_CONTEXT_KEY, Collections.singletonMap(Parameters.CLIENT_ID, client.getClientId()));
if (domain.getWebAuthnSettings() != null && domain.getWebAuthnSettings().getAuthenticatorAttachment() != null) {
routingContext.put(ConstantKeys.PARAM_AUTHENTICATOR_ATTACHMENT_KEY, domain.getWebAuthnSettings().getAuthenticatorAttachment().getValue());
}
// render the webauthn register page
this.renderPage(routingContext, generateData(routingContext, domain, client), client, logger, "Unable to render WebAuthn register page");
} catch (Exception ex) {
logger.error("An error has occurred while rendering WebAuthn register page", ex);
routingContext.fail(503);
}
}
use of io.gravitee.am.model.safe.UserProperties 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.UserProperties 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;
}
use of io.gravitee.am.model.safe.UserProperties in project gravitee-access-management by gravitee-io.
the class UserNotificationServiceImpl method send.
@Override
public CompletableFuture<Void> send(Notification notification, Map<String, Object> param) {
var future = new CompletableFuture<Void>();
final UserProperties audience = (UserProperties) param.get(NotificationDefinitionUtils.NOTIFIER_DATA_USER);
final DomainProperties domain = (DomainProperties) param.get(NotificationDefinitionUtils.NOTIFIER_DATA_DOMAIN);
if (audience == null || domain == null) {
logger.warn("Receive notification to store in database without user or domain, ignore it.");
future.complete(null);
} else {
try {
ManagementUINotifierConfiguration notifierConfiguration = mapper.readValue(notification.getConfiguration(), ManagementUINotifierConfiguration.class);
String content = uiTemplateProvider.getNotificationContent(notifierConfiguration.getTemplate(), param);
final Date now = new Date();
final UserNotification userNotif = new UserNotification();
userNotif.setMessage(content);
userNotif.setCreatedAt(now);
userNotif.setUpdatedAt(now);
userNotif.setStatus(UserNotificationStatus.UNREAD);
userNotif.setReferenceId(domain.getId());
userNotif.setReferenceType(ReferenceType.DOMAIN);
userNotif.setAudienceId(audience.getId());
logger.debug("Receive notification to store in database for user '{}'", audience.getId());
notificationRepository.create(userNotif).observeOn(Schedulers.io()).subscribe(createdNotif -> {
logger.debug("Notification stored: {}", createdNotif);
// CompletableStage use the Void type. So it requires null to be mapped properly in the NotificationTrigger
future.complete(null);
}, future::completeExceptionally);
} catch (Exception e) {
logger.warn("Unable to deserialize ManagementUI Notifier configuration : {}", e.getMessage());
future.completeExceptionally(e);
}
}
return future;
}
Aggregations