Uploaded image for project: 'Artifactory Binary Repository'
  1. Artifactory Binary Repository
  2. RTFACT-14884

Unable to switch to system role from within a method

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Normal
    • Resolution: Done
    • Affects Version/s: 5.3.2
    • Fix Version/s: None
    • Component/s: Plugins
    • Labels:
      None

      Description

      asSystem block does not work correctly when attempting to use from a method:

      test-assystem.groovy
      import org.artifactory.security.RealmPolicy
      import org.artifactory.security.User
      
      realms {
          testAsSystem(autoCreateUsers: false, realmPolicy: RealmPolicy.ADDITIVE) {
              authenticate { username, password ->
                  log.debug('Initializing: running as {}', security.currentUsername)
                  asSystem {
                      log.debug('Switching context: running as {}', security.currentUsername)
                  }
                  try {
                      doSomething()
                  } catch (Exception e) {
                      log.warn('Failed to do something: {}', e.message)
                  }
                  log.debug('Finalizing: running as {}', security.currentUsername)
                  return true
              }
      
              userExists { username ->
                  return true
              }
          }
      }
      
      void doSomething() {
          log.debug('Doing something: running as {}', security.currentUsername)
          asSystem {
              log.debug('Doing something as system: running as {}', security.currentUsername)
          }
      }
      
      artifactory.log
      2017-09-01 14:42:11,781 [http-nio-8081-exec-218] [DEBUG] (test-assystem       :7) - Initializing: running as anonymous
      2017-09-01 14:42:11,787 [http-nio-8081-exec-218] [DEBUG] (test-assystem       :9) - Switching context: running as _system_
      2017-09-01 14:42:11,787 [http-nio-8081-exec-218] [DEBUG] (test-assystem       :27) - Doing something: running as anonymous
      2017-09-01 14:42:11,789 [http-nio-8081-exec-218] [WARN ] (test-assystem       :14) - Failed to do something: No signature of method: org.artifactory.addon.plugin.DefaultMethodsDelegate.doSomething() is applicable for argument types: () values: []
      Possible solutions: toString(), toString()
      2017-09-01 14:42:11,789 [http-nio-8081-exec-218] [DEBUG] (test-assystem       :16) - Finalizing: running as anonymous
      

      Please re-work asSystem support to be able to use also from methods. It is important to elevate privileges for as little work as required and not for the whole plugin.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              akm022 Krzysztof Malinowski
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: