Changes

Jump to navigation Jump to search
731 bytes added ,  18:39, 1 December 2023
m
Text replacement - "syntaxhighlight" to "pre"
This [[Module Library|XQuery Module]] contains functions for creating and administering database users. The [[User Management]] article gives provides more information on database users and permissions.
=Conventions=
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:current||() as xs:string}}<br/pre>|-valign="top"
| '''Summary'''
|Returns the name of the currently logged -in user.|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:list||() as xs:string*}}<br/pre>|-valign="top"
| '''Summary'''
|Returns the names of all registered users that who are visible to the current user.|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|user:list-details||element(user)*}}<br/pre>{{Func|user:list-details|( $name as xs:string| := ()) as element(user)*}}<br/pre>|-valign="top"
| '''Summary'''
|Returns an element sequence, containing all registered users that who are visible to the current user.<br/>In addition to the [[Commands#SHOW_USERS{{Command|SHOW USERS]] }} command, encoded password strings and database permissions will be output. A user {{Code|$name}} can be specified to filter the results in advance.|-valign="top"
| '''Examples'''
|
* After a fresh installation, {{Code|user:list-details()}} returns output similar to the following one:
<pre classlang="brush:xml">
<user name="admin" permission="admin">
<password algorithm="digest">
</user>
</pre>
|-valign="top"
| '''Errors'''
|{{Error|unknown|#Errors}} The specified user name username is unknown.
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:exists|( $name as xs:string|) as xs:boolean}}<br/pre>|-valign="top"
| '''Summary'''
|Checks if a user with the specified {{Code|$name}} exists.
|-valign="top"
| '''Examples'''
|
* {{Code|user:exists('admin')}} will always yield true.
|-valign="top"
| '''Errors'''
|{{Error|name|#Errors}} The specified user name username is invalid.
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:check|( $name as xs:string, $password as xs:string|xs:) as empty-sequence()}}<br/pre>|-valign="top"
| '''Summary'''
|Checks if the specified user and password is correct. Raises errors otherwise.
|-valign="top"
| '''Examples'''
|
* {{Code|user:check('admin', 'admin')}} will raise an error if the password of the admin password was changeduser is a non-empty string.|-valign="top"
| '''Errors'''
|{{Error|name|#Errors}} The specified user name username is invalid.<br/>{{Error|unknown|#Errors}} The specified user does not exist.<br/>{{Error|password|#Errors}} The specified password is wrong.<br/>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:info||( $name as xs:string := ()) as element(info)}}</pre>|-valign="top"
| '''Summary'''
|Returns an <code>info</code> element, which can be used to organize may contain application-specific data. If a user {{Code|$name}} is supplied, a user-specific element is returned. By default, the returned element has no contents. It can be modified via [[#user:update-info{{Function||user:update-info]]}}.|-valign="top"
| '''Examples'''
|
=Updates=
'''Important note:''' All functions in this section are ''updating functions'': they will not be immediately executed, but queued on the [[XQuery Update#Pending Update List|Pending Update List]], which will be processed after the actual query has been evaluated. This means that the order in which the functions are specified in the query usually does usually not reflect the order in which the code will be evaluated.
==user:create==
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|user:create|$name as xs:string, $password as xs:string|empty-sequence()}}<br/pre>{{Func|user:create|( $name as xs:string, $password as xs:string, $permissions as xs:string*|empty-sequence := ()}}<br/>{{Func|user:create|, $name patterns as xs:string, $password as xs* :string= (), $permissions info as xselement(info) :string*, $patterns = ()) as xs:string*|empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Creates a new user with the specified {{Code|$name}}, {{Code|$password}}, and {{Code|$permissions}}. :* Local permissions are granted with non-empty glob {{Code|$patterns}}. * An {{Code|$info}} element with application-specific information can be supplied.* The default global permission (''none'') can be overwritten with an empty pattern or by omitting the last argument. * Existing users will be overwritten.|-valign="top"
| '''Examples'''
|
* {{Code|user:create('John', '7e$j#!1', 'admin')}} creates a new user 'John' with admin permissions.
* {{Code|user:create('Jack', 'top!secret', 'read', 'index*')}} creates a new user 'Jack' with no permissions, but write read permissions for databases starting with the letters 'index'.|-valign="top"
| '''Errors'''
|{{Error|name|#Errors}} The specified user name username is invalid.<br/>{{Error|permission|#Errors}} The specified permission is invalid.<br/>{{Error|admin|#Errors}} The "admin" user cannot be modified.<br/>{{Error|logged-in|#Errors}} The specified user is currently logged in.<br/>{{Error|update|#Errors}} The operation can only be performed once per user or database pattern.
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|user:grant|$name as xs:string, $permissions as xs:string*|empty-sequence()}}<br/pre>{{Func|user:grant|( $name as xs:string, $permissions as xs:string*, $patterns as xs:string*| := ()) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Grants global or local {{Code|$permissions}} to a user with the specified {{Code|$name}}. Local permissions are granted with non-empty glob {{Code|$patterns}}.
|-valign="top"
| '''Examples'''
|
* {{Code|user:grant('John', 'create')}} grants create permissions to the user 'John'.
* {{Code|user:grant('John', ('read','write'), ('index*','unit*'))}} allows John to read all databases starting with the letters 'index', and to write to all databases starting with 'unit'.
|-valign="top"
| '''Errors'''
|{{Error|unknown|#Errors}} The specified user name username is unknown.<br/>{{Error|name|#Errors}} The specified user name username is invalid.<br/>{{Error|pattern|#Errors}} The specified database pattern is invalid.<br/>{{Error|permission|#Errors}} The specified permission is invalid.<br/>{{Error|admin|#Errors}} The "admin" user cannot be modified.<br/>{{Error|local|#Errors}} A local permission can only be 'none', 'read' or 'write'.<br/>{{Error|logged-in|#Errors}} The specified user is currently logged in.<br/>{{Error|update|#Errors}} The operation can only be performed once per user or database pattern.
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|user:drop|$name as xs:string|empty-sequence()}}<br/pre>{{Func|user:drop|( $name as xs:string, $patterns as xs:string*| := ()) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Drops a user with the specified {{Code|$name}}. If non-empty glob {{Code|$patterns}} are specified, only the database patterns will be droppedremoved.|-valign="top"
| '''Examples'''
|
* {{Code|user:drop('John')}} drops the user 'John'.
* {{Code|user:grant('John', 'unit*')}} removes the 'unit*' database pattern. If John accesses any of these database, his global permission will be checked again.
|-valign="top"
| '''Errors'''
|{{Error|unknown|#Errors}} The specified user name username is unknown.<br/>{{Error|name|#Errors}} The specified user name username is invalid.<br/>{{Error|pattern|#Errors}} The specified database pattern is invalid.<br/>{{Error|admin|#Errors}} The "admin" user cannot be modified.<br/>{{Error|logged-in|#Errors}} The specified user is currently logged in.<br/>{{Error|update|#Errors}} The operation can only be performed once per user or database pattern.<br/>{{Error|conflict|#Errors}} A user cannot be both altered and dropped.
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:alter|( $name as xs:string, $newname as xs:string|) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Renames a user with the specified {{Code|$name}} to {{Code|$newname}}.
|-valign="top"
| '''Examples'''
|
* {{Code|user:renamealter('John', 'Jack')}} renames the user 'John' to 'Jack'.|-valign="top"
| '''Errors'''
|{{Error|unknown|#Errors}} The specified user name username is unknown.<br/>{{Error|name|#Errors}} The specified user name username is invalid.<br/>{{Error|admin|#Errors}} The "admin" user cannot be modified.<br/>{{Error|logged-in|#Errors}} The specified user is currently logged in.<br/>{{Error|update|#Errors}} The operation can only be performed once per user or database pattern.<br/>{{Error|conflict|#Errors}} A user cannot be both altered and dropped.
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:password|( $name as xs:string, $password as xs:string|) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Changes the {{Code|password}} of a user with the specified {{Code|$name}}.
|-valign="top"
| '''Examples'''
|
* {{Code|user:password('John', '')}} assigns user 'John' an empty password string.
|-valign="top"
| '''Errors'''
|{{Error|unknown|#Errors}} The specified user name username is unknown.<br/>{{Error|name|#Errors}} The specified user name username is invalid.<br/>{{Error|update|#Errors}} The operation can only be performed once per user or database pattern.
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>user:update-info|( $info as element(info)|, $name as xs:string := ()) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Updates Assigns the <code>specified {{Code|$info</code> }} element with to the user management or, if {{Code|$infoname}}is supplied, to a specific user. This node function can be used to organize manage application-specific data (groups, enhanced user info, etc.).|-valign="top"
| '''Examples'''
|
* Store initial groups information:
<pre classlang="brush:'xquery"'>
user:update-info(element info {
for $group in ('editor', 'author', 'writer')
})
</pre>
* Assign Add a group to a new specific user:<pre classlang="brush:'xquery"'>let $user := 'john', $pw := '8hKJ@%.c/!0O', $group := 'editor'return ( user:create($user, $pw), user:update-info(user:<info() update insert node <user name='{ $user }' group='{ $group }editor'/> into . ), 'john')
</pre>
|}
! width="110"|Code
|Description
|-valign="top"
|{{Code|admin}}
|The "admin" user cannot be modified.
|-valign="top"
|{{Code|conflict}}
|A user cannot be both altered and dropped.
|-valign="top"
|{{Code|equal}}
|Name of old and new user is equal.
|-valign="top"
|{{Code|local}}
|A local permission can only be 'none', 'read' or 'write'.
|-valign="top"
|{{Code|logged-in}}
|The specified user is currently logged in.
|-valign="top"
|{{Code|name}}
|The specified user name username is invalid.|-valign="top"
|{{Code|password}}
|The specified password is wrong.
|-valign="top"
|{{Code|pattern}}
|The specified database name is invalid.
|-valign="top"
|{{Code|permission}}
|The specified permission is invalid.
|-valign="top"
|{{Code|unknown}}
|The specified user does not exist.
|-valign="top"
|{{Code|update}}
|The operation can only be performed once per user or database pattern.
;Version 8.6
* AddedUpdated: [[#{{Function||user:checkcreate}}, {{Function||user:check]]info}}, [[#{{Function||user:update-info}}: {{Code|$name}} parameter added. ;Version 8.6* Added: {{Function||user:info]]check}}, [[#{{Function||user:update-info}}, {{Function||user:update-info]]}}.* Updated: [[#user:list{{Function||user:list]]}}, [[#user:list-details{{Function||user:list-details]]}}: If called by non-admins, will only return the current user.
;Version 8.4
* Updated: [[#user:create{{Function||user:create]]}}, [[#user:grant{{Function||user:grant]]}}, [[#user:drop{{Function||user:drop]]}}: extended support for database patterns.
;Version 8.1
* Added: [[#user:current{{Function||user:current]]}}.
The Module was introduced with Version 8.0.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu