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

No principal with automation in the context of a scheduler event

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 11.4
    • Fix Version/s: 11.5, 2021.2
    • Component/s: Authentication
    • Backlog priority:
      710
    • Team:
      FG
    • Sprint:
      nxFG 11.3.1
    • Story Points:
      1

      Description

      This used to work in 10.10, fails (see below) in 11.4:

      1. Have a scheduler

      <extension target="org.nuxeo.ecm.core.scheduler.SchedulerService" point="schedule">
        <schedule id="CLEANUP_DEMO">
          <eventId>cleanupDemo</eventId>
          <eventCategory>default</eventCategory>
          <!-- Every hour -->
          <cronExpression>0 0 0/1 * * ?</cronExpression>
        </schedule>
      </extension>
      

      2. And an event handler (Studio => not a Java listener):

      <extension target="org.nuxeo.ecm.core.operation.OperationServiceComponent" point="event-handlers">
          <handler chainId="javascript.Admin_DemoScheduledCleanup">
            <event>cleanupDemo</event>
          </handler>
      . . .
      

      3. The JS is very simple:

      function run(input, params) {
        var docs, nxql, found;
        Auth.LoginAs(null, {}); // <========== Fails here
        docs = Repository.Query( . . . . )
      

      The JS fails with NPE when calling the operation, because (looking at the source code) it expects a principal but there is none (it fails at line 55)

      #54    Principal origPrincipal = ctx.getPrincipal();
      #55    lc = Framework.loginSystem(origPrincipal.getName());
      

      Reminder : this worked fine in 10.10, so something changed in between.

      Workaround : explicitly set the user to a an administrator:

      Auth.LoginAs(null, {"name": "Administrator"}); 
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours
                  2h