I am having problems getting a message handler to react from an authentication challenge complete script.
The message handler type is "saveRecord", it is saving info to a database after an authentication challenge. It is used in a few places, so it is a message handler attached to the root of my main view in the project. I have widened its scope to Session, Page, and View.
Assuming authentication is successful, I execute:
logger.info("user = {} roles = {}".format(user, roles))
#Success - save the record
system.perspective.sendMessage("saveRecord", sessionID = session.info["id"], scope = "session")
logger.info("Made it past the save")
I have confirmed that sessionID s match, but ithe message handler doesn't fire. I can see that it made it past the call because I see "Made it past the save" in the log. But no saving happens, and no log messages that happen every other time I successfully fire the message handler under other circumstances.
OK, doing a little checking, it looks like the view isn't there during the challenge, or at least i have found it restarts after the challenge is done.
I could move it, but it kind of shoots my scope, because the data I want to record is in the view. Or at least some of it, most of it is in session custom properties. I should be able to get everything I need to save into there
I have a view with info displayed in a table and a couple of textboxes. I want to do an authentication challenge, and if it fails, I want to take the user back to the view with all of the information still filled in. I figured out how to do that, based on taking away persistence in some elements, etc
But I would also like to have a popup saying something like "Your credentials don't have privilege to do this". I'm having problems with communicating between this Authentication Challenge session and the view/page that doesn't exist during this challenge script. How would I get it to make a popup, or just communicate with the calling page that is no longer there, but will be momentarily?
Have you looked into security settings on your button (or whatever object) you are using? This is a built in feature and limits an action based on roles/zones.
If they done have rights they will see this popup:
Yes, good idea, that would solve that problem, I wouldn't have thought of that.
But this is an authentication challenge where an operator is already logged in, and system.perspective.authenticationChallenge is called. This is so when there is an error, the operator is stopped and a supervisor has to log in to show that they saw it, therefore the username of the person about to authenticate is not known.
So, when this kind of challenge occurs, it would be good to be able for the view that is being used to be able to react to the result of the authentication challenge, whether with a popup or an error box built into the view.
As it is, the authentication challenge event is called in session scope, and I don't see how to get information back from that scope to the calling scope. Perhaps through session properties, but every time I think about doing that it becomes more and more complex in my head and seems like it would turn into a horrible can of worms.
I did end up doing it with a session variable. Since the view restarts when the auth challenge is done, I left a message for it from the authentication challenge. Kinda janky but it works
Use a gateway message event instead of a perspective message event.
You can send these messages with system.util.sendMessage instead of system.perspective.sendMessage. You can even use sendRequest to get a response back and confirm that the recording was successful, if that matters.