Listening to changes in sling's users and groups - jackrabbit

I want to be notified of changes to users or groups in sling's userManager as they happen. For example, when a new group is created, I need to create a new node with the same name under /content. When a new user is created, I want to give them write-permissions for /content/foo. And similar tearDown steps when objects are deleted.
I tried registering a EventHandler (org.osgi.service.event.EventHandler), with event.topics set to "*" (all topics), but this captured only resource changes and not userManager changes because users and groups are synthetic resources (I think)
I tried using a org.apache.sling.api.request.SlingRequestListener, but the SlingRequestEvent did not come with any info that would help me distinguish the request (or I didn't know how). Also, I am not sure if this is can even be used for callbacks that need to be called AFTER the request is processed.
I have used Filters for a different issue and I tried applying them for this purpose too. But they have their limitations - My filter is called BEFORE the request, so it's not possible to know if the request will result in SUCCESS before deciding to take action.
Any suggestions on how to listen and respond to changes in sling's user and group models?

In https://issues.apache.org/jira/browse/SLING-977 Ian Boston suggests using a SlingPostProcessor service to be informed of calls to the user management's POST servlets.
I haven't tried it myself, and if you do it you might anyway miss changes that are done via Sling's user management APIs - but that might be good enough depending on your use case.
Apart from that I don't think there's currently a surefire way of being notified of such changes. To implement that in Sling we'd need to wrap the org.apache.jackrabbit.api.security.user.* objects (Group, User, UserManager) to send events when they're changed. Certainly doable but would require changes to that Sling bundle.

Related

How send notification into ms teams user from custom tab

I'm designing a custom team tab using React that calls third party API, I need after executing the API successfully, user gets notified . What is the best way to achieve this? I used Bot in my project, but not sure how can I call it from my custom tab class. I'm aware of the existence of proactive messaging, is it the only way to do it? If it is, a pointer on how to implement it to a custom tab would be appreciated.
If you're wanting to message the user 1-1 (like in the personal app), then proactive messaging is definitely what you need (inside a Team, there are other options), and considering you have the bot already in place that's perfect. The only thing you might be missing are the details required to send the actual proactive message (the best time to get them is when the bot is first installed by the user). In particular, you need ConversationId and ServiceUrl.
With regards the concept of Proactive Messaging, basically once the bot is installed, and you have the required values, you can -send- the message from any backend code at all. That can include, for example, custom tab's backend api. You need to identify the user, which you can do using the Teams Context (it's not the safest way but it's the easiest), and then look up the values in your own backend store (e.g. database or whatever) to get the ConversationId and ServiceUrl, then just message the user in your backend.

Raise an event notification to a specific client when a user is registered/created on Identity Server

I am creating an AdminUI for my users where I set all the permission. As part of the requirements, every time that a user logins on my IdentityServer I need to set some default permissions, but those are handle on my Admin application. Which is the best way to raise an event to let that application that a user was created on the IdentityServer?
The simplest is i think to create a simple WebApi in IdentityServer that returns the latest users and then let the other application poll this API every X seconds. In that way the system is cleanly decoupled. Perhaps expose the data as a a RSS XML document or a JSON list of items.
There is a built in eventing model in IdentityServer that you could use and push notifications to the Admin application. But push is a bit more complicated to get right, especially how to deal with all the failre/error cases.
I's suggest to add a custom event sink to process UserLoginSuccessEvent or any other event you need, here is list of all builtin events. Find their code here.
In the custom sink as suggested in the other answer you can call an API on admin app to inform it about changes.
Here is a sample for custom sink.
I think to keep two applications decoupled you better to setup a service-bus for simple implementation a sub/pub mechanism. when any user complete registration(or any other actions),then as mentioned in another answer handle the events and add message. admin UI should subscribed before to receive these messages with some information to create a user related data.

Salesforce – Notify external API (or create activity event) on custom object change

I need a fairly trivial thing: every time a user changes a salesoforce custom object field, I need to notify the external service about the change.
Either push the notification or somehow log the object change event somewhere in salesforce. (and make the external service regularly check those latest events for any new activity)
Is either of those options possible?
The only info I could find on this issue is this somewhat relevant SO thread, but it's 3 years old and doesn't answer anything.
This can be done by creating a PushTopic and subscribing to it via Streaming API.

Getting history events for just new messages?

I'd like to monitor a users gmail account for new messages and take an appropriate action. Is there a way to fetch the history events for just new messages but NOT for things like starring an email or changing its labels, etc.?
So I ended up using messages.list and storing the timestamp of the most recent message. Then on subsequent calls to messages.list I'd supply a query of "after:theMostRecentTimestampIKnowOf" to find new messages since the last time we synced.
Another route I've seen done, is if you have the ability to add a filter (e.g. user's can do that, or use the Google Admin SDK for Google Apps users, or do it through HTML/DOM hacking) then you can simply setup a filter to apply a label to all new messages. Then just messages.list(labelId=THAT_LABEL) when you do your polling (and remove it after you process them).
There is not any ability now to filter history based on change type, though it's something that would be nice to provide at some point.

AngularJS: combine REST with Socket.IO

In the single page webapp I've recently built I'm getting data for my models using Restangular module. I'd like to add real-time updates to the app so whenever any model has been changed or added on the server I can update my model list.
I've seen this working very well in webapps like Trello where you can see the updates without refreshing the web page. I'm sure Trello webclient uses REST API.
What is a proper way to architect both server and client to archive this?
First of all, your question is too general and can have a lot of solutions that depend
on your needs and conditions.
I'll give you a brief overview for a single case when you want to leave REST APIs
and add some realtime with web sockets.
Get all data from the REST -- Sokets for notifications only.
Pros: Easy to implement both server side and client side. You only need to emit events on the server with
info about modified resource (like resource name and ID), and catch these events on the client side and fetch
data with REST APIs.
Cons: One more request to the server on every notification. That can increase traffic dramaticaly when you have a lot of active clients for a single resource (they will generate a lot of reverse requests to the server).
Get initial load from the REST -- Sockets for notifications with data payload.
Pros: All info comes with the notification and will not cause new requests to the server, so we have less traffic.
Cons: Harder to implement both server side and client side. You will need to add data to all the events on the server. You will need to fetch data from all the events on the client side.
Updated according to the comment
As for handling different types of models (just a way to go).
Client side.
Keep a factory for each model.
Keep in mind that you need realtime updates only for displayed data (in most cases), so you can easily
use memory caching (so you can find any entity by its ID).
Add listener for every type of changes (Created, Updated, Deleted).
In any listener you should call some initObject function, that will find entity in the cache by ID and extend it, if there is no entity with such ID, just create a new one and add it to cache.
Any Delete just removes an entity from the cache.
Any time you need this resource, you should return the link to cache object in order to keep two way databinding (that is why I use extend and not =). Of course, you need to handle the cases like: "User is editing the resource while notification about deleting comes".
Server side.
It is easier to send all the model then just modified fields (in both cases you must send the ID of resource).
For any Create, Update, Delete event push event to all engaged users.
Event name should contain action name (like New, Update, Delete) and the name of resource (like User, Task etc.). So, you will have NewTask, UpdateTask events.
Event payload should contain the model or just modified fields with the ID.
Collection changes can be handled in two ways: with add/update/remove items in collection or changing all the collection as a whole.
All modifications like PUT, POST, DELETE are made with REST of course.
I've made a super simple pseudo gist for the case 1). https://gist.github.com/gpstmp/9868760 but it can be updated for case 2) like so https://gist.github.com/gpstmp/9900454
Hope this helps.

Resources