UserRegistrationProvider addUser get firsname, lastname and email

In SPI UserStorageProvider the addUser function only has the username parameter, how do I get the first name, last name and email?

Can you share your code, and what you’re trying to accomplish? There is no addUser method in UserStorageProvider. Do you mean the one in UserProvider/UserRegistrationProvider?

If you are trying to create a new user, you can call the addUser(RealmModel realm, String username) method, and that will return an UserModel. Then you can call the setXxx() methods on that, and those values will be automatically persisted.

@Override
    public UserModel addUser(RealmModel rm, String username) {
        
        Logger.getLogger(CustomUserStorageProvider.class).info("addUser: realm={" + rm.getName() + "} username={" + username + "}");

        var tenant = this.db.session().createNamedQuery("Tenant.findByAliveName", Tenant.class).setParameter(1, rm.getName()).uniqueResult();
        if (tenant == null) {
            return null;
        }

        var account = new Account();

        account.setAlive(Boolean.TRUE);
        account.setStatId(Status.ENABLED);
        account.setCreationTime(Calendar.getInstance());
        account.setUsername(username);
        account.setTenaId(tenant.getTenaId());

        this.db.begin();

        var id = this.db.save(account);

        this.db.commit();

        return this.getUserById(StorageId.keycloakId(this.model, id.toString()), rm);
    }

This returns the UserModel. You can get the first name, last name and email from there.

This method is also overwritten and query on the record entered previously

@Override
public UserModel getUserById(String id, RealmModel rm) {

        Logger.getLogger(CustomUserStorageProvider.class).info("getUserById: realm={" + rm.getName() + "} id={" + id + "}");

        var account = this.db.session().byId(Account.class).load(Integer.parseInt(externalId(id)));
        if (account == null) {
            return null;
        }

        return new UsuarioAdapter(account, this.db.session().createNamedQuery("Allow.findByAccoId", Allow.class).setParameter(1, account.getAccoId()).list(), this.session, rm, this.model);
    }