RFR: 8314094: java/lang/ProcessHandle/InfoTest.java fails on Windows when run as user with Administrator privileges

Roger Riggs rriggs at openjdk.org
Wed Aug 30 16:01:11 UTC 2023


On Tue, 29 Aug 2023 08:30:10 GMT, Christoph Langer <clanger at openjdk.org> wrote:

>> It seems that ProcessHandle.info()  returns **DOMAIN/USERNAME** on Windows but System.getProperty("user.name") only the **USERNAME**.
>> You can get **DOMAIN** and **USERNAME** on **Windows** by calling:
>> com.sun.security.auth.module.NTSystem NTSystem = new com.sun.security.auth.module.NTSystem();
>> String user = NTSystem.getName();
>> String domain = NTSystem.getDomain();
>
> Yes, I think using System.getProperty("user.name") is brittle as well. If we'd use `com.sun.security.auth.module.NTSystem`, we would introduce the dependency to another module - `jdk.security.auth`. Not sure, whether this is a good option.

The system environment has the domainname and the username.

String username = (System.getenv("USERDOMAIN") + "/" + System.getenv("USERNAME")).toLowerCase(Locale.ROOT);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15222#discussion_r1310499879


More information about the core-libs-dev mailing list