Retrieving the active session

0
Is there a way to retreive the active system.session in a microflow?
asked
2 answers
3

You could write a Java action with no inputs and use this.getContext().getSession() and return the session object.

Why would you need the session anyway?

EDIT: I once solved such a requirement in the following manner:

  • I added a non-persistent entity with a reference to a system.User
  • On login, I create the entity and let it refer to the system.User
  • Then, I use Java to get the session identifier, see code below.
  • Whenever I needed to use the information in that non-persistent object, I would:

    • Get the session identifier
    • Retrieve a list of all non-persistent objects associated to the current user
    • Filter this list on the session identifier
    • I now have the object and I can use the information.

    public class GetSessionIdentifier extends UserAction<string> { public GetSessionIdentifier() { super(); }

    @Override public String executeAction() throws Exception { // BEGIN USER CODE return this.getContext().getSession().getId().toString(); // END USER CODE }

    /**

    • Returns a string representation of this action */ @Override public String toString() { return "GetSessionIdentifier"; }

    // BEGIN EXTRA CODE // END EXTRA CODE }

answered
0

In addition to Rom's comment, depending on your requirements you can also use the Session entity in the System module.

In some projects I had to use references from my data to the user that was logged in, but since 1 user account can have parallel sessions, we couldn't use the System.User entity.
We enable persistentSessions in the platform (PersistentSessions=true) and just did a database retrieve to find the session object from the user.

Just one side-note about associating object to user or session. The platform garbage collection is based on objects that are no longer 'accessible'. If you associate object to user or session, those objects are always accessible. Therefore any objects associated to session or user will never be cleaned up by the platform (this is desired behavior), until logout.
If you want objects to be cleaned up by the platform you should remove them yourself or reset the association.

answered