简体   繁体   English

如何获取当前用户的 SAS 元数据组?

[英]How can I get the SAS Metadata groups of the current user?

I wish to set the value of a macro variable (in the autoexec file of a workspace server) based on the current user's metadata group membership.我希望根据当前用户的元数据组成员身份设置宏变量的值(在工作区服务器的 autoexec 文件中)。

Users can be in more than one group, and I need to be able to write logic that decides the variable's value based on the "highest" group of which the user is a member (for some definition of highest).用户可以在多个组中,我需要能够编写逻辑来根据用户所属的“最高”组(对于最高的某些定义)来决定变量的值。

I have looked at generic methods for querying metadata from SAS code, but they seem to suggest the executing user should have an administrative role, and my users won't.我查看了从 SAS 代码查询元数据的通用方法,但它们似乎建议执行用户应该具有管理角色,而我的用户不会。

Users do not need to be admins in order to query metadata. 用户不必是管理员即可查询元数据。 They would need to have read access to the metadata objects. 他们将需要对元数据对象具有读取权限。 I'm just a user on our server, and I can get a list of all users and their associated groups, using an adaption of http://support.sas.com/kb/30/682.html : 我只是我们服务器上的一个用户,使用http://support.sas.com/kb/30/682.html的改编版,我可以获得所有用户及其关联组的列表:

data users_grps (keep=name group email);
   length uri name groupuri group emailuri email $256 ;

   call missing(uri, name, groupuri, group, emailuri, email) ;    

   /* Get URI of first person */
   n=1; 
   nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
   if nobj=0 then put 'No Persons available.';
   do while (nobj > 0);
      call missing(name, groupuri, group, emailuri, email) ;    

      /* Retrieve the current persons name. */
      rc=metadata_getattr(uri, "Name", Name);

      /* get the persons email address (only first one)*/
      rc2=metadata_getnasn(uri,"EmailAddresses",1,emailURI) ;
      rc3=metadata_getattr(emailuri, "Address", email);

      /* Get the group association information for the current person. */
      a=1;
      rcgrp=metadata_getnasn(uri,"IdentityGroups",a,groupuri);

         /* If this person does not belong to any groups, set their group */
         /* variable to 'No groups' and output the name. */
      if rcgrp in (-3,-4) then do;
         group="No groups";
         output;
      end;

      /* If the person belongs to any groups, loop through the list */
      /* and retrieve the name of each group, outputting each on a */
      /* separate record. */
      else do while (rcgrp > 0);
         rc4=metadata_getattr(groupuri, "Name", group);
         a+1;
         output;
         rcgrp=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
      end;

      /* Get URI of next person. */
      n+1;
      nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
   end;

run;

Would think that could be adapted to look up the groups of the current user. 会认为可以调整以查找当前用户的组。

This macro will give you either all groups, or the direct-group memberships of a specific user:此宏将为您提供所有组或特定用户的直接组成员资格:

https://core.sasjs.io/mm__getgroups_8sas.html https://core.sasjs.io/mm__getgroups_8sas.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM