こちらの記事では、既存のユーザ設定をプログラムで変更する方法をご紹介します。
ユーザロールを追加/削除したい、有効期限設定を変更したい、等の場合にお役立てください。
なお、ユーザ設定をプログラムで新規作成する方法は こちら の記事で紹介しております。
1.ある特定ユーザの設定を参照+変更する方法
2.既存の全てのユーザの設定を参照する方法
3.おまけ(Webアプリケーション情報の参照+変更)
1.ある特定ユーザの設定を参照+変更する方法
USER>zn "%SYS"
%SYS>do ##class(Security.Users).Get("test",.prop)
%SYS>zwrite prop
prop("AccountNeverExpires")=0
prop("AutheEnabled")=0
prop("ChangePassword")=0
:
prop("Roles")="%DB_USER,%Developer,testrole"
$SYS>write prop("Roles")
%DB_USER,%Developer,testrole
%SYS>write ##class(Security.Users).AddRoles("test","%SQL")
1
%SYS>kill
%SYS>do ##class(Security.Users).Get("test",.prop)
%SYS>write prop("Roles")
%DB_USER,%Developer,%SQL,testrole
%SYS>set prop("Roles")="%Developer,testrole"
%SYS>write ##class(Security.Users).Modify("test",.prop)
1
%SYS>kill
%SYS>do ##class(Security.Users).Get("test",.prop)
%SYS>w prop("Roles")
%Developer,testrole
%SYS>write ##class(Security.Users).RemoveRoles("test","testrole")
1
%SYS>kill
%SYS>do ##class(Security.Users).Get("test",.prop)
%SYS>write prop("Roles")
%Developer
%SYS>zn "user"
USER>write $SYSTEM.SQL.Security.GrantPrivilege("Insert,Update,Select,Delete","Sample","Schema","testrole")
1
2.既存の全てのユーザの設定を参照する方法(例:ロール)
%SYS>set stmt=##class(%SQL.Statement).%New()
%SYS>write stmt.%PrepareClassQuery("Security.Users","List")
1
%SYS>set rs=stmt.%Execute()
%SYS>while rs.%Next() { write !,rs.%Get("Name")," || ",rs.%Get("Roles") }
Admin || %EnsRole_Administrator,%EnsRole_Developer,%Manager
CSPSystem ||
IAM || %IAM_API
SuperUser || %All
UnknownUser || %All
_Ensemble || %All
_PUBLIC ||
_SYSTEM || %All
test ||
※Listクエリの詳細情報はこちら、さらに詳しい情報が必要な場合は Detailクエリ を使用してください。
3.おまけ
Webアプリケーション情報(Security.Applications)や、ロールの情報(Security.Roles)等の、セキュリティ情報についても、同様の手順で参照・変更することが可能です。
*「RESTのディスパッチクラス」を参照・変更したいとき
%SYS>do ##class(Security.Applications).Get("/csp/user/rest",.prop)
%SYS>zwrite prop
prop("AutheEnabled")=64
prop("AutoCompile")=1
prop("CSPZENEnabled")=1
prop("CSRFToken")=0
prop("ChangePasswordPage")=""
prop("CookiePath")="/csp/user/rest/"
prop("DeepSeeEnabled")=0
prop("Description")=""
prop("DispatchClass")="User.REST"
:
%SYS>set Properties("DispatchClass")="User.REST2"
%SYS>write ##class(Security.Applications).Modify("/csp/user/rest",.Properties)
1
*「許可された認証方法」を参照・変更したいとき(例:認証なし+パスワード ⇒ パスワード)
%SYS>do ##class(Security.Applications).Get("/csp/user",.prop)
%SYS>zwrite prop
prop("AutheEnabled")=96
prop("AutoCompile")=1
prop("CSPZENEnabled")=1
:
%SYS>set prop("AutheEnabled")=32
%SYS>write ##class(Security.Applications).Modify("/csp/user",.prop)
1
詳細はクラスリファレンスをご覧ください。
Securityパッケージ