Published on :
Administration INTERNAL_CREATION

Extracting User IDs from DefaultAuth Domain

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The script initializes a connection to the SAS© metadata server by configuring options such as the host (`metaserver`), port (`metaport`), user (`metauser`), password (`metapass`), repository (`metarepository`), and protocol (`metaprotocol`). It then creates a temporary dataset `work.users`. Using the `metadata_getnobj` and `metadata_getattr` functions, it searches for the 'DefaultAuth' authentication domain, retrieves its URI and internal ID. A `do while` loop is then used to iterate over all Login objects associated with this domain. For each Login object found, the user ID (`UserID`) is extracted and added to the `work.users` dataset. The final dataset retains only the `user_id` variable.
Data Analysis

Type : INTERNAL_CREATION


The `work.users` dataset is dynamically created and populated from information extracted from the SAS metadata server via the `metadata_getnobj` and `metadata_getattr` functions. There is no external data source to the script (file, database) or SASHELP dataset directly used as input.

1 Code Block
OPTIONS
Explanation :
This block configures the connection options to the SAS metadata server. It specifies the server address (`metaserver`), port (`metaport`), user credentials (`metauser`, `metapass`), metadata repository (`metarepository`), and communication protocol (`metaprotocol`). This information is essential for establishing the connection and querying metadata.
Copied!
1options
2 metaserver="<hostname>"
3 metaport=8561
4 metauser="sasadm @saspw"
5 metapass="<password>"
6 metarepository=Foundation
7 metaprotocol=BRIDGE;
2 Code Block
DATA STEP Data
Explanation :
This `DATA STEP` block is responsible for creating the `work.users` dataset and populating it with user IDs. It declares and initializes the necessary variables. It uses `metadata_getnobj` to find the 'DefaultAuth' authentication domain and its URI, then `metadata_getattr` to retrieve its ID. Subsequently, a `do while` loop iterates through all Login objects associated with this domain. For each Login, the user ID (`UserID`) is extracted via `metadata_getattr` and added to the `work.users` dataset. Only the `user_id` variable is kept in the final dataset.
Copied!
1DATA work.users; /* Create work.users library to house data. */
2 
3/* declare variables */
4 
5LENGTH
6 ad_uri $ 256
7 ad_id $ 256
8 login_uri $ 256
9 user_id $ 256;
10 
11/* initialize variables. */
12 
13call missing(ad_uri,ad_id,login_uri,user_id);
14keep user_id; /* only keep the user ids in the table. */
15 
16n=1;
17/* Get the URI for the DefaultAuth Authentication Domain. */
18adrc=metadata_getnobj("omsobj:AuthenticationDomain? @code_sas_json_prod_multi/libname_de.json = 'DefaultAuth'",1,ad_uri);
19rc=metadata_getattr(ad_uri,"Id",ad_id);
20 
21/* Get number of login objects that have the DefaultAuth authentication */
22/* domain associated with them, as well as the URI of the first login. */
23loginrc=metadata_getnobj("omsobj:Login?Login[Domain/AuthenticationDomain[ @Id='"||ad_id||"']",n,login_uri);
24DO while(loginrc>0);
25 /* extract the user ID from login */
26 rc=metadata_getattr(login_uri,"UserID",user_id);
27 OUTPUT;
28 n+1;
29 /* Get the URI of the next login. */
30 loginrc=metadata_getnobj("omsobj:Login?Login[Domain/AuthenticationDomain[ @Id='"||ad_id||"']",n,login_uri);
31END;
32RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Author: Greg Wootton Date: 08FEB2017