@Override
    public void set(final WebContext context, final String key, final Object value) {
        LOGGER.trace("Setting key: [{}]", key);
        val sessionId = getSessionId(context, true).orElseGet(() -> {
            val newSessionId = UUID.randomUUID().toString();
            LOGGER.trace("Generated session id: [{}]", newSessionId);
            return newSessionId;
        });

        val properties = new HashMap<String, Serializable>();
        if (value instanceof final Serializable serializable) {
            properties.put(key, serializable);
        } else if (value != null) {
            LOGGER.warn("Object value [{}] assigned to [{}] is not serializable and may not be part of the ticket [{}]", value, key, sessionId);
        }
        
        val ticket = getTransientSessionTicketForSession(context);

        if (value == null && ticket != null) {
            ticket.getProperties().remove(key);
            updateTicket(context, ticket);
        } else if (ticket == null) {
            FunctionUtils.doAndHandle(__ -> {
                val transientFactory = (TransientSessionTicketFactory) ticketFactory.get(TransientSessionTicket.class);
                val transientSessionTicket = transientFactory.create(sessionId, properties);
                val addedTicket = ticketRegistry.addTicket(transientSessionTicket);
                
                val webContext = (JEEContext) context;
                cookieGenerator.addCookie(webContext.getNativeRequest(), webContext.getNativeResponse(), addedTicket.getId());

                context.setRequestAttribute(SESSION_ID_IN_REQUEST_ATTRIBUTE, addedTicket.getId());
            });
        } else {
            ticket.getProperties().putAll(properties);
            updateTicket(context, ticket);
        }
    }
This is {@link TicketRegistrySessionStore}.

@author Misagh Moayyed
@author Jerome LELEU
@since 6.1.0
support/cas-server-support-pac4j-api/src/main/java/org/apereo/cas/pac4j/TicketRegistrySessionStore.java