1

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 !!

prakashjv
  • 329
  • 2
  • 8
  • 16

2 Answers2

3

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.

Community
  • 1
  • 1
gtiwari333
  • 24,554
  • 15
  • 75
  • 102
  • Hey, Thanks for the reply. This is kind of half answer for me. The above method returns the user account name on the system. Can I use this name and check if that user is an Administrator on the system? – prakashjv Feb 28 '12 at 08:31
0

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

Kuldeep Jain
  • 8,409
  • 8
  • 48
  • 73