xqueryexist-db

Exist-db: extracting name from _eXist_xmldb_user string


This question was asked a long time ago by @lovemeansnothing. It was answered with the function: xmldb:get-current-user(). However, that function is no longer defined in the namespace and has been removed from exist-db documentation. The statements in the original question remain, so I have quoted it verbatim:

"I need to get the username of the current session as a string

this:

session:get-attribute('_eXist_xmldb_user')

returns this:

< account name="foobar" id="11" >< group name="dba" id="1048575" >< manager name="admin"/ >< /group>< /account >

But I only want the username that, in this example, is:

foobar

Is there any way to do that?"

Any help gratefully received

Ralph


Solution

  • Try

    xquery version "3.1";
    
    import module namespace sm = "http://exist-db.org/xquery/securitymanager";
    
    sm:id()//sm:real/sm:username/text()