How to check access level of user on any system

孤街醉人 提交于 2019-12-10 11:44:29

问题


In our RCP application we have newly added a menu as command under menu contributions. Now that we want to enable or disable this new menu depending the user who has logged on to the system. Basically we want to enable the menu only for the Administrator login and not for any other user.

How can this be accomplished?

Thanks in advance !!


回答1:


You can retrieve the logged in user's name as :

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

You can retrieve the logged in user detail 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);
    }
}

If you get an error like this :

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

then , follow the following steps as described in https://stackoverflow.com/a/2174607/607637

To know about Well-known security identifiers in Windows operating systems, see this page http://support.microsoft.com/kb/243330

Then I hope that you get enough hints.




回答2:


You may try using the activities mechanism for this. Have a look at this



来源:https://stackoverflow.com/questions/9477643/how-to-check-access-level-of-user-on-any-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!