Exporting security settings into a stream

Primary tabs

Hello,

I am working on Ensemble 2017.2.1 .
I need to export my security settings into an extern database, in order to make a report.

I've created a Business Operation with an SQL Adapter into a Namespace, but I don't know how to get every security data from "%SYS" Namespace  ( SQLPrivileges , Resources , Roles , Services , Users ... ).

I dont't want to use the terminal and the ^SECURITY routine, because i don't want to store a XML file on the server.


I tried to create a method where I can use the (Security.System).ExportAll  command  in order to use the stream , but it doesn't work because the "ExportAll" method asks for a filePath instead of a Stream .

This is a part of my code :

   NEW $NAMESPACE
   SET $NAMESPACE="%SYS"
   set xmlFile = ##class(%Stream.FileBinary).%New()
   do ##class(Security.System).ExportAll(.xmlFile,.nbRows)   

 

Do you know any method to get every Security settings without exporting a file ? 
Do you think creating a proxy class can be a good idea to get every security data from the "%SYS" Namespace ? ( this seems a bit dangerous )

 

Thank you in advance.
Best regards,

 

Lucas BOURRE

Replies

Hi Lucas,

All security settings are store in the %SYS databases.

You can access then with this query :

select * from Security.System

Or with this procedure

select * from Security.System_List()

If you want to do this in COS :

s ResultSet=##class(%ResultSet).%New("Security.System:List")
d ResultSet.Execute()
While ResultSet.Next() {
	zw ResultSet.Data("Name")
}

Like that you don't have to use the export function who only create files.

Now you can parse data and build your report directly from an homemade object.

Hi Guillaume,

This is exactly what I am looking for.
Thank you for the example, I'm giving it a try , i keep you informed :) 

Best regards,

Lucas Bourré