Search in sources :

Example 1 with UserProperties

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;
}
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 UserProperties

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);
    }
}
Also used : MultiMap(io.vertx.reactivex.core.MultiMap) User(io.gravitee.am.model.User) UserProperties(io.gravitee.am.model.safe.UserProperties) HttpServerRequest(io.vertx.reactivex.core.http.HttpServerRequest) Client(io.gravitee.am.model.oidc.Client)

Example 3 with UserProperties

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;
}
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 4 with UserProperties

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

Example 5 with UserProperties

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;
}
Also used : DomainProperties(io.gravitee.am.model.safe.DomainProperties) ManagementUINotifierConfiguration(io.gravitee.am.management.service.impl.notifications.ManagementUINotifierConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) UserProperties(io.gravitee.am.model.safe.UserProperties) UserNotification(io.gravitee.am.model.notification.UserNotification) Date(java.util.Date)

Aggregations

UserProperties (io.gravitee.am.model.safe.UserProperties)8 ClientProperties (io.gravitee.am.model.safe.ClientProperties)6 DomainProperties (io.gravitee.am.model.safe.DomainProperties)4 JWT (io.gravitee.am.common.jwt.JWT)3 User (io.gravitee.am.model.User)3 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)3 SimpleExecutionContext (io.gravitee.gateway.api.context.SimpleExecutionContext)3 Client (io.gravitee.am.model.oidc.Client)2 Date (java.util.Date)2 HashMap (java.util.HashMap)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 UserAuthenticationManager (io.gravitee.am.gateway.handler.common.auth.user.UserAuthenticationManager)1 JWTService (io.gravitee.am.gateway.handler.common.jwt.JWTService)1 ExecutionContextFactory (io.gravitee.am.gateway.handler.context.ExecutionContextFactory)1 InvalidGrantException (io.gravitee.am.gateway.handler.oauth2.exception.InvalidGrantException)1