【问题标题】:How to check access level of user on any system如何在任何系统上检查用户的访问级别
【发布时间】:2012-02-28 06:52:52
【问题描述】:

在我们的 RCP 应用程序中,我们在菜单贡献下新添加了一个菜单作为命令。现在我们要根据登录系统的用户来启用或禁用这个新菜单。基本上我们只想为管理员登录启用菜单,而不是为任何其他用户启用菜单。

如何做到这一点?

提前致谢!!

【问题讨论】:

    标签: java eclipse eclipse-rcp


    【解决方案1】:

    您可以检索登录用户的名称:

    String user=System.getProperty("user.name"); 
    

    您可以检索登录用户详细信息 as described in java-forums.org:

    public static void ntSystemDetails() {
    
        com.sun.security.auth.module.NTSystem NTSystem = new com.sun.security.auth.module.NTSystem();
    
        System.out.println(NTSystem.getName());
        System.out.println(NTSystem.getDomain());
        System.out.println(NTSystem.getDomainSID());
    
        System.out.println(NTSystem.getImpersonationToken());
        System.out.println(NTSystem.getPrimaryGroupID());
        System.out.println(NTSystem.getUserSID());
        for (String group : NTSystem.getGroupIDs()) {
            System.out.println("Groups  " + group);
        }
    }
    

    如果您收到这样的错误:

       NTSystem is not accessible due to restriction on required library ...
    

    然后,按照https://stackoverflow.com/a/2174607/607637中所述的以下步骤进行操作

    要了解 Windows 操作系统中的众所周知的安全标识符,请参阅此页面http://support.microsoft.com/kb/243330

    然后 我希望你得到足够的提示。

    【讨论】:

    • 您好,感谢您的回复。这对我来说是一半的答案。上述方法返回系统上的用户帐户名。我可以使用此名称并检查该用户是否是系统上的管理员吗?
    【解决方案2】:

    您可以尝试为此使用活动机制。看看this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-07
      • 2012-11-14
      • 2014-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      相关资源
      最近更新 更多