How to check if user belongs to certain AD group in java

后端 未结 3 625
Happy的楠姐
Happy的楠姐 2021-01-21 17:46

I know it must be a very easy question, but I am new to java and find it hard to get exact code that I need. What I need to be able to do is to get currently logged in username

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 18:14

    You can get all the groups without JNA like this:

    String groups[] = (new com.sun.security.auth.module.NTSystem()).getGroupIDs();
    

    Obviously this will work only on Windows, and even on Windows is the use of com.sun.* packages discouraged. See this for the explanation of the result.

提交回复
热议问题