[keycloak-user] attributes are not persisted

Max Bruchmann max.bruchmann at hotmail.com
Wed Aug 22 18:54:41 EDT 2018


So I tried the "do everything on login" approach which works.

But still I think it would be way cleaner to have a synchronous callback 
for processing/onboarding new users (including their name). No matter if 
they registred via form or an identity provider.


Kind Regards,

Max


Am 22.08.18 um 10:35 schrieb Max Bruchmann:
> Ok, do you think the "extending registration form" will work if users register via google, facebook etc...?
>
> With the LOGIN directly after REGISTER
>
> you mean I could try something like this:
>
> onLogin:
>
> String externalID = userModel.getFirstAttribute("foo");
>
>   if(externalID == null){
>
>   String externalID  = createSomethingWithUserEmail(userModel.getEmail())
>
>   userModel.setSingleAttribute("foo", externalID)
>
> }
>
> You think the transaction state is a different which then really perists the data or is the runJobInTransaction better working and will find the user?
>
> Max
>
> Am 20.08.18 um 19:08 schrieb Marek Posolda:
> Maybe it's better to rather extend registration form as described here: https://www.keycloak.org/docs/latest/server_development/index.html#modifying-extending-the-registration-form
>
> Alternative is, to update user directly in the LOGIN event after REGISTER event, but not 100% sure this one will work. Also even if it works, it's more a workaround.
>
> Marek
>
> On 10/08/18 19:32, Max Bruchmann wrote:
>
> Hmm unfortunatelly if I use
>
> KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (session) -> {
>        UserModel user = getUserModel(session, userId, realmId);
>
> ...
>
> The user is null :/
>
>
> Max
>
> Am 10.08.18 um 09:03 schrieb Marek Posolda:
> I am not 100% sure, but it's possible that updating users in the events don't currently work. Reason is, that transaction might be already commited. The possible solution long term is to use pre/post events for this (which we don't yet support).
>
> For the short term, it may be possible to manually trigger your own temporarily transaction (You can take a look at KeycloakModelUtils.runJobInTransaction method). Note that in the new transaction, you need to ensure to not use Hibernate entities from the "outer" transaction (EG. all the things like RealmModel, UserModel need to be look-up again through the Model API in the new transaction).
>
>
> Marek
>
>
>
> On 09/08/18 21:39, Max Bruchmann wrote:
> Hi,
>
> I have a custom EventListenerProvider that consumes Register and Login events.
>
> On register it creates some external resource
>
> ...//on register
>
> String externalID  = createSomethingWithUserEmail(userModel.getEmail())
>
> userModel.setSingleAttribute("foo", externalID)
>
> ...
>
> On login I need to todo some additional calls with the already created id.
>
> ...// on login
>
> String externalID = userModel.getFirstAttribute("foo");
>
> doSomeUpdate(externalID, userModel.getFirstName(), userModel.getLastName())
>
> ...
>
>
> Unfortunatelly the retrieved id via getFirstAttribute seems to be null.
>
> Is there anything I need todo when modifying attributes so they are persisted?
>
>
> Kind Regards,
>
> Max
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org<mailto:keycloak-user at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/keycloak-user
>
>
>
>
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user




More information about the keycloak-user mailing list