Errors attempting to run XQuery scripts for single sign on into MarkLogic

Viewed 48

I'm working on using an xquery re-writer script to automate the login for a Single Sign-On solution. I'm starting with the Admin App Server at port 8001. In the App Server configuration I have:

  • Set authentication = application-level
  • Set url rewriter = rewriter.xqy

I have also set the following rewriter.xqy script at the root Admin/ directory on the server. As you can see, just as a simple test, I'm attempting to programmatically login as user "Austin" (a valid user).

xquery version "1.0-ml";

import module namespace rest = "http://marklogic.com/appservices/rest"
    at "/MarkLogic/appservices/utils/rest.xqy";

import module namespace config = "http://marklogic.com/admin/endpoint-config"
    at "/endpoints/config.xqy";

xdmp:login("Austin")

return (rest:rewrite($config:OPTIONS,"uri"),xdmp:get-request-url())[1]

However, after recycling the webserver, I keep getting the following error when browsing to the Admin UI.
As soon as I remove the xdmp line, the error goes away, and I can get straight in.

500: Internal Server Error
XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected QName_
In /rewriter.xqy on line 9

As another test, I tried to log some messages using xdmp:log, but those lines are also failing.
Any clue why xdmp scripts are not running successfully?

1 Answers

In XQuery a return is only part of a FLWOR expression. It's not a procedural return. You can just execute a sequence here:

xdmp:login("Austin"),
(rest:rewrite($config:OPTIONS,"uri"),xdmp:get-request-url())[1]

I can't vouch that this logic is sound, but the syntax is.

Related