[keycloak-user] Getting the user email before delete it

Jairo Henao jahenao at itroisolutions.com
Mon Jun 13 15:48:20 EDT 2016


Ok, the report has already been sent

https://issues.jboss.org/browse/KEYCLOAK-3107



Jairo Henao Rojas
IT ROI Solutions
Software Architect

From: Stian Thorgersen [mailto:sthorger at redhat.com]
Sent: Monday, June 13, 2016 12:33 PM
To: Jairo Henao <jahenao at itroisolutions.com>
Cc: keycloak-user at lists.jboss.org
Subject: Re: [keycloak-user] Getting the user email before delete it

You're right, the event is fired after the user is deleted so it won't be available. You can create a JIRA feature request if you want.

On 13 June 2016 at 18:31, Jairo Henao <jahenao at itroisolutions.com<mailto:jahenao at itroisolutions.com>> wrote:
Thanks Stian:

Your suggestion works well for 'create' and 'update' events, but when I try to use the session.users().getUserById(userId, realm), the result is null.

☹

if (event.getRealmId() != null && event.getAuthDetails().getUserId() != null && event.getResourcePath() != null && event.getResourcePath().startsWith("users/")) {
                     RealmModel realm = model.getRealm(event.getRealmId());
                     String userId = event.getResourcePath().substring(event.getResourcePath().lastIndexOf("/")+1);
            UserModel user = session.users().getUserById(userId, realm);

            if (user != null) {
                           if(OperationType.DELETE.equals(event.getOperationType())){
                                  //Deleting the user in Hubspot
                                  log.infov("Deleting the user (ID={0}) in Hubspot...", user.getEmail());
                           }else if(OperationType.UPDATE.equals(event.getOperationType())){
                                  //Deleting the user in Hubspot
                                  log.infov("Updating the user (ID={0}) in Hubspot...", user.getEmail());
                           }else if(OperationType.CREATE.equals(event.getOperationType())){
                                  //Deleting the user in Hubspot
                                  log.infov("Registering the user (ID={0}) in Hubspot...", user.getEmail());
                           }
            }else{
              log.errorv("No User found with ID={0}, Operation={1}", userId, event.getOperationType());
            }
              }else{
              log.errorv("No Realm ID or User ID found");
        }




2016-06-13 11:22:02,502 INFO  [com.itroi.keycloak.events.hubspot.HubspotEventListenerProvider] (default task-56) Registering the user (ID=user500 at mail.com<mailto:user500 at mail.com>) in Hubspot...
2016-06-13 11:22:19,463 INFO  [com.itroi.keycloak.events.hubspot.HubspotEventListenerProvider] (default task-64) Updating the user (ID=user500 at mail2.com<mailto:user500 at mail2.com>) in Hubspot...
2016-06-13 11:22:32,403 ERROR [com.itroi.keycloak.events.hubspot.HubspotEventListenerProvider] (default task-7) No User found with ID=179e55e6-5788-4a10-a640-6661485bfa95, Operation=DELETE


Jairo Henao Rojas
IT ROI Solutions
Software Architect
Mobile  : 314-738-6032<tel:314-738-6032>
Office Colombia: + (571) 381-9185<tel:%28571%29%20381-9185>
Office Mexico: + 52-81-4624-4468<tel:%2B%2052-81-4624-4468>
Office Chile: + 5622-582-2257
Office USA:  954-518-3330<tel:954-518-3330>
Office Canada:  604-998-2280<tel:604-998-2280>
jahenao at itroisolutions.com<mailto:jahenao at itroisolutions.com>

[cid:image001.png at 01CFACA6.CA39D4D0]

[Description: Description: cid:image002.png at 01CD70CF.8782CD50]<https://twitter.com/ITROISolutions>[Description: Description: cid:image003.png at 01CD70CF.8782CD50]<http://www.linkedin.com/company/itroi-solutions> [Description: Description: cid:image004.png at 01CD70CF.8782CD50] <http://www.facebook.com/pages/IT-ROI-Solutions-CA-Clarity-Consultants/110571835703154>  [Description: Description: cid:image005.png at 01CD70CF.8782CD50] <http://www.youtube.com/user/ITROISolutions>

From: Stian Thorgersen [mailto:sthorger at redhat.com<mailto:sthorger at redhat.com>]
Sent: Monday, June 13, 2016 8:28 AM
To: Jairo Henao <jahenao at itroisolutions.com<mailto:jahenao at itroisolutions.com>>
Cc: keycloak-user at lists.jboss.org<mailto:keycloak-user at lists.jboss.org>
Subject: Re: [keycloak-user] Getting the user email before delete it

You can get the user object from session.users().getUserById(..), which will give you the email.

On 11 June 2016 at 08:58, Jairo Henao <jahenao at itroisolutions.com<mailto:jahenao at itroisolutions.com>> wrote:
Hello community:

I have a listener that is pending when an administrator deletes a user. How I can get the user email?

Apparently I can only get his ID, but I need his email to delete it in HubSpot.

There is something like a pre-delete event?

Thanks,


Jairo Henao Rojas
IT ROI Solutions
Software Architect
Mobile  : 314-738-6032<tel:314-738-6032>
Office Colombia: + (571) 381-9185<tel:%28571%29%20381-9185>
Office Mexico: + 52-81-4624-4468<tel:%2B%2052-81-4624-4468>
Office Chile: + 5622-582-2257
Office USA:  954-518-3330<tel:954-518-3330>
Office Canada:  604-998-2280<tel:604-998-2280>
jahenao at itroisolutions.com<mailto:jahenao at itroisolutions.com>

[cid:image001.png at 01CFACA6.CA39D4D0]

[Description: Description: cid:image002.png at 01CD70CF.8782CD50]<https://twitter.com/ITROISolutions>[Description: Description: cid:image003.png at 01CD70CF.8782CD50]<http://www.linkedin.com/company/itroi-solutions> [Description: Description: cid:image004.png at 01CD70CF.8782CD50] <http://www.facebook.com/pages/IT-ROI-Solutions-CA-Clarity-Consultants/110571835703154>  [Description: Description: cid:image005.png at 01CD70CF.8782CD50] <http://www.youtube.com/user/ITROISolutions>


_______________________________________________
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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160613/f7e1d21d/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 2814 bytes
Desc: image001.png
Url : http://lists.jboss.org/pipermail/keycloak-user/attachments/20160613/f7e1d21d/attachment-0005.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 2066 bytes
Desc: image002.png
Url : http://lists.jboss.org/pipermail/keycloak-user/attachments/20160613/f7e1d21d/attachment-0006.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 2435 bytes
Desc: image003.png
Url : http://lists.jboss.org/pipermail/keycloak-user/attachments/20160613/f7e1d21d/attachment-0007.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 3041 bytes
Desc: image004.png
Url : http://lists.jboss.org/pipermail/keycloak-user/attachments/20160613/f7e1d21d/attachment-0008.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 2897 bytes
Desc: image005.png
Url : http://lists.jboss.org/pipermail/keycloak-user/attachments/20160613/f7e1d21d/attachment-0009.png 


More information about the keycloak-user mailing list