Question
· 17 hr ago

How to create a user via ObjectScript for the instance and specify roles and namespace?

I am trying to create users who only have `%SQL` Role for the INSTANCE. But I am unable to find any documentation on the ` Security.Users` class.

See:

    // Instantiate the Security.Users object
    Set userObj = ##class(Security.Users).%New()    
    // Set the username and password
    Set userObj.Name = userName
    Set userObj.FullName = userFullName
    Set userObj.Namespace = "USER"
    Set userObj.Roles = "%SQL"
    Set sc = userObj.ChangePassword(passwd)    
    // Save the user to the database
    Set ss = userObj.%Save()

I cant figure out the "Namespace" property for this class, let alone assign a password. Any help would be appreciated. Also the `ChangePassword` method does not appear to work.

Product version: IRIS 2024.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2024.1.2 (Build 398_0_23819) Wed Nov 20 2024 18:24:21 EST
Discussion (1)2
Log in or sign up to continue

Ronaldo,

The ChangePassword property isn't for the password, it's to set a flag if the user is supposed to change their password on next login - this property's handy for admins that assign temporary passwords and the user needs to change it to something befitting them on first login. To set the property, it's a simple 'set' like the others:

Set userObj.ChangePassword=1

And to set the initial Password is also a standard 'set':

Set userObj.Password="initialpassword"

Also, if the Roles is only %SQL, but if you're testing the login using Terminal, that user doesn't have enough rights for that functionality and you'll probably get an 'Access Denied' error. You'll either need to (temporarily) assign the %All role to that user to test, or just verify that the settings are getting set in the Management Portal.

As to the NameSpace, if the Namespace doesn't exist (typo, I've done that before) or if the user doesn't have enough rights to access that Namespace, it may not be set correctly.

Lastly, here's the documentation for the Security.Users class:  https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic.cls?LIBRARY=%25SYS&CLASSNAME=Security.Us

Hope this helps!

[[ edit for readability and examples were out of order. ]]