Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-28079

User session/context is not fully established in automation triggered by loginSuccess event

    XMLWordPrintable

    Details

      Description

      There seems to be no easy/direct way to get the current user when running an automation script triggered by the loginSuccess event.

      i.e. CurrentUser.getActingUser() is null

      This script provides a workaround, but is definitely less than obvious:

       

      function run(input, params) {
        Console.info("script log_user_js:");
        Console.info("  ctx        : '" + ctx           + "' (" + typeof(ctx)            + ")");
        if (ctx && ctx.Event) {
          Console.info("    event    : '" + ctx.Event      + "' (" + typeof(ctx.Event)     + ")");
          Console.info("      name   : '" + ctx.Event.name + "' (" + typeof(ctx.Event.name) + ")");
        }
      
        var actingUser;
        var eventCtx;
        var principal;
        var UserManager;
      
        UserManager = Fn.getUserManager();
        Console.info("  UserManager: '" + UserManager + "'");
      
        eventCtx = ctx.Event.getContext();
        Console.info("  eventCtx   : '" + eventCtx + "'");
      
        // org.nuxeo.ecm.core.api.impl.UserPrincipal
        principal = eventCtx.getPrincipal();
        Console.info("  principal  : '" + principal + "'");
      
        actingUser = principal.getActingUser();
        Console.info("  actingUser : '" + actingUser + "'");
      
        // org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl
        principal = UserManager.getPrincipal(actingUser);
        Console.info("  principal  : '" + principal + "'");
        Console.info("  firstName  : '" + principal.getFirstName() + "'");
        Console.info("  lastName   : '" + principal.getLastName()  + "'");
        Console.info("  email      : '" + principal.getEmail()     + "'");
      
        return input;
      }
      

       

       

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: