Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-99412

Automate the process of enabling and disabling external directories in Confluence

XMLWordPrintable

    • 1
    • We collect Confluence feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      Some companies might have specific requirements of enabling/disabling external directories in Confluence in an automated way (due to DR exercises, for example).

      Currently, Confluence does not have a built-in functionality to automate this tasks and administrators needs to perform such changes directly through the User Directories menu in the browser.

      Workaround

      The following script can be used to automate this task, but it has limitations:

      #######
      # Adjust some variables
      #######
      CONFLUENCE_BASE_URL=https://<confluence-base-url>
      ADMIN_USERNAME=<local admin username>
      ADMIN_PASSWORD=<local admin password>
      COOKIES_FILE=tomcatcookies.txt
      
      USR_DIR_ID=<ID of the directory being updated>
      USR_DIR_OPERATION=enable
      
      #######
      # Get session cookies that will be reused on the next steps.
      # The expected output is the HTTP status 200.
      #######
      curl -s ${CONFLUENCE_BASE_URL}'/rest/tsv/1.0/authenticate' -X POST \
        -c "${COOKIES_FILE}" \
        -H 'Content-Type: application/json' \
        --data-raw '{"username":"'${ADMIN_USERNAME}'","password":"'${ADMIN_PASSWORD}'","rememberMe":true,"targetUrl":"/plugins/servlet/embedded-crowd/directories/list","captchaId":""}'
      
      
      #######
      # Validate the authentication worked (optional)
      #######
      curl -s -c "${COOKIES_FILE}" -b "${COOKIES_FILE}" \
        ${CONFLUENCE_BASE_URL}'/rest/api/user/current'
      
      #######
      # Get the xsrf token
      #######
      ATL_XSRF_TOKEN=$(curl -s -c "${COOKIES_FILE}" -b "${COOKIES_FILE}" \
        ${CONFLUENCE_BASE_URL}'/plugins/servlet/embedded-crowd/directories/list' | awk -F 'content="' '/<meta id="atlassian-token"/ {print $2}' | awk -F '"' '{print $1}')
      
      #######
      # Run the user directory operation
      #######
      curl -o /dev/null -s -w "%{http_code}\n" -X POST \
        -c "${COOKIES_FILE}" -b "${COOKIES_FILE}" \
        -H 'Content-Type: application/x-www-form-urlencoded' \
        ${CONFLUENCE_BASE_URL}'/plugins/servlet/embedded-crowd/directories/'${USR_DIR_OPERATION}'?directoryId='${USR_DIR_ID} \
        --data-raw 'atl_token='${ATL_XSRF_TOKEN}

       Please note that you'll need to adjust the script variables according to your instance's settings:

      • CONFLUENCE_BASE_URL: Is the base URL of your instance.
      • ADMIN_USERNAME: The username of a Confluence local admin (the user must exist in Confluence's internal directory).
      • ADMIN_PASSWORD: The password of the admin user.
      • USR_DIR_ID: The ID of the directory you wish to disable - this can be found in Confluence's cwd_directory table.
      • USR_DIR_OPERATION: The kind of operation you wish to perform. This can be either enable or disable.

      Please note that, in order for the script to work, Secure Administrator Sessions must be turned OFF in the instance. 

      Please note that, the endpoints used in the script are only available on Confluence 9.0 onward.

              Unassigned Unassigned
              cd74979134f3 Murilo Bellini
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: