Backend Validation for custom attributes without declerative User Profile SPI

Hello guys, ive just recently updated keycloak from version 9 to version 14, previusly i had a provider that implemented UserProfileProvider in which i’ve done some logic for adding a BE validation,
like this:

public UserProfileValidationResult validate(UserProfileContext updateContext, UserProfile updatedProfile) {
        LOGGER.info("UserProfileValidationResult - " + updateContext.getUpdateEvent());
        RealmModel realm = this.session.getContext().getRealm();
        ValidationChainBuilder builder = ValidationChainBuilder.builder();
        switch (updateContext.getUpdateEvent()) {
            case UserResource:
                this.addReadOnlyAttributeValidators(builder, this.adminReadOnlyAttributes, updateContext, updatedProfile);
                break;
            case IdpReview:
                this.addBasicValidators(builder, !realm.isRegistrationEmailAsUsername());
                this.addReadOnlyAttributeValidators(builder, this.readOnlyAttributes, updateContext, updatedProfile);
                break;
            case Account:
            case RegistrationProfile:
            case UpdateProfile:
                this.addBasicValidators(builder, !realm.isRegistrationEmailAsUsername() && realm.isEditUsernameAllowed());
                this.addReadOnlyAttributeValidators(builder, this.readOnlyAttributes, updateContext, updatedProfile);
                this.addSessionValidators(builder);
                this.addCustomValidators(builder, updatedProfile); //funzione per validare gli attributi custom
                break;
            case RegistrationUserCreation:
                this.addUserCreationValidators(builder);
                this.addReadOnlyAttributeValidators(builder, this.readOnlyAttributes, updateContext, updatedProfile);
        }

        return new UserProfileValidationResult(builder.build().validate(updateContext, updatedProfile), updatedProfile);
    }

private void addCustomValidators(ValidationChainBuilder builder, UserProfile updatedProfile) {
        final int IS_ENDUSER = 1;
        final int IS_PROFESSIONAL = 2;
        int userType = IS_ENDUSER;
        try {
            userType = Integer.parseInt(updatedProfile.getAttributes().getFirstAttribute("user_type"));
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        }

        if (userType == IS_PROFESSIONAL) {
            builder.addAttributeValidator().forAttribute("company")
                    .addSingleAttributeValueValidationFunction("missingCompany", StaticValidators.isBlank())
                    .build()
                    .addAttributeValidator().forAttribute("job_title")
                    .addSingleAttributeValueValidationFunction("missingJobTitle", StaticValidators.isBlank())
                    .build();
        }

        builder.addAttributeValidator().forAttribute("country")
                .addSingleAttributeValueValidationFunction("missingCountry", StaticValidators.isBlank())
                .build();
    }

In the new 14.0 version the UserProfileProvider is completely different, is there any way to implement backend attributes validation without enabling the thecnical preview feature of User Profile SPI? (modificato)

Just a side note:
Version 14 is approx. 3 years old, so it’s in neither way “new”!!!
(it’s outdated, has several security vulnerabilities and receives no more updates, don’t use it in production, there’s not “but…” allowed)

Don’t know what all has been changed since 14, but in current versions, there is no (more) method public UserProfileValidationResult validate(...). Don’t know how to handle it today, as I didn’t implement anything to the user profile, yet.

The user profile thing has changed, as somewhen around 12-14, the declarative user profile was introduced. It was long time in an experimental state, it’s now still “preview” but there’s a lot of work around it, so I expect it to be fully supported soon (no, I don’t know more details).